cafe-utility 32.1.0 → 32.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +10 -10
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -450,7 +450,7 @@ declare function minutes(value: number): number
450
450
  declare function hours(value: number): number
451
451
  declare function days(value: number): number
452
452
  declare function makeDate(numberWithUnit: string): number
453
- declare function makeStorage(numberWithUnit: string): number
453
+ declare function makeStorage(numberWithUnit: string, conversionMultiplier?: number): number
454
454
  declare function getPreLine(string: string): string
455
455
  declare function getCached<T>(key: string, ttlMillis: number, handler: () => Promise<T>): Promise<T>
456
456
  declare function deleteFromCache(key: string): void
package/index.js CHANGED
@@ -1416,21 +1416,21 @@ function makeDate(n) {
1416
1416
  .replace(/^-?[0-9.]+/, '')
1417
1417
  .trim()
1418
1418
  .toLowerCase(),
1419
- r = dateUnits[t]
1419
+ r = t === '' ? 1 : dateUnits[t]
1420
1420
  if (!r) throw Error(`Unknown unit: "${t}"`)
1421
- return e * r
1421
+ return Math.ceil(e * r)
1422
1422
  }
1423
- const storageUnits = { b: 1, byte: 1, bytes: 1, kb: 1024, kilobyte: 1024, kilobytes: 1024, mb: 1024 ** 2, megabyte: 1024 ** 2, megabytes: 1024 ** 2, gb: 1024 ** 3, gigabyte: 1024 ** 3, gigabytes: 1024 ** 3, tb: 1024 ** 4, terabyte: 1024 ** 4, terabytes: 1024 ** 4 }
1424
- function makeStorage(n) {
1425
- const e = parseFloat(n)
1426
- if (isNaN(e)) throw Error('makeDate got NaN for input')
1427
- const t = n
1423
+ const storageUnitExponents = { b: 0, byte: 0, bytes: 0, kb: 1, kilobyte: 1, kilobytes: 1, mb: 2, megabyte: 2, megabytes: 2, gb: 3, gigabyte: 3, gigabytes: 3, tb: 4, terabyte: 4, terabytes: 4 }
1424
+ function makeStorage(n, e = 1024) {
1425
+ const t = parseFloat(n)
1426
+ if (isNaN(t)) throw Error('makeStorage got NaN for input')
1427
+ const r = n
1428
1428
  .replace(/^-?[0-9.]+/, '')
1429
1429
  .trim()
1430
1430
  .toLowerCase(),
1431
- r = storageUnits[t]
1432
- if (!r) throw Error(`Unknown unit: "${t}"`)
1433
- return e * r
1431
+ o = r === '' ? 0 : storageUnitExponents[r]
1432
+ if (o == null) throw Error(`Unknown unit: "${r}"`)
1433
+ return Math.ceil(t * e ** o)
1434
1434
  }
1435
1435
  function getPreLine(n) {
1436
1436
  return n.replace(/ +/g, ' ').replace(/^ /gm, '')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "32.1.0",
3
+ "version": "32.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {