@valkyriestudios/utils 12.8.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.
Files changed (87) hide show
  1. package/README.md +35 -14
  2. package/array/dedupe.js +1 -1
  3. package/array/groupBy.js +1 -1
  4. package/array/index.js +1 -1
  5. package/array/is.js +1 -1
  6. package/array/isNotEmpty.js +1 -1
  7. package/array/join.js +3 -2
  8. package/array/mapFn.js +2 -2
  9. package/array/mapKey.js +2 -2
  10. package/array/mapPrimitive.js +8 -14
  11. package/array/shuffle.js +1 -1
  12. package/array/sort.js +1 -1
  13. package/boolean/index.js +1 -1
  14. package/boolean/is.js +1 -1
  15. package/caching/index.js +1 -1
  16. package/caching/memoize.d.ts +2 -1
  17. package/caching/memoize.js +39 -12
  18. package/date/addUTC.js +1 -1
  19. package/date/diff.js +1 -3
  20. package/date/endOfUTC.js +1 -1
  21. package/date/format.js +11 -9
  22. package/date/index.js +1 -1
  23. package/date/is.js +1 -1
  24. package/date/nowUnix.js +1 -1
  25. package/date/nowUnixMs.js +1 -1
  26. package/date/startOfUTC.js +1 -1
  27. package/date/toUTC.js +1 -1
  28. package/date/toUnix.js +1 -1
  29. package/deep/freeze.js +1 -1
  30. package/deep/get.js +1 -1
  31. package/deep/index.js +1 -1
  32. package/deep/seal.js +1 -1
  33. package/deep/set.js +1 -1
  34. package/equal.js +1 -1
  35. package/formdata/index.js +1 -1
  36. package/formdata/is.js +1 -1
  37. package/function/index.js +1 -1
  38. package/function/is.js +1 -1
  39. package/function/isAsync.js +1 -1
  40. package/function/noop.js +1 -1
  41. package/function/noopresolve.d.ts +1 -1
  42. package/function/noopresolve.js +1 -1
  43. package/function/noopreturn.d.ts +1 -1
  44. package/function/noopreturn.js +1 -1
  45. package/function/sleep.js +1 -1
  46. package/hash/fnv1A.js +1 -1
  47. package/hash/guid.js +1 -1
  48. package/hash/index.js +1 -1
  49. package/index.d.ts +12 -12
  50. package/is.js +1 -1
  51. package/number/index.js +1 -1
  52. package/number/is.js +1 -1
  53. package/number/isAbove.js +1 -1
  54. package/number/isAboveOrEqual.js +1 -1
  55. package/number/isBelow.js +1 -1
  56. package/number/isBelowOrEqual.js +1 -1
  57. package/number/isBetween.js +1 -1
  58. package/number/isInteger.js +1 -1
  59. package/number/isIntegerAbove.js +1 -1
  60. package/number/isIntegerAboveOrEqual.js +1 -1
  61. package/number/isIntegerBelow.js +1 -1
  62. package/number/isIntegerBelowOrEqual.js +1 -1
  63. package/number/isIntegerBetween.js +1 -1
  64. package/number/isNumericalNaN.js +1 -1
  65. package/number/randomBetween.js +1 -1
  66. package/number/randomIntBetween.js +1 -1
  67. package/number/round.js +1 -1
  68. package/number/toPercentage.js +1 -1
  69. package/object/define.js +1 -1
  70. package/object/index.js +1 -1
  71. package/object/is.js +2 -3
  72. package/object/isNotEmpty.js +7 -2
  73. package/object/merge.js +1 -1
  74. package/object/pick.js +1 -1
  75. package/package.json +1 -1
  76. package/regexp/index.js +1 -1
  77. package/regexp/is.js +1 -1
  78. package/regexp/sanitize.js +1 -1
  79. package/string/humanizeBytes.d.ts +2 -2
  80. package/string/humanizeBytes.js +6 -6
  81. package/string/humanizeNumber.d.ts +1 -1
  82. package/string/humanizeNumber.js +13 -27
  83. package/string/index.js +1 -1
  84. package/string/is.js +1 -1
  85. package/string/isBetween.js +1 -1
  86. package/string/isNotEmpty.js +1 -1
  87. 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 specific function. An optional resolver function can be passed which allows custom cache key generation.
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.dedupe = void 0;
4
4
  const fnv1A_1 = require("../hash/fnv1A");
package/array/groupBy.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.groupBy = void 0;
4
4
  const isNotEmpty_1 = require("../object/isNotEmpty");
package/array/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isArray = void 0;
4
4
  function isArray(val) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNotEmptyArray = void 0;
