@valkyriestudios/utils 12.9.0 → 12.10.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/README.md +35 -14
- package/array/dedupe.js +1 -1
- package/array/groupBy.js +1 -1
- package/array/index.js +1 -1
- package/array/is.js +1 -1
- package/array/isNotEmpty.js +1 -1
- package/array/join.js +3 -2
- package/array/mapFn.js +2 -2
- package/array/mapKey.js +2 -2
- package/array/mapPrimitive.js +8 -14
- package/array/shuffle.js +1 -1
- package/array/sort.js +1 -1
- package/boolean/index.js +1 -1
- package/boolean/is.js +1 -1
- package/caching/index.js +1 -1
- package/caching/memoize.d.ts +2 -1
- package/caching/memoize.js +39 -12
- package/date/addUTC.js +1 -1
- package/date/diff.js +1 -3
- package/date/endOfUTC.js +1 -1
- package/date/format.js +11 -9
- package/date/index.js +1 -1
- package/date/is.js +1 -1
- package/date/nowUnix.js +1 -1
- package/date/nowUnixMs.js +1 -1
- package/date/startOfUTC.js +1 -1
- package/date/toUTC.js +1 -1
- package/date/toUnix.js +1 -1
- package/deep/freeze.js +1 -1
- package/deep/get.js +1 -1
- package/deep/index.js +1 -1
- package/deep/seal.js +1 -1
- package/deep/set.js +1 -1
- package/equal.js +1 -1
- package/formdata/index.js +1 -1
- package/formdata/is.js +1 -1
- package/function/index.js +1 -1
- package/function/is.js +1 -1
- package/function/isAsync.js +1 -1
- package/function/noop.js +1 -1
- package/function/noopresolve.d.ts +1 -1
- package/function/noopresolve.js +1 -1
- package/function/noopreturn.d.ts +1 -1
- package/function/noopreturn.js +1 -1
- package/function/sleep.js +1 -1
- package/hash/fnv1A.js +1 -1
- package/hash/guid.js +1 -1
- package/hash/index.js +1 -1
- package/index.d.ts +12 -12
- package/is.js +1 -1
- package/number/index.js +1 -1
- package/number/is.js +1 -1
- package/number/isAbove.js +1 -1
- package/number/isAboveOrEqual.js +1 -1
- package/number/isBelow.js +1 -1
- package/number/isBelowOrEqual.js +1 -1
- package/number/isBetween.js +1 -1
- package/number/isInteger.js +1 -1
- package/number/isIntegerAbove.js +1 -1
- package/number/isIntegerAboveOrEqual.js +1 -1
- package/number/isIntegerBelow.js +1 -1
- package/number/isIntegerBelowOrEqual.js +1 -1
- package/number/isIntegerBetween.js +1 -1
- package/number/isNumericalNaN.js +1 -1
- package/number/randomBetween.js +1 -1
- package/number/randomIntBetween.js +1 -1
- package/number/round.js +1 -1
- package/number/toPercentage.js +1 -1
- package/object/define.js +1 -1
- package/object/index.js +1 -1
- package/object/is.js +1 -1
- package/object/isNotEmpty.js +1 -1
- package/object/merge.js +1 -1
- package/object/pick.js +1 -1
- package/package.json +1 -1
- package/regexp/index.js +1 -1
- package/regexp/is.js +1 -1
- package/regexp/sanitize.js +1 -1
- package/string/humanizeBytes.d.ts +2 -2
- package/string/humanizeBytes.js +6 -6
- package/string/humanizeNumber.d.ts +1 -1
- package/string/humanizeNumber.js +13 -27
- package/string/index.js +1 -1
- package/string/is.js +1 -1
- package/string/isBetween.js +1 -1
- package/string/isNotEmpty.js +1 -1
- package/string/shorten.js +1 -1
package/README.md
CHANGED
|
@@ -39,7 +39,7 @@ mapKey([
|
|
|
39
39
|
{uid: 87, name: 'Josh'},
|
|
40
40
|
], 'uid');
|
|
41
41
|
|
|
42
|
-
output:
|
|
42
|
+
output:
|
|
43
43
|
|
|
44
44
|
{
|
|
45
45
|
12: {uid: 12, name: 'Peter'},
|
|
@@ -72,7 +72,7 @@ output:
|
|
|
72
72
|
}
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
allows merging objects onto existing keys:
|
|
75
|
+
allows merging objects onto existing keys:
|
|
76
76
|
```js
|
|
77
77
|
mapKey([
|
|
78
78
|
0,
|
|
@@ -215,7 +215,7 @@ shuffle(arr);
|
|
|
215
215
|
```
|
|
216
216
|
|
|
217
217
|
- **sort(val:Array[object], by:string|Function, dir:Enum(asc,desc), options:Object)**
|
|
218
|
-
Sort an array of objects, uses an implementation of [Tony Hoare's quicksort](https://cs.stanford.edu/people/eroberts/courses/soco/projects/2008-09/tony-hoare/quicksort.html)
|
|
218
|
+
Sort an array of objects, uses an implementation of [Tony Hoare's quicksort](https://cs.stanford.edu/people/eroberts/courses/soco/projects/2008-09/tony-hoare/quicksort.html)
|
|
219
219
|
|
|
220
220
|
```js
|
|
221
221
|
const out = sort([
|
|
@@ -226,7 +226,7 @@ const out = sort([
|
|
|
226
226
|
{test: 'Joe'},
|
|
227
227
|
{test: 'Bob'},
|
|
228
228
|
{test: 'Alice'},
|
|
229
|
-
], 'test', 'desc');
|
|
229
|
+
], 'test', 'desc');
|
|
230
230
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'John'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}]
|
|
231
231
|
```
|
|
232
232
|
|
|
@@ -239,7 +239,7 @@ const out = sort([
|
|
|
239
239
|
{test: 'Joe'},
|
|
240
240
|
{test: 'Bob'},
|
|
241
241
|
{test: 'Alice'},
|
|
242
|
-
], 'test', 'asc');
|
|
242
|
+
], 'test', 'asc');
|
|
243
243
|
// [{test: 'Alice'}, {test: 'Bob'}, {test: 'Jack'}, {test: 'Joe'}, {test: 'John'}, {test: 'Peter'}, {test: 'Pony'}]
|
|
244
244
|
```
|
|
245
245
|
|
|
@@ -254,7 +254,7 @@ const out = sort([
|
|
|
254
254
|
{test: 'Joe'},
|
|
255
255
|
{test: 'Bob'},
|
|
256
256
|
{test: 'Alice'},
|
|
257
|
-
], el => el.test.toLowerCase(), 'desc');
|
|
257
|
+
], el => el.test.toLowerCase(), 'desc');
|
|
258
258
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}]
|
|
259
259
|
```
|
|
260
260
|
|
|
@@ -272,7 +272,7 @@ const out = sort([
|
|
|
272
272
|
{test: 'Bob'},
|
|
273
273
|
undefined,
|
|
274
274
|
{test: 'Alice'},
|
|
275
|
-
], el => el.test.toLowerCase(), 'desc');
|
|
275
|
+
], el => el.test.toLowerCase(), 'desc');
|
|
276
276
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}]
|
|
277
277
|
```
|
|
278
278
|
|
|
@@ -293,7 +293,7 @@ const out = sort([
|
|
|
293
293
|
{test: 'Bob'},
|
|
294
294
|
undefined,
|
|
295
295
|
{test: 'Alice'},
|
|
296
|
-
], el => el.test.toLowerCase(), 'desc', {filter_fn: el => isNotEmptyString(el.test)});
|
|
296
|
+
], el => el.test.toLowerCase(), 'desc', {filter_fn: el => isNotEmptyString(el.test)});
|
|
297
297
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Joe'}, {test: 'Jack'}, {test: 'Bob'}, {test: 'Alice'}]
|
|
298
298
|
```
|
|
299
299
|
|
|
@@ -301,13 +301,13 @@ allows passing custom options to position elements without a proper key (nokey_a
|
|
|
301
301
|
|
|
302
302
|
```js
|
|
303
303
|
const arr = [{test: 'Peter'}, {test: undefined}, {test: 'Jack'}, {test: 'Pony'}, {uid: 100}, {test: 'JOHn'}];
|
|
304
|
-
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_atend: false});
|
|
304
|
+
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_atend: false});
|
|
305
305
|
// [{test: undefined}, {uid: 100}, {test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Jack'}]
|
|
306
306
|
|
|
307
|
-
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_atend: true});
|
|
307
|
+
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_atend: true});
|
|
308
308
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Jack'}, {test: undefined}, {uid: 100}]
|
|
309
309
|
|
|
310
|
-
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_hide: true});
|
|
310
|
+
const out = sort(arr, el => el.test.toLowerCase(), 'desc', {nokey_hide: true});
|
|
311
311
|
// [{test: 'Pony'}, {test: 'Peter'}, {test: 'JOHn'}, {test: 'Jack'}]
|
|
312
312
|
```
|
|
313
313
|
|
|
@@ -321,8 +321,8 @@ isBoolean(true); // TRUE
|
|
|
321
321
|
```
|
|
322
322
|
|
|
323
323
|
### caching
|
|
324
|
-
- **memoize(fn:Function, resolver:Function=false)**
|
|
325
|
-
memoize the output of a
|
|
324
|
+
- **memoize(fn:Function, resolver:Function=false, memoize_for:number|false)**
|
|
325
|
+
memoize the output of a function. An optional resolver function can be passed which allows custom cache key generation.
|
|
326
326
|
|
|
327
327
|
```js
|
|
328
328
|
const memoized_function = memoize((a) => {
|
|
@@ -330,6 +330,27 @@ const memoized_function = memoize((a) => {
|
|
|
330
330
|
});
|
|
331
331
|
```
|
|
332
332
|
|
|
333
|
+
Take Note: Also supports async functions and cache busting, eg:
|
|
334
|
+
```js
|
|
335
|
+
async function retrieveUser (userId:string) {
|
|
336
|
+
...
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/* Async but with no cache busting */
|
|
340
|
+
const memoized = memoize(retrieveUser);
|
|
341
|
+
await memoized('123456'); /* Original function will be called */
|
|
342
|
+
await memoized('123456'); /* Original function will not be called and memoized cache will be returned */
|
|
343
|
+
|
|
344
|
+
/* Async with cache busting after 5 seconds */
|
|
345
|
+
const memoized = memoize(retrieveUser, null, 5000);
|
|
346
|
+
await memoized('123456'); /* Original function will be called */
|
|
347
|
+
await memoized('123456'); /* Original function will not be called and memoized cache will be returned */
|
|
348
|
+
|
|
349
|
+
... (some time longer than 5 seconds passes)
|
|
350
|
+
|
|
351
|
+
await memoized('123456'); /* Original function will be called and re-cached */
|
|
352
|
+
```
|
|
353
|
+
|
|
333
354
|
### date
|
|
334
355
|
- **isDate(val:any)**
|
|
335
356
|
Check if a variable is of type Date
|
|
@@ -807,7 +828,7 @@ merge({a: 1, b: false}, {a: 900, c: 50}); // {a: 900, b: false, c: 50}
|
|
|
807
828
|
Creates an object with the passed accessors set on it
|
|
808
829
|
```js
|
|
809
830
|
define(
|
|
810
|
-
{
|
|
831
|
+
{
|
|
811
832
|
a: {
|
|
812
833
|
enumerable: false,
|
|
813
834
|
value : function () { ... }
|
package/array/dedupe.js
CHANGED
package/array/groupBy.js
CHANGED
package/array/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sort = exports.shuffle = exports.groupBy = exports.mapPrimitive = exports.mapKey = exports.mapFn = exports.join = exports.isNe = exports.isNeArray = exports.isNotEmpty = exports.isNotEmptyArray = exports.is = exports.isArray = exports.dedupe = void 0;
|
|
4
4
|
const dedupe_1 = require("./dedupe");
|
package/array/is.js
CHANGED
package/array/isNotEmpty.js
CHANGED
package/array/join.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.join = void 0;
|
|
4
4
|
const round_1 = require("../number/round");
|
|
5
|
+
const isInteger_1 = require("../number/isInteger");
|
|
5
6
|
function join(val, opts) {
|
|
6
7
|
if (!Array.isArray(val) || !val.length)
|
|
7
8
|
return '';
|
|
@@ -16,7 +17,7 @@ function join(val, opts) {
|
|
|
16
17
|
TRIM = opts.trim;
|
|
17
18
|
if (opts.valtrim === false)
|
|
18
19
|
VALTRIM = opts.valtrim;
|
|
19
|
-
if (
|
|
20
|
+
if ((0, isInteger_1.isInteger)(opts.valround) && opts.valround >= 0)
|
|
20
21
|
VALROUND = opts.valround;
|
|
21
22
|
}
|
|
22
23
|
const filtered = [];
|
package/array/mapFn.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.mapFn = void 0;
|
|
4
4
|
function mapFn(arr, fn, opts) {
|
|
5
5
|
if ((!Array.isArray(arr) || !arr.length) ||
|
|
6
6
|
typeof fn !== 'function')
|
|
7
7
|
return {};
|
|
8
|
-
const MERGE = opts
|
|
8
|
+
const MERGE = opts?.merge === true;
|
|
9
9
|
const map = {};
|
|
10
10
|
let hash = false;
|
|
11
11
|
for (const el of arr) {
|
package/array/mapKey.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.mapKey = void 0;
|
|
4
4
|
function mapKey(arr, key, opts) {
|
|
@@ -8,7 +8,7 @@ function mapKey(arr, key, opts) {
|
|
|
8
8
|
const key_s = key.trim();
|
|
9
9
|
if (!key_s.length)
|
|
10
10
|
return {};
|
|
11
|
-
const MERGE = opts
|
|
11
|
+
const MERGE = opts?.merge === true;
|
|
12
12
|
const map = {};
|
|
13
13
|
for (const el of arr) {
|
|
14
14
|
if (Object.prototype.toString.call(el) !== '[object Object]' ||
|
package/array/mapPrimitive.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.mapPrimitive = void 0;
|
|
4
4
|
const round_1 = require("../number/round");
|
|
5
|
-
|
|
5
|
+
const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
|
|
6
|
+
function mapPrimitive(arr, opts = {}) {
|
|
6
7
|
if (!Array.isArray(arr) || !arr.length)
|
|
7
8
|
return {};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
VALTRIM = true;
|
|
14
|
-
if (opts.valround === true ||
|
|
15
|
-
(Number.isInteger(opts.valround) && opts.valround >= 0))
|
|
16
|
-
VALROUND = opts.valround;
|
|
17
|
-
if (opts.keyround === true)
|
|
18
|
-
KEYROUND = true;
|
|
19
|
-
}
|
|
9
|
+
const VALTRIM = opts?.valtrim === true;
|
|
10
|
+
const VALROUND = (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(opts?.valround, 0)
|
|
11
|
+
? opts?.valround
|
|
12
|
+
: opts?.valround === true;
|
|
13
|
+
const KEYROUND = opts?.keyround === true;
|
|
20
14
|
const map = {};
|
|
21
15
|
for (const el of arr) {
|
|
22
16
|
if (typeof el === 'string') {
|
package/array/shuffle.js
CHANGED
package/array/sort.js
CHANGED
package/boolean/index.js
CHANGED
package/boolean/is.js
CHANGED
package/caching/index.js
CHANGED
package/caching/memoize.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @param fn - Function to memoize
|
|
8
8
|
* @param resolver - Optional resolver function to generate cache key. If not passed the first argument is used as map key
|
|
9
|
+
* @param {false|number?} memoize_for - Memoize for X milliseconds, if passed false will indefinitely memoize (default = false)
|
|
9
10
|
*/
|
|
10
|
-
declare function memoize(fn:
|
|
11
|
+
declare function memoize<T extends (...args: any[]) => unknown>(fn: T, resolver?: (...args: Parameters<T>) => any, memoize_for?: number | false): T;
|
|
11
12
|
export { memoize, memoize as default };
|
package/caching/memoize.js
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.memoize = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
const isAsync_1 = require("../function/isAsync");
|
|
5
|
+
const isIntegerAbove_1 = require("../number/isIntegerAbove");
|
|
6
|
+
const toUTC_1 = require("../date/toUTC");
|
|
7
|
+
const diff_1 = require("../date/diff");
|
|
8
|
+
function memoize(fn, resolver, memoize_for = false) {
|
|
9
|
+
const cache_for = (0, isIntegerAbove_1.default)(memoize_for, 0) ? memoize_for : false;
|
|
10
|
+
if ((0, isAsync_1.default)(fn)) {
|
|
11
|
+
const memoized = async function (...args) {
|
|
12
|
+
const key = typeof resolver === 'function' ? resolver(...args) : args[0];
|
|
13
|
+
if (memoized.cache.has(key)) {
|
|
14
|
+
const cached_val = memoized.cache.get(key);
|
|
15
|
+
if (cache_for === false || (0, diff_1.default)((0, toUTC_1.default)(new Date()), cached_val.d) < cache_for) {
|
|
16
|
+
return cached_val.r;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const result = await fn(...args);
|
|
20
|
+
memoized.cache.set(key, { r: result, d: (0, toUTC_1.default)(new Date()) });
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
memoized.cache = new Map();
|
|
24
|
+
return memoized;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
const memoized = function (...args) {
|
|
28
|
+
const key = typeof resolver === 'function' ? resolver(...args) : args[0];
|
|
29
|
+
if (memoized.cache.has(key)) {
|
|
30
|
+
const cached_val = memoized.cache.get(key);
|
|
31
|
+
if (cache_for === false || (0, diff_1.default)((0, toUTC_1.default)(new Date()), cached_val.d) < cache_for) {
|
|
32
|
+
return cached_val.r;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const result = fn(...args);
|
|
36
|
+
memoized.cache.set(key, { r: result, d: (0, toUTC_1.default)(new Date()) });
|
|
37
|
+
return result;
|
|
38
|
+
};
|
|
39
|
+
memoized.cache = new Map();
|
|
40
|
+
return memoized;
|
|
41
|
+
}
|
|
15
42
|
}
|
|
16
43
|
exports.memoize = memoize;
|
|
17
44
|
exports.default = memoize;
|
package/date/addUTC.js
CHANGED
package/date/diff.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.diff = void 0;
|
|
4
4
|
const is_1 = require("./is");
|
|
@@ -11,8 +11,6 @@ function diff(val_a, val_b, key = 'millisecond') {
|
|
|
11
11
|
if (!(0, is_1.isDate)(val_a) ||
|
|
12
12
|
!(0, is_1.isDate)(val_b))
|
|
13
13
|
throw new TypeError('Diff requires date objects for both values');
|
|
14
|
-
if (typeof key !== 'string')
|
|
15
|
-
throw new TypeError('Key needs to be a string');
|
|
16
14
|
const diff_in_ms = val_a.valueOf() - val_b.valueOf();
|
|
17
15
|
switch (key) {
|
|
18
16
|
case 'week':
|
package/date/endOfUTC.js
CHANGED
package/date/format.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.format = void 0;
|
|
4
4
|
const is_1 = require("./is");
|
|
@@ -39,12 +39,13 @@ function toZone(date, zone) {
|
|
|
39
39
|
}
|
|
40
40
|
function runIntl(loc, token, props, val) {
|
|
41
41
|
const hash = `${loc}:${token}`;
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
let formatter = intl_formatters.get(hash);
|
|
43
|
+
if (formatter)
|
|
44
|
+
return formatter.format(val);
|
|
44
45
|
try {
|
|
45
|
-
|
|
46
|
-
intl_formatters.set(hash,
|
|
47
|
-
return
|
|
46
|
+
formatter = new Intl.DateTimeFormat(loc, props);
|
|
47
|
+
intl_formatters.set(hash, formatter);
|
|
48
|
+
return formatter.format(val);
|
|
48
49
|
}
|
|
49
50
|
catch (err) {
|
|
50
51
|
throw new Error(`format: Failed to run conversion for ${token} with locale ${loc}`);
|
|
@@ -76,9 +77,10 @@ const Tokens = [
|
|
|
76
77
|
.sort((a, b) => a[0].length > b[0].length ? -1 : 1)
|
|
77
78
|
.map((el) => [el[0], new RegExp(el[0], 'g'), el[1]]);
|
|
78
79
|
function getSpecChain(spec) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
let spec_chain = spec_cache.get(spec);
|
|
81
|
+
if (spec_chain)
|
|
82
|
+
return spec_chain;
|
|
83
|
+
spec_chain = [];
|
|
82
84
|
let cursor;
|
|
83
85
|
for (let i = 0; i < Tokens.length; i++) {
|
|
84
86
|
cursor = Tokens[i];
|
package/date/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toUTC = exports.toUnix = exports.startOfUTC = exports.nowUnixMs = exports.nowUnix = exports.is = exports.isDate = exports.format = exports.endOfUTC = exports.diff = exports.addUTC = void 0;
|
|
4
4
|
const addUTC_1 = require("./addUTC");
|
package/date/is.js
CHANGED
package/date/nowUnix.js
CHANGED
package/date/nowUnixMs.js
CHANGED
package/date/startOfUTC.js
CHANGED
package/date/toUTC.js
CHANGED
package/date/toUnix.js
CHANGED
package/deep/freeze.js
CHANGED
package/deep/get.js
CHANGED
package/deep/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deepSet = exports.set = exports.deepSeal = exports.seal = exports.deepGet = exports.get = exports.deepFreeze = exports.freeze = void 0;
|
|
4
4
|
const freeze_1 = require("./freeze");
|
package/deep/seal.js
CHANGED
package/deep/set.js
CHANGED
package/equal.js
CHANGED
package/formdata/index.js
CHANGED
package/formdata/is.js
CHANGED
package/function/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sleep = exports.noopreturn = exports.noopresolve = exports.noop = exports.isAsyncFn = exports.isAsync = exports.isAsyncFunction = exports.isFn = exports.is = exports.isFunction = void 0;
|
|
4
4
|
const is_1 = require("./is");
|
package/function/is.js
CHANGED
package/function/isAsync.js
CHANGED
package/function/noop.js
CHANGED
package/function/noopresolve.js
CHANGED
package/function/noopreturn.d.ts
CHANGED
package/function/noopreturn.js
CHANGED
package/function/sleep.js
CHANGED
package/hash/fnv1A.js
CHANGED
package/hash/guid.js
CHANGED
package/hash/index.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ declare module "number/round" {
|
|
|
26
26
|
function round(val: number, precision?: number): number;
|
|
27
27
|
export { round, round as default };
|
|
28
28
|
}
|
|
29
|
+
declare module "number/isInteger" {
|
|
30
|
+
function isInteger(val: unknown): val is number;
|
|
31
|
+
export { isInteger, isInteger as default };
|
|
32
|
+
}
|
|
29
33
|
declare module "array/join" {
|
|
30
34
|
interface joinOptions {
|
|
31
35
|
delim?: string;
|
|
@@ -51,6 +55,10 @@ declare module "array/mapKey" {
|
|
|
51
55
|
function mapKey<T extends Record<string, any>>(arr: T[], key: string, opts?: mapOptions): Record<string, T>;
|
|
52
56
|
export { mapKey, mapKey as default };
|
|
53
57
|
}
|
|
58
|
+
declare module "number/isIntegerAboveOrEqual" {
|
|
59
|
+
function isIntegerAboveOrEqual(val: unknown, ref: number): val is number;
|
|
60
|
+
export { isIntegerAboveOrEqual, isIntegerAboveOrEqual as default };
|
|
61
|
+
}
|
|
54
62
|
declare module "array/mapPrimitive" {
|
|
55
63
|
interface mapOptions {
|
|
56
64
|
valtrim?: boolean;
|
|
@@ -184,11 +192,11 @@ declare module "function/noop" {
|
|
|
184
192
|
export { noop, noop as default };
|
|
185
193
|
}
|
|
186
194
|
declare module "function/noopresolve" {
|
|
187
|
-
function noopresolve<T>(val?: T): Promise<T>;
|
|
195
|
+
function noopresolve<T>(val?: T): Promise<T | undefined>;
|
|
188
196
|
export { noopresolve, noopresolve as default };
|
|
189
197
|
}
|
|
190
198
|
declare module "function/noopreturn" {
|
|
191
|
-
function noopreturn<T>(val?: T): T;
|
|
199
|
+
function noopreturn<T>(val?: T): T | undefined;
|
|
192
200
|
export { noopreturn, noopreturn as default };
|
|
193
201
|
}
|
|
194
202
|
declare module "function/sleep" {
|
|
@@ -299,18 +307,10 @@ declare module "number/isBetween" {
|
|
|
299
307
|
function isNumberBetween(val: unknown, min: number, max: number): val is number;
|
|
300
308
|
export { isNumberBetween, isNumberBetween as default };
|
|
301
309
|
}
|
|
302
|
-
declare module "number/isInteger" {
|
|
303
|
-
function isInteger(val: unknown): val is number;
|
|
304
|
-
export { isInteger, isInteger as default };
|
|
305
|
-
}
|
|
306
310
|
declare module "number/isIntegerAbove" {
|
|
307
311
|
function isIntegerAbove(val: unknown, ref: number): val is number;
|
|
308
312
|
export { isIntegerAbove, isIntegerAbove as default };
|
|
309
313
|
}
|
|
310
|
-
declare module "number/isIntegerAboveOrEqual" {
|
|
311
|
-
function isIntegerAboveOrEqual(val: unknown, ref: number): val is number;
|
|
312
|
-
export { isIntegerAboveOrEqual, isIntegerAboveOrEqual as default };
|
|
313
|
-
}
|
|
314
314
|
declare module "number/isIntegerBelow" {
|
|
315
315
|
function isIntegerBelow(val: unknown, ref: number): val is number;
|
|
316
316
|
export { isIntegerBelow, isIntegerBelow as default };
|
|
@@ -364,7 +364,7 @@ declare module "string/humanizeNumber" {
|
|
|
364
364
|
divider?: number;
|
|
365
365
|
real?: boolean;
|
|
366
366
|
}
|
|
367
|
-
function humanizeNumber(val: number | string, options?: humanizeNumberOptions
|
|
367
|
+
function humanizeNumber(val: number | string, options?: humanizeNumberOptions): string;
|
|
368
368
|
export { humanizeNumber, humanizeNumber as default };
|
|
369
369
|
}
|
|
370
370
|
declare module "string/humanizeBytes" {
|
|
@@ -468,7 +468,7 @@ declare module "is" {
|
|
|
468
468
|
export { Is, Is as default };
|
|
469
469
|
}
|
|
470
470
|
declare module "caching/memoize" {
|
|
471
|
-
function memoize(fn:
|
|
471
|
+
function memoize<T extends (...args: any[]) => unknown>(fn: T, resolver?: (...args: Parameters<T>) => any, memoize_for?: number | false): T;
|
|
472
472
|
export { memoize, memoize as default };
|
|
473
473
|
}
|
|
474
474
|
declare module "caching/index" {
|
package/is.js
CHANGED
package/number/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toPct = exports.toPercentage = exports.round = exports.randIntBetween = exports.randomIntBetween = exports.randBetween = exports.randomBetween = exports.isNumericalNaN = exports.isIntBetween = exports.isIntegerBetween = exports.isIntLte = exports.isIntegerBelowOrEqual = exports.isIntLt = exports.isIntegerBelow = exports.isIntGte = exports.isIntegerAboveOrEqual = exports.isIntGt = exports.isIntegerAbove = exports.isInt = exports.isInteger = exports.isNumBetween = exports.isNumberBetween = exports.isLte = exports.isNumLte = exports.isNumberBelowOrEqual = exports.isLt = exports.isNumLt = exports.isNumberBelow = exports.isGte = exports.isNumGte = exports.isNumberAboveOrEqual = exports.isGt = exports.isNumGt = exports.isNumberAbove = exports.isNum = exports.is = exports.isNumber = void 0;
|
|
4
4
|
const is_1 = require("./is");
|
package/number/is.js
CHANGED
package/number/isAbove.js
CHANGED
package/number/isAboveOrEqual.js
CHANGED
package/number/isBelow.js
CHANGED
package/number/isBelowOrEqual.js
CHANGED
package/number/isBetween.js
CHANGED
package/number/isInteger.js
CHANGED
package/number/isIntegerAbove.js
CHANGED
package/number/isIntegerBelow.js
CHANGED
package/number/isNumericalNaN.js
CHANGED
package/number/randomBetween.js
CHANGED
package/number/round.js
CHANGED
package/number/toPercentage.js
CHANGED
package/object/define.js
CHANGED
package/object/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pick = exports.merge = exports.isNe = exports.isNeObject = exports.isNotEmpty = exports.isNotEmptyObject = exports.is = exports.isObject = exports.define = void 0;
|
|
4
4
|
const define_1 = require("./define");
|
package/object/is.js
CHANGED
package/object/isNotEmpty.js
CHANGED
package/object/merge.js
CHANGED
package/object/pick.js
CHANGED
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "name": "@valkyriestudios/utils", "version": "12.
|
|
1
|
+
{ "name": "@valkyriestudios/utils", "version": "12.10.0", "description": "A collection of single-function utilities for common tasks", "author": { "name": "Peter Vermeulen", "url": "https://www.linkedin.com/in/petervermeulen1/" }, "keywords": [ "utility", "library", "javascript", "js", "node", "bun" ], "license": "MIT", "repository": { "type": "git", "url": "git+https://github.com/ValkyrieStudios/utils.git" }, "bugs": { "url": "https://github.com/ValkyrieStudios/utils/issues" }, "homepage": "https://github.com/ValkyrieStudios/utils#readme", "types": "index.d.ts" }
|
package/regexp/index.js
CHANGED
package/regexp/is.js
CHANGED
package/regexp/sanitize.js
CHANGED
|
@@ -31,8 +31,8 @@ interface humanizeBytesOptions {
|
|
|
31
31
|
* humanizeBytes(23); // '23 bytes'
|
|
32
32
|
* humanizeBytes(-374237489237); // '-348.5 GB'
|
|
33
33
|
*
|
|
34
|
-
* @param val - Number or string byte value to humanize (string should be convertible to a number)
|
|
35
|
-
* @param
|
|
34
|
+
* @param {number|string} val - Number or string byte value to humanize (string should be convertible to a number)
|
|
35
|
+
* @param {humanizeBytesOptions?} opts - Humanization options
|
|
36
36
|
*
|
|
37
37
|
* @returns Humanized byte value as string
|
|
38
38
|
*/
|
package/string/humanizeBytes.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.humanizeBytes = void 0;
|
|
4
4
|
const humanizeNumber_1 = require("./humanizeNumber");
|
|
5
|
+
const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
|
|
5
6
|
function humanizeBytes(val, options = {}) {
|
|
6
|
-
const has_opts = Object.prototype.toString.call(options) === '[object Object]';
|
|
7
7
|
return (0, humanizeNumber_1.humanizeNumber)(val, {
|
|
8
|
-
delim:
|
|
8
|
+
delim: typeof options?.delim === 'string'
|
|
9
9
|
? options.delim
|
|
10
10
|
: ',',
|
|
11
|
-
separator:
|
|
11
|
+
separator: typeof options?.separator === 'string' && options.separator.trim().length
|
|
12
12
|
? options.separator
|
|
13
13
|
: '.',
|
|
14
|
-
precision:
|
|
14
|
+
precision: (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(options?.precision, 0)
|
|
15
15
|
? options.precision
|
|
16
16
|
: 2,
|
|
17
|
-
units:
|
|
17
|
+
units: Array.isArray(options?.units) && options.units.length
|
|
18
18
|
? options.units
|
|
19
19
|
: [' bytes', ' KB', ' MB', ' GB', ' TB', ' PB', ' EB', ' ZB', ' YB'],
|
|
20
20
|
divider: 1024,
|
|
@@ -48,5 +48,5 @@ interface humanizeNumberOptions {
|
|
|
48
48
|
*
|
|
49
49
|
* @returns Humanized number as string
|
|
50
50
|
*/
|
|
51
|
-
declare function humanizeNumber(val: number | string, options?: humanizeNumberOptions
|
|
51
|
+
declare function humanizeNumber(val: number | string, options?: humanizeNumberOptions): string;
|
|
52
52
|
export { humanizeNumber, humanizeNumber as default };
|
package/string/humanizeNumber.js
CHANGED
|
@@ -1,34 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.default = exports.humanizeNumber = void 0;
|
|
4
4
|
const round_1 = require("../number/round");
|
|
5
|
+
const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
|
|
5
6
|
const DEFAULT_UNITS = ['', 'k', 'm', 'b', 't', 'q'];
|
|
6
|
-
function humanizeNumber(val, options =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
SEPARATOR = options.separator;
|
|
18
|
-
if (Number.isInteger(options.precision) && options.precision >= 0)
|
|
19
|
-
PRECISION = options.precision;
|
|
20
|
-
if (Array.isArray(options.units) && options.units.length) {
|
|
21
|
-
UNITS = options.units;
|
|
22
|
-
}
|
|
23
|
-
else if (options.units === false) {
|
|
24
|
-
UNITS = false;
|
|
25
|
-
}
|
|
26
|
-
if (Number.isInteger(options.divider) && options.divider > 1) {
|
|
27
|
-
DIVIDER = options.divider;
|
|
28
|
-
}
|
|
29
|
-
if (options.real === true)
|
|
30
|
-
REAL = true;
|
|
31
|
-
}
|
|
7
|
+
function humanizeNumber(val, options = {}) {
|
|
8
|
+
const DELIM = typeof options?.delim === 'string' ? options.delim : ',';
|
|
9
|
+
const SEPARATOR = typeof options?.separator === 'string' && options.separator.trim().length ? options.separator : '.';
|
|
10
|
+
const PRECISION = (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(options?.precision, 0) ? options.precision : 2;
|
|
11
|
+
const DIVIDER = (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(options?.divider, 2) ? options.divider : 1000;
|
|
12
|
+
const REAL = options?.real === true;
|
|
13
|
+
const UNITS = Array.isArray(options?.units) && options.units.length
|
|
14
|
+
? options.units
|
|
15
|
+
: options?.units === false
|
|
16
|
+
? false
|
|
17
|
+
: DEFAULT_UNITS;
|
|
32
18
|
let normalized = 0;
|
|
33
19
|
if (typeof val === 'string') {
|
|
34
20
|
normalized = REAL ? parseInt(val.trim(), 10) : parseFloat(val);
|
package/string/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shorten = exports.isBetween = exports.isStringBetween = exports.isNe = exports.isNeString = exports.isNotEmpty = exports.isNotEmptyString = exports.is = exports.isString = exports.humanizeNumber = exports.humanizeBytes = void 0;
|
|
4
4
|
const humanizeBytes_1 = require("./humanizeBytes");
|
package/string/is.js
CHANGED
package/string/isBetween.js
CHANGED
package/string/isNotEmpty.js
CHANGED
package/string/shorten.js
CHANGED