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.
- package/index.d.ts +1 -1
- package/index.js +10 -10
- 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
|
|
1424
|
-
function makeStorage(n) {
|
|
1425
|
-
const
|
|
1426
|
-
if (isNaN(
|
|
1427
|
-
const
|
|
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
|
-
|
|
1432
|
-
if (
|
|
1433
|
-
return
|
|
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, '')
|