4
4
  function isNotEmptyArray(val) {
package/array/join.js CHANGED
@@ -1,7 +1,8 @@
1
- 'use strict';
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 (Number.isInteger(opts.valround) && opts.valround >= 0)
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
- 'use strict';
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 && Object.prototype.toString.call(opts) === '[object Object]' && opts.merge === true;
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
- 'use strict';
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 && Object.prototype.toString.call(opts) === '[object Object]' && opts.merge === true;
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]' ||
@@ -1,22 +1,16 @@
1
- 'use strict';
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
- function mapPrimitive(arr, opts) {
5
+ const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
6
+ function mapPrimitive(arr, opts = {}) {
6
7
  if (!Array.isArray(arr) || !arr.length)
7
8
  return {};
8
- let VALTRIM = false;
9
- let VALROUND = false;
10
- let KEYROUND = false;
11
- if (opts && Object.prototype.toString.call(opts) === '[object Object]') {
12
- if (opts.valtrim === true)
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.shuffle = void 0;
4
4
  function shuffle(arr) {
package/array/sort.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.sort = void 0;
4
4
  const isNotEmpty_1 = require("../object/isNotEmpty");
package/boolean/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.is = exports.isBoolean = void 0;
4
4
  const is_1 = require("./is");
package/boolean/is.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isBoolean = void 0;
4
4
  function isBoolean(val) {
package/caching/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.memoize = void 0;
4
4
  const memoize_1 = require("./memoize");
@@ -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: Function, resolver?: Function): Function;
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 };
@@ -1,17 +1,44 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.memoize = void 0;
4
- function memoize(fn, resolver) {
5
- const memoized = function () {
6
- const key = typeof resolver === 'function' ? resolver.apply(this, arguments) : arguments[0];
7
- if (memoized.cache.has(key))
8
- return memoized.cache.get(key);
9
- const result = fn.apply(this, arguments);
10
- memoized.cache.set(key, result);
11
- return result;
12
- };
13
- memoized.cache = new Map();
14
- return memoized;
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.addUTC = void 0;
4
4
  const is_1 = require("./is");
package/date/diff.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.endOfUTC = void 0;
4
4
  const is_1 = require("./is");
package/date/format.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
- if (intl_formatters.has(hash))
43
- return intl_formatters.get(hash).format(val);
42
+ let formatter = intl_formatters.get(hash);
43
+ if (formatter)
44
+ return formatter.format(val);
44
45
  try {
45
- const instance = new Intl.DateTimeFormat(loc, props);
46
- intl_formatters.set(hash, instance);
47
- return instance.format(val);
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
- if (spec_cache.has(spec))
80
- return spec_cache.get(spec);
81
- const spec_chain = [];
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
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isDate = void 0;
4
4
  function isDate(val) {
package/date/nowUnix.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.nowUnix = void 0;
4
4
  function nowUnix() {
package/date/nowUnixMs.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.nowUnixMs = void 0;
4
4
  function nowUnixMs() {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.startOfUTC = void 0;
4
4
  const is_1 = require("./is");
package/date/toUTC.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.toUTC = void 0;
4
4
  const is_1 = require("./is");
package/date/toUnix.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.toUnix = void 0;
4
4
  const is_1 = require("./is");
package/deep/freeze.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.deepFreeze = void 0;
4
4
  function deep(obj) {
package/deep/get.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.deepGet = void 0;
4
4
  function deepGet(obj, path, get_parent = false) {
package/deep/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.deepSeal = void 0;
4
4
  function deep(obj) {
package/deep/set.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.deepSet = void 0;
4
4
  const RGX_MALICIOUS = /__proto__|constructor|prototype/;
package/equal.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.equal = void 0;
4
4
  const isNumericalNaN_1 = require("./number/isNumericalNaN");
package/formdata/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.is = exports.isFormData = void 0;
4
4
  const is_1 = require("./is");
package/formdata/is.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isFormData = void 0;
4
4
  function isFormData(val) {
package/function/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isFunction = void 0;
4
4
  function isFunction(val) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isAsyncFunction = void 0;
4
4
  function isAsyncFunction(val) {
package/function/noop.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.noop = void 0;
4
4
  function noop() {
@@ -6,5 +6,5 @@
6
6
  *
7
7
  * @returns Promise that resolves with passed value
8
8
  */
9
- declare function noopresolve<T>(val?: T): Promise<T>;
9
+ declare function noopresolve<T>(val?: T): Promise<T | undefined>;
10
10
  export { noopresolve, noopresolve as default };
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.noopresolve = void 0;
4
4
  function noopresolve(val) {
@@ -5,5 +5,5 @@
5
5
  *
6
6
  * @returns Passed value
7
7
  */
8
- declare function noopreturn<T>(val?: T): T;
8
+ declare function noopreturn<T>(val?: T): T | undefined;
9
9
  export { noopreturn, noopreturn as default };
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.noopreturn = void 0;
4
4
  function noopreturn(val) {
package/function/sleep.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.sleep = void 0;
4
4
  function sleep(ms = 1000) {
package/hash/fnv1A.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.fnv1A = void 0;
4
4
  const FNV_32 = 2166136261;
package/hash/guid.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.guid = void 0;
4
4
  const HEX = [];
package/hash/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.guid = exports.fnv1A = void 0;
4
4
  const fnv1A_1 = require("./fnv1A");
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 | false): string;
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: Function, resolver?: Function): Function;
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.Is = void 0;
4
4
  const equal_1 = require("./equal");
package/number/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumber = void 0;
4
4
  function isNumber(val) {
package/number/isAbove.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumberAbove = void 0;
4
4
  function isNumberAbove(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumberAboveOrEqual = void 0;
4
4
  function isNumberAboveOrEqual(val, ref) {
package/number/isBelow.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumberBelow = void 0;
4
4
  function isNumberBelow(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumberBelowOrEqual = void 0;
4
4
  function isNumberBelowOrEqual(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumberBetween = void 0;
4
4
  function isNumberBetween(val, min, max) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isInteger = void 0;
4
4
  function isInteger(val) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isIntegerAbove = void 0;
4
4
  function isIntegerAbove(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isIntegerAboveOrEqual = void 0;
4
4
  function isIntegerAboveOrEqual(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isIntegerBelow = void 0;
4
4
  function isIntegerBelow(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isIntegerBelowOrEqual = void 0;
4
4
  function isIntegerBelowOrEqual(val, ref) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isIntegerBetween = void 0;
4
4
  function isIntegerBetween(val, min, max) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNumericalNaN = void 0;
4
4
  function isNumericalNaN(val) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.randomBetween = void 0;
4
4
  function randomBetween(min = 0, max = 10) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.randomIntBetween = void 0;
4
4
  function randomIntBetween(min = 0, max = 10) {
package/number/round.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.round = void 0;
4
4
  function round(val, precision = 0) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.toPercentage = void 0;
4
4
  const round_1 = require("./round");
package/object/define.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.define = void 0;
4
4
  function define(props, obj = {}) {
package/object/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
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
@@ -1,9 +1,8 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isObject = void 0;
4
- const PROTO_OBJ = '[object Object]';
5
4
  function isObject(val) {
6
- return Object.prototype.toString.call(val) === PROTO_OBJ;
5
+ return Object.prototype.toString.call(val) === '[object Object]';
7
6
  }
8
7
  exports.isObject = isObject;
9
8
  exports.default = isObject;
@@ -1,8 +1,13 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNotEmptyObject = void 0;
4
4
  function isNotEmptyObject(val) {
5
- return Object.prototype.toString.call(val) === '[object Object]' && Object.keys(val).length !== 0;
5
+ if (Object.prototype.toString.call(val) !== '[object Object]')
6
+ return false;
7
+ for (const _ in val) {
8
+ return true;
9
+ }
10
+ return false;
6
11
  }
7
12
  exports.isNotEmptyObject = isNotEmptyObject;
8
13
  exports.default = isNotEmptyObject;
package/object/merge.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.merge = void 0;
4
4
  const PROTO_OBJ = '[object Object]';
package/object/pick.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.pick = void 0;
4
4
  const get_1 = require("../deep/get");
package/package.json CHANGED
@@ -1 +1 @@
1
- { "name": "@valkyriestudios/utils", "version": "12.8.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" }
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sanitize = exports.sanitizeRegExp = exports.is = exports.isRegExp = void 0;
4
4
  const is_1 = require("./is");
package/regexp/is.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isRegExp = void 0;
4
4
  function isRegExp(val) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.sanitizeRegExp = void 0;
4
4
  function sanitizeRegExp(val) {
@@ -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 opts - (default={}) Pass to override options.
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
  */
@@ -1,20 +1,20 @@
1
- 'use strict';
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: has_opts && typeof options.delim === 'string'
8
+ delim: typeof options?.delim === 'string'
9
9
  ? options.delim
10
10
  : ',',
11
- separator: has_opts && typeof options.separator === 'string' && options.separator.trim().length
11
+ separator: typeof options?.separator === 'string' && options.separator.trim().length
12
12
  ? options.separator
13
13
  : '.',
14
- precision: has_opts && Number.isInteger(options.precision) && options.precision >= 0
14
+ precision: (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(options?.precision, 0)
15
15
  ? options.precision
16
16
  : 2,
17
- units: has_opts && Array.isArray(options.units) && options.units.length
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 | false): string;
51
+ declare function humanizeNumber(val: number | string, options?: humanizeNumberOptions): string;
52
52
  export { humanizeNumber, humanizeNumber as default };
@@ -1,34 +1,20 @@
1
- 'use strict';
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 = false) {
7
- let DELIM = ',';
8
- let SEPARATOR = '.';
9
- let PRECISION = 2;
10
- let UNITS = DEFAULT_UNITS;
11
- let DIVIDER = 1000;
12
- let REAL = false;
13
- if (options && Object.prototype.toString.call(options) === '[object Object]') {
14
- if (typeof options.delim === 'string')
15
- DELIM = options.delim;
16
- if (typeof options.separator === 'string' && options.separator.trim().length)
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
- 'use strict';
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
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isString = void 0;
4
4
  function isString(val) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isStringBetween = void 0;
4
4
  function isStringBetween(val, min, max, trimmed = true) {
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.isNotEmptyString = void 0;
4
4
  function isNotEmptyString(val, trimmed = true) {
package/string/shorten.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = exports.shorten = void 0;
4
4
  function shorten(val, length, postfix = '...') {