@valkyriestudios/utils 12.37.0 → 12.38.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 (193) hide show
  1. package/array/groupBy.d.ts +3 -3
  2. package/array/join.d.ts +2 -2
  3. package/array/split.d.ts +3 -3
  4. package/caching/LRU.d.ts +16 -10
  5. package/{array → cjs/array}/groupBy.js +16 -4
  6. package/{array → cjs/array}/join.js +15 -3
  7. package/{array → cjs/array}/split.js +16 -7
  8. package/cjs/caching/LRU.js +123 -0
  9. package/{caching → cjs/caching}/memoize.js +11 -5
  10. package/{date → cjs/date}/format.js +4 -1
  11. package/{date → cjs/date}/isFormat.js +4 -1
  12. package/esm/array/dedupe.js +52 -0
  13. package/esm/array/groupBy.js +43 -0
  14. package/esm/array/index.js +14 -0
  15. package/esm/array/is.js +4 -0
  16. package/esm/array/isNotEmpty.js +4 -0
  17. package/esm/array/join.js +58 -0
  18. package/esm/array/mapFn.js +22 -0
  19. package/esm/array/mapFnAsMap.js +21 -0
  20. package/esm/array/mapKey.js +22 -0
  21. package/esm/array/mapKeyAsMap.js +22 -0
  22. package/esm/array/mapPrimitive.js +33 -0
  23. package/esm/array/shuffle.js +10 -0
  24. package/esm/array/sort.js +137 -0
  25. package/esm/array/split.js +43 -0
  26. package/esm/boolean/index.js +1 -0
  27. package/esm/boolean/is.js +4 -0
  28. package/esm/caching/LRU.js +116 -0
  29. package/esm/caching/index.js +3 -0
  30. package/esm/caching/memoize.js +37 -0
  31. package/esm/date/addUTC.js +41 -0
  32. package/esm/date/convertToDate.js +12 -0
  33. package/esm/date/diff.js +34 -0
  34. package/esm/date/endOfUTC.js +50 -0
  35. package/esm/date/format.js +241 -0
  36. package/esm/date/index.js +15 -0
  37. package/esm/date/is.js +4 -0
  38. package/esm/date/isFormat.js +118 -0
  39. package/esm/date/isLeap.js +9 -0
  40. package/esm/date/nowUnix.js +4 -0
  41. package/esm/date/nowUnixMs.js +4 -0
  42. package/esm/date/setTimeUTC.js +10 -0
  43. package/esm/date/startOfUTC.js +50 -0
  44. package/esm/date/toUTC.js +7 -0
  45. package/esm/date/toUnix.js +7 -0
  46. package/esm/deep/freeze.js +21 -0
  47. package/esm/deep/get.js +84 -0
  48. package/esm/deep/index.js +8 -0
  49. package/esm/deep/seal.js +21 -0
  50. package/esm/deep/set.js +50 -0
  51. package/esm/equal.js +67 -0
  52. package/esm/formdata/index.js +2 -0
  53. package/esm/formdata/is.js +4 -0
  54. package/esm/formdata/toObject.js +89 -0
  55. package/esm/function/debounce.js +39 -0
  56. package/esm/function/index.js +9 -0
  57. package/esm/function/is.js +4 -0
  58. package/esm/function/isAsync.js +4 -0
  59. package/esm/function/noop.js +2 -0
  60. package/esm/function/noopresolve.js +4 -0
  61. package/esm/function/noopreturn.js +4 -0
  62. package/esm/function/sleep.js +6 -0
  63. package/esm/hash/fnv1A.js +51 -0
  64. package/esm/hash/guid.js +31 -0
  65. package/esm/hash/index.js +2 -0
  66. package/esm/is.js +63 -0
  67. package/esm/modules/PubSub.js +187 -0
  68. package/esm/modules/Scheduler.js +343 -0
  69. package/esm/modules/index.js +2 -0
  70. package/esm/number/index.js +37 -0
  71. package/esm/number/is.js +4 -0
  72. package/esm/number/isAbove.js +4 -0
  73. package/esm/number/isAboveOrEqual.js +4 -0
  74. package/esm/number/isBelow.js +4 -0
  75. package/esm/number/isBelowOrEqual.js +4 -0
  76. package/esm/number/isBetween.js +7 -0
  77. package/esm/number/isInteger.js +4 -0
  78. package/esm/number/isIntegerAbove.js +4 -0
  79. package/esm/number/isIntegerAboveOrEqual.js +4 -0
  80. package/esm/number/isIntegerBelow.js +4 -0
  81. package/esm/number/isIntegerBelowOrEqual.js +4 -0
  82. package/esm/number/isIntegerBetween.js +7 -0
  83. package/esm/number/isNumericalNaN.js +4 -0
  84. package/esm/number/randomBetween.js +7 -0
  85. package/esm/number/randomIntBetween.js +7 -0
  86. package/esm/number/round.js +10 -0
  87. package/esm/number/toPercentage.js +9 -0
  88. package/esm/object/define.js +7 -0
  89. package/esm/object/index.js +7 -0
  90. package/esm/object/is.js +4 -0
  91. package/esm/object/isNotEmpty.js +9 -0
  92. package/esm/object/merge.js +31 -0
  93. package/esm/object/omit.js +30 -0
  94. package/esm/object/pick.js +33 -0
  95. package/esm/regexp/index.js +3 -0
  96. package/esm/regexp/is.js +4 -0
  97. package/esm/regexp/sanitize.js +7 -0
  98. package/esm/string/humanizeBytes.js +15 -0
  99. package/esm/string/humanizeNumber.js +40 -0
  100. package/esm/string/index.js +7 -0
  101. package/esm/string/is.js +4 -0
  102. package/esm/string/isBetween.js +12 -0
  103. package/esm/string/isNotEmpty.js +20 -0
  104. package/esm/string/shorten.js +18 -0
  105. package/index.d.ts +19 -15
  106. package/package.json +192 -850
  107. package/caching/LRU.js +0 -72
  108. /package/{array → cjs/array}/dedupe.js +0 -0
  109. /package/{array → cjs/array}/index.js +0 -0
  110. /package/{array → cjs/array}/is.js +0 -0
  111. /package/{array → cjs/array}/isNotEmpty.js +0 -0
  112. /package/{array → cjs/array}/mapFn.js +0 -0
  113. /package/{array → cjs/array}/mapFnAsMap.js +0 -0
  114. /package/{array → cjs/array}/mapKey.js +0 -0
  115. /package/{array → cjs/array}/mapKeyAsMap.js +0 -0
  116. /package/{array → cjs/array}/mapPrimitive.js +0 -0
  117. /package/{array → cjs/array}/shuffle.js +0 -0
  118. /package/{array → cjs/array}/sort.js +0 -0
  119. /package/{boolean → cjs/boolean}/index.js +0 -0
  120. /package/{boolean → cjs/boolean}/is.js +0 -0
  121. /package/{caching → cjs/caching}/index.js +0 -0
  122. /package/{date → cjs/date}/addUTC.js +0 -0
  123. /package/{date → cjs/date}/convertToDate.js +0 -0
  124. /package/{date → cjs/date}/diff.js +0 -0
  125. /package/{date → cjs/date}/endOfUTC.js +0 -0
  126. /package/{date → cjs/date}/index.js +0 -0
  127. /package/{date → cjs/date}/is.js +0 -0
  128. /package/{date → cjs/date}/isLeap.js +0 -0
  129. /package/{date → cjs/date}/nowUnix.js +0 -0
  130. /package/{date → cjs/date}/nowUnixMs.js +0 -0
  131. /package/{date → cjs/date}/setTimeUTC.js +0 -0
  132. /package/{date → cjs/date}/startOfUTC.js +0 -0
  133. /package/{date → cjs/date}/toUTC.js +0 -0
  134. /package/{date → cjs/date}/toUnix.js +0 -0
  135. /package/{deep → cjs/deep}/freeze.js +0 -0
  136. /package/{deep → cjs/deep}/get.js +0 -0
  137. /package/{deep → cjs/deep}/index.js +0 -0
  138. /package/{deep → cjs/deep}/seal.js +0 -0
  139. /package/{deep → cjs/deep}/set.js +0 -0
  140. /package/{equal.js → cjs/equal.js} +0 -0
  141. /package/{formdata → cjs/formdata}/index.js +0 -0
  142. /package/{formdata → cjs/formdata}/is.js +0 -0
  143. /package/{formdata → cjs/formdata}/toObject.js +0 -0
  144. /package/{function → cjs/function}/debounce.js +0 -0
  145. /package/{function → cjs/function}/index.js +0 -0
  146. /package/{function → cjs/function}/is.js +0 -0
  147. /package/{function → cjs/function}/isAsync.js +0 -0
  148. /package/{function → cjs/function}/noop.js +0 -0
  149. /package/{function → cjs/function}/noopresolve.js +0 -0
  150. /package/{function → cjs/function}/noopreturn.js +0 -0
  151. /package/{function → cjs/function}/sleep.js +0 -0
  152. /package/{hash → cjs/hash}/fnv1A.js +0 -0
  153. /package/{hash → cjs/hash}/guid.js +0 -0
  154. /package/{hash → cjs/hash}/index.js +0 -0
  155. /package/{is.js → cjs/is.js} +0 -0
  156. /package/{modules → cjs/modules}/PubSub.js +0 -0
  157. /package/{modules → cjs/modules}/Scheduler.js +0 -0
  158. /package/{modules → cjs/modules}/index.js +0 -0
  159. /package/{number → cjs/number}/index.js +0 -0
  160. /package/{number → cjs/number}/is.js +0 -0
  161. /package/{number → cjs/number}/isAbove.js +0 -0
  162. /package/{number → cjs/number}/isAboveOrEqual.js +0 -0
  163. /package/{number → cjs/number}/isBelow.js +0 -0
  164. /package/{number → cjs/number}/isBelowOrEqual.js +0 -0
  165. /package/{number → cjs/number}/isBetween.js +0 -0
  166. /package/{number → cjs/number}/isInteger.js +0 -0
  167. /package/{number → cjs/number}/isIntegerAbove.js +0 -0
  168. /package/{number → cjs/number}/isIntegerAboveOrEqual.js +0 -0
  169. /package/{number → cjs/number}/isIntegerBelow.js +0 -0
  170. /package/{number → cjs/number}/isIntegerBelowOrEqual.js +0 -0
  171. /package/{number → cjs/number}/isIntegerBetween.js +0 -0
  172. /package/{number → cjs/number}/isNumericalNaN.js +0 -0
  173. /package/{number → cjs/number}/randomBetween.js +0 -0
  174. /package/{number → cjs/number}/randomIntBetween.js +0 -0
  175. /package/{number → cjs/number}/round.js +0 -0
  176. /package/{number → cjs/number}/toPercentage.js +0 -0
  177. /package/{object → cjs/object}/define.js +0 -0
  178. /package/{object → cjs/object}/index.js +0 -0
  179. /package/{object → cjs/object}/is.js +0 -0
  180. /package/{object → cjs/object}/isNotEmpty.js +0 -0
  181. /package/{object → cjs/object}/merge.js +0 -0
  182. /package/{object → cjs/object}/omit.js +0 -0
  183. /package/{object → cjs/object}/pick.js +0 -0
  184. /package/{regexp → cjs/regexp}/index.js +0 -0
  185. /package/{regexp → cjs/regexp}/is.js +0 -0
  186. /package/{regexp → cjs/regexp}/sanitize.js +0 -0
  187. /package/{string → cjs/string}/humanizeBytes.js +0 -0
  188. /package/{string → cjs/string}/humanizeNumber.js +0 -0
  189. /package/{string → cjs/string}/index.js +0 -0
  190. /package/{string → cjs/string}/is.js +0 -0
  191. /package/{string → cjs/string}/isBetween.js +0 -0
  192. /package/{string → cjs/string}/isNotEmpty.js +0 -0
  193. /package/{string → cjs/string}/shorten.js +0 -0
@@ -1,4 +1,4 @@
1
- type Handler<T> = (val: T) => string | number | boolean;
1
+ type Handler<T> = (val: T) => string | number | boolean | undefined;
2
2
  /**
3
3
  * Return a grouped object from an array.
4
4
  * Take Note: This function will automatically filter out any non/empty objects from the array
@@ -15,8 +15,8 @@ type Handler<T> = (val: T) => string | number | boolean;
15
15
  * true: [{tally: 20, name: 'Peter'}, {tally: 40, name: 'Jake'}],
16
16
  * }
17
17
  *
18
- * @param {T[]} arr - Array to group
18
+ * @param {T[]} val - Array or Set to group
19
19
  * @param {Handler<T>|keyof T} handler - String or a function, determines what to group by
20
20
  */
21
- declare function groupBy<T extends Record<string, any>>(arr: T[], handler: Handler<T> | keyof T): Record<string, T[]>;
21
+ declare function groupBy<T extends Record<string, any>>(val: T[] | Set<T>, handler: Handler<T> | keyof T): Record<string, T[]>;
22
22
  export { groupBy, groupBy as default };
package/array/join.d.ts CHANGED
@@ -39,8 +39,8 @@ interface joinOptions {
39
39
  /**
40
40
  * Join an array of values while autofiltering any non-string/non-number elements
41
41
  *
42
- * @param {unknown[]} val - Array of values to join
42
+ * @param {T[]|Set<T>} val - Array or Set of values to join
43
43
  * @param {joinOptions?} opts - Join options
44
44
  */
45
- declare function join(val: unknown[], opts?: joinOptions): string;
45
+ declare function join<T>(val: T[] | Set<T>, opts?: joinOptions): string;
46
46
  export { join, join as default };
package/array/split.d.ts CHANGED
@@ -2,16 +2,16 @@ type SplitOptions<T> = {
2
2
  filter_fn?: (el: T) => boolean;
3
3
  };
4
4
  /**
5
- * Splits the provided array in a set of batches according to the provided size
5
+ * Splits the provided array or set in a set of batches according to the provided size
6
6
  * For Example:
7
7
  * split([1, 2, 3, 4, 5], 2) -> [[1,2],[3,4],[5]]
8
8
  *
9
9
  * For Example w/ filter
10
10
  * split([1, false, 3, 4, 5], 2, {filter_fn: el => isInteger(el)}) -> [[1, 3], [4, 5]]
11
11
  *
12
- * @param {Array} val - Array to split
12
+ * @param {T[]|Set<T>} val - Array or Set to split
13
13
  * @param {number} size - Size of batches
14
14
  * @param {SplitOptions?} opts - Split options
15
15
  */
16
- declare function split<T>(arr: T[], size: number, opts?: SplitOptions<T>): T[][];
16
+ declare function split<T>(arr: T[] | Set<T>, size: number, opts?: SplitOptions<T>): T[][];
17
17
  export { split, split as default };
package/caching/LRU.d.ts CHANGED
@@ -8,7 +8,7 @@ export type LRUCacheOptions = {
8
8
  /**
9
9
  * Least-Recently-Used (LRU) Cache
10
10
  */
11
- declare class LRUCache<K, V> {
11
+ declare class LRUCache<V> {
12
12
  #private;
13
13
  constructor(opts?: LRUCacheOptions);
14
14
  /**
@@ -24,32 +24,38 @@ declare class LRUCache<K, V> {
24
24
  /**
25
25
  * Returns whether or not a key exists in cache
26
26
  *
27
- * @param {K} key - Key to retrieve
27
+ * @param {string} key - Key to retrieve
28
28
  */
29
- has(key: K): boolean;
29
+ has(key: string): boolean;
30
30
  /**
31
31
  * Retrieves a value from the cache
32
32
  *
33
- * @param {K} key - Key to retrieve
34
- * @returns {V | undefined} Either the found value or undefined
33
+ * @param {string} key - Key to retrieve
35
34
  */
36
- get(key: K): V | undefined;
35
+ get(key: string): V | undefined;
37
36
  /**
38
37
  * Sets a value on to the cache
39
38
  *
40
- * @param {K} key - Key to set
39
+ * @param {string} key - Key to set
41
40
  * @param {V} value - Value to set for the key
42
41
  */
43
- set(key: K, value: V): void;
42
+ set(key: string, value: V): void;
44
43
  /**
45
44
  * Removes a single value from the cache
46
45
  *
47
- * @param {K} key - Key to remove
46
+ * @param {string} key - Key to remove
48
47
  */
49
- del(key: K): void;
48
+ del(key: string): void;
50
49
  /**
51
50
  * Clears all contents of the cache
52
51
  */
53
52
  clear(): void;
53
+ /**
54
+ * MARK: Private
55
+ */
56
+ private addToFront;
57
+ private removeNode;
58
+ private moveToFront;
59
+ private evictTail;
54
60
  }
55
61
  export { LRUCache, LRUCache as default };
@@ -5,9 +5,21 @@ exports.default = groupBy;
5
5
  const isNotEmpty_1 = require("../object/isNotEmpty");
6
6
  const FALLBACK = '_';
7
7
  const defaultHandler = () => FALLBACK;
8
- function groupBy(arr, handler) {
9
- if (!Array.isArray(arr))
8
+ function groupBy(val, handler) {
9
+ let normalized;
10
+ if (Array.isArray(val)) {
11
+ if (!val.length)
12
+ return {};
13
+ normalized = val;
14
+ }
15
+ else if (val instanceof Set) {
16
+ if (!val.size)
17
+ return {};
18
+ normalized = [...val];
19
+ }
20
+ else {
10
21
  return {};
22
+ }
11
23
  const acc = {};
12
24
  const n_handler = typeof handler === 'function'
13
25
  ? handler
@@ -16,8 +28,8 @@ function groupBy(arr, handler) {
16
28
  : defaultHandler;
17
29
  let key;
18
30
  let el;
19
- for (let i = 0; i < arr.length; i++) {
20
- el = arr[i];
31
+ for (let i = 0; i < normalized.length; i++) {
32
+ el = normalized[i];
21
33
  if (!(0, isNotEmpty_1.isNotEmptyObject)(el))
22
34
  continue;
23
35
  key = n_handler(el);
@@ -6,8 +6,20 @@ const round_1 = require("../number/round");
6
6
  const isIntegerAboveOrEqual_1 = require("../number/isIntegerAboveOrEqual");
7
7
  const SPACE_RGX = /(\s)+/g;
8
8
  function join(val, opts) {
9
- if (!Array.isArray(val) || !val.length)
9
+ let normalized;
10
+ if (Array.isArray(val)) {
11
+ if (!val.length)
12
+ return '';
13
+ normalized = val;
14
+ }
15
+ else if (val instanceof Set) {
16
+ if (!val.size)
17
+ return '';
18
+ normalized = [...val];
19
+ }
20
+ else {
10
21
  return '';
22
+ }
11
23
  const DELIM = typeof opts?.delim === 'string' ? opts.delim : ' ';
12
24
  const DEDUPE = opts?.dedupe === true ? new Set() : null;
13
25
  const VALTRIM = opts?.valtrim ?? true;
@@ -15,8 +27,8 @@ function join(val, opts) {
15
27
  const VALROUND = (0, isIntegerAboveOrEqual_1.isIntegerAboveOrEqual)(opts?.valround, 0) ? opts.valround : false;
16
28
  let result = '';
17
29
  let has_val = false;
18
- for (let i = 0; i < val.length; i++) {
19
- const el = val[i];
30
+ for (let i = 0; i < normalized.length; i++) {
31
+ const el = normalized[i];
20
32
  let n_el;
21
33
  if (typeof el === 'string') {
22
34
  const trimmed = el.trim();
@@ -3,18 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.split = split;
4
4
  exports.default = split;
5
5
  function split(arr, size, opts) {
6
- if (!Array.isArray(arr) ||
7
- !Number.isInteger(size) ||
6
+ if (!Number.isInteger(size) ||
8
7
  size <= 0)
9
- throw new Error('split requires an array and positive integer size');
8
+ throw new Error('split requires a positive integer size');
9
+ let normalized;
10
+ if (Array.isArray(arr)) {
11
+ normalized = arr;
12
+ }
13
+ else if (arr instanceof Set) {
14
+ normalized = [...arr];
15
+ }
16
+ else {
17
+ throw new Error('split requires an array or set');
18
+ }
10
19
  const FILTER_FN = typeof opts?.filter_fn === 'function' ? opts?.filter_fn : false;
11
20
  const result = [];
12
21
  let cursor = [];
13
22
  let ticker = 0;
14
- const len = arr.length;
23
+ const len = normalized.length;
15
24
  if (FILTER_FN) {
16
25
  for (let i = 0; i < len; i++) {
17
- const el = arr[i];
26
+ const el = normalized[i];
18
27
  if (FILTER_FN && !FILTER_FN(el))
19
28
  continue;
20
29
  ticker++;
@@ -29,8 +38,8 @@ function split(arr, size, opts) {
29
38
  result.push(cursor);
30
39
  }
31
40
  else {
32
- for (let i = 0; i < arr.length; i += size) {
33
- result.push(arr.slice(i, i + size));
41
+ for (let i = 0; i < len; i += size) {
42
+ result.push(normalized.slice(i, i + size));
34
43
  }
35
44
  }
36
45
  return result;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ var _LRUCache_map, _LRUCache_head, _LRUCache_tail, _LRUCache_max_size, _LRUCache_size;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.default = exports.LRUCache = void 0;
19
+ const is_1 = __importDefault(require("../object/is"));
20
+ const isIntegerAbove_1 = __importDefault(require("../number/isIntegerAbove"));
21
+ class LRUCache {
22
+ constructor(opts = {}) {
23
+ _LRUCache_map.set(this, void 0);
24
+ _LRUCache_head.set(this, null);
25
+ _LRUCache_tail.set(this, null);
26
+ _LRUCache_max_size.set(this, void 0);
27
+ _LRUCache_size.set(this, 0);
28
+ const { max_size = 100 } = (0, is_1.default)(opts) ? opts : {};
29
+ __classPrivateFieldSet(this, _LRUCache_map, Object.create(null), "f");
30
+ __classPrivateFieldSet(this, _LRUCache_max_size, (0, isIntegerAbove_1.default)(max_size, 0) ? max_size : 100, "f");
31
+ }
32
+ get max_size() {
33
+ return __classPrivateFieldGet(this, _LRUCache_max_size, "f");
34
+ }
35
+ set max_size(max_size) {
36
+ if (!(0, isIntegerAbove_1.default)(max_size, 0))
37
+ throw new Error('max_size must be a positive integer');
38
+ __classPrivateFieldSet(this, _LRUCache_max_size, max_size, "f");
39
+ while (__classPrivateFieldGet(this, _LRUCache_size, "f") > max_size)
40
+ this.evictTail();
41
+ }
42
+ has(key) {
43
+ return key in __classPrivateFieldGet(this, _LRUCache_map, "f");
44
+ }
45
+ get(key) {
46
+ const node = __classPrivateFieldGet(this, _LRUCache_map, "f")[key];
47
+ if (!node)
48
+ return undefined;
49
+ this.moveToFront(node);
50
+ return node.value;
51
+ }
52
+ set(key, value) {
53
+ var _a;
54
+ let node = __classPrivateFieldGet(this, _LRUCache_map, "f")[key];
55
+ if (node !== undefined) {
56
+ node.value = value;
57
+ this.moveToFront(node);
58
+ }
59
+ else {
60
+ node = { key, value, prev: null, next: null };
61
+ __classPrivateFieldGet(this, _LRUCache_map, "f")[key] = node;
62
+ this.addToFront(node);
63
+ __classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a++, _a), "f");
64
+ if (__classPrivateFieldGet(this, _LRUCache_tail, "f") && __classPrivateFieldGet(this, _LRUCache_size, "f") > __classPrivateFieldGet(this, _LRUCache_max_size, "f")) {
65
+ this.evictTail();
66
+ }
67
+ }
68
+ }
69
+ del(key) {
70
+ var _a;
71
+ const node = __classPrivateFieldGet(this, _LRUCache_map, "f")[key];
72
+ if (!node)
73
+ return;
74
+ this.removeNode(node);
75
+ delete __classPrivateFieldGet(this, _LRUCache_map, "f")[key];
76
+ __classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a--, _a), "f");
77
+ }
78
+ clear() {
79
+ __classPrivateFieldSet(this, _LRUCache_map, Object.create(null), "f");
80
+ __classPrivateFieldSet(this, _LRUCache_head, null, "f");
81
+ __classPrivateFieldSet(this, _LRUCache_tail, null, "f");
82
+ __classPrivateFieldSet(this, _LRUCache_size, 0, "f");
83
+ }
84
+ addToFront(node) {
85
+ node.next = __classPrivateFieldGet(this, _LRUCache_head, "f");
86
+ node.prev = null;
87
+ if (__classPrivateFieldGet(this, _LRUCache_head, "f")) {
88
+ __classPrivateFieldGet(this, _LRUCache_head, "f").prev = node;
89
+ }
90
+ __classPrivateFieldSet(this, _LRUCache_head, node, "f");
91
+ if (!__classPrivateFieldGet(this, _LRUCache_tail, "f")) {
92
+ __classPrivateFieldSet(this, _LRUCache_tail, node, "f");
93
+ }
94
+ }
95
+ removeNode(node) {
96
+ if (node.prev)
97
+ node.prev.next = node.next;
98
+ else
99
+ __classPrivateFieldSet(this, _LRUCache_head, node.next, "f");
100
+ if (node.next)
101
+ node.next.prev = node.prev;
102
+ else
103
+ __classPrivateFieldSet(this, _LRUCache_tail, node.prev, "f");
104
+ node.prev = null;
105
+ node.next = null;
106
+ }
107
+ moveToFront(node) {
108
+ if (__classPrivateFieldGet(this, _LRUCache_head, "f") === node)
109
+ return;
110
+ this.removeNode(node);
111
+ this.addToFront(node);
112
+ }
113
+ evictTail() {
114
+ var _a;
115
+ const old_tail = __classPrivateFieldGet(this, _LRUCache_tail, "f");
116
+ this.removeNode(old_tail);
117
+ delete __classPrivateFieldGet(this, _LRUCache_map, "f")[old_tail.key];
118
+ __classPrivateFieldSet(this, _LRUCache_size, (_a = __classPrivateFieldGet(this, _LRUCache_size, "f"), _a--, _a), "f");
119
+ }
120
+ }
121
+ exports.LRUCache = LRUCache;
122
+ exports.default = LRUCache;
123
+ _LRUCache_map = new WeakMap(), _LRUCache_head = new WeakMap(), _LRUCache_tail = new WeakMap(), _LRUCache_max_size = new WeakMap(), _LRUCache_size = new WeakMap();
@@ -1,17 +1,22 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.memoize = memoize;
4
7
  exports.default = memoize;
5
- const isAsync_1 = require("../function/isAsync");
6
- const isIntegerAbove_1 = require("../number/isIntegerAbove");
7
- const LRU_1 = require("./LRU");
8
+ const isAsync_1 = __importDefault(require("../function/isAsync"));
9
+ const fnv1A_1 = __importDefault(require("../hash/fnv1A"));
10
+ const isIntegerAbove_1 = __importDefault(require("../number/isIntegerAbove"));
11
+ const LRU_1 = __importDefault(require("./LRU"));
8
12
  function memoize(fn, resolver, cache_duration_ms = false, cache_max_size = 100) {
9
13
  const cache_duration = (0, isIntegerAbove_1.default)(cache_duration_ms, 0) ? cache_duration_ms : false;
10
14
  const cache = new LRU_1.default({ max_size: cache_max_size });
11
15
  const isResolverFn = typeof resolver === 'function';
12
16
  const memoized = (0, isAsync_1.default)(fn)
13
17
  ? async function (...args) {
14
- const key = isResolverFn ? resolver(...args) : args[0];
18
+ let key = isResolverFn ? resolver(...args) : args[0];
19
+ key = typeof key === 'string' ? key : Number.isFinite(key) ? String(key) : String((0, fnv1A_1.default)(key));
15
20
  const cached_val = cache.get(key);
16
21
  const now = Date.now();
17
22
  if (cached_val !== undefined && (cache_duration === false || (now - cached_val.ts) < cache_duration)) {
@@ -22,7 +27,8 @@ function memoize(fn, resolver, cache_duration_ms = false, cache_max_size = 100)
22
27
  return result;
23
28
  }
24
29
  : function (...args) {
25
- const key = isResolverFn ? resolver(...args) : args[0];
30
+ let key = isResolverFn ? resolver(...args) : args[0];
31
+ key = typeof key === 'string' ? key : Number.isFinite(key) ? String(key) : String((0, fnv1A_1.default)(key));
26
32
  const cached_val = cache.get(key);
27
33
  const now = Date.now();
28
34
  if (cached_val !== undefined && (cache_duration === false || (now - cached_val.ts) < cache_duration)) {
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.format = format;
4
7
  exports.default = format;
5
8
  const convertToDate_1 = require("./convertToDate");
6
- const LRU_1 = require("../caching/LRU");
9
+ const LRU_1 = __importDefault(require("../caching/LRU"));
7
10
  const WEEK_STARTS = {
8
11
  mon: 'mon',
9
12
  sun: 'sun',
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.isDateFormat = isDateFormat;
4
7
  exports.default = isDateFormat;
5
- const LRU_1 = require("../caching/LRU");
8
+ const LRU_1 = __importDefault(require("../caching/LRU"));
6
9
  const SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g;
7
10
  const TOKENS = [
8
11
  ['YYYY', /\d{4}/.source, (raw, context) => {
@@ -0,0 +1,52 @@
1
+ const REPL_NAN = 'nan';
2
+ const REPL_TRUE = 'true';
3
+ const REPL_FALSE = 'false';
4
+ const REPL_UNDEF = 'undefined';
5
+ const REPL_NULL = 'null';
6
+ function getTypeString(el) {
7
+ switch (typeof el) {
8
+ case 'string':
9
+ return el;
10
+ case 'number':
11
+ return Number.isNaN(el) || !Number.isFinite(el) ? REPL_NAN : String(el);
12
+ case 'boolean':
13
+ return el ? REPL_TRUE : REPL_FALSE;
14
+ case 'undefined':
15
+ return REPL_UNDEF;
16
+ case 'object':
17
+ if (el === null) {
18
+ return REPL_NULL;
19
+ }
20
+ else if (Array.isArray(el) || el.toString() === '[object Object]') {
21
+ return JSON.stringify(el);
22
+ }
23
+ else if (el instanceof RegExp) {
24
+ return el.toString();
25
+ }
26
+ else if (el instanceof Date) {
27
+ return String(el.getTime());
28
+ }
29
+ }
30
+ return '';
31
+ }
32
+ function dedupe(val, opts) {
33
+ if (!Array.isArray(val))
34
+ return [];
35
+ const FILTER_FN = opts?.filter_fn;
36
+ const set = new Set();
37
+ const acc = [];
38
+ let hash;
39
+ const len = val.length;
40
+ for (let i = 0; i < len; i++) {
41
+ const el = val[i];
42
+ if (FILTER_FN && !FILTER_FN(el))
43
+ continue;
44
+ hash = getTypeString(el);
45
+ if (!set.has(hash)) {
46
+ set.add(hash);
47
+ acc.push(el);
48
+ }
49
+ }
50
+ return acc;
51
+ }
52
+ export { dedupe, dedupe as default };
@@ -0,0 +1,43 @@
1
+ import { isNotEmptyObject } from '../object/isNotEmpty';
2
+ const FALLBACK = '_';
3
+ const defaultHandler = () => FALLBACK;
4
+ function groupBy(val, handler) {
5
+ let normalized;
6
+ if (Array.isArray(val)) {
7
+ if (!val.length)
8
+ return {};
9
+ normalized = val;
10
+ }
11
+ else if (val instanceof Set) {
12
+ if (!val.size)
13
+ return {};
14
+ normalized = [...val];
15
+ }
16
+ else {
17
+ return {};
18
+ }
19
+ const acc = {};
20
+ const n_handler = typeof handler === 'function'
21
+ ? handler
22
+ : typeof handler === 'string'
23
+ ? ((el) => el[handler])
24
+ : defaultHandler;
25
+ let key;
26
+ let el;
27
+ for (let i = 0; i < normalized.length; i++) {
28
+ el = normalized[i];
29
+ if (!isNotEmptyObject(el))
30
+ continue;
31
+ key = n_handler(el);
32
+ if (key === undefined || (typeof key === 'string' && !key.length))
33
+ key = FALLBACK;
34
+ if (!acc[key]) {
35
+ acc[key] = [el];
36
+ }
37
+ else {
38
+ acc[key].push(el);
39
+ }
40
+ }
41
+ return acc;
42
+ }
43
+ export { groupBy, groupBy as default };
@@ -0,0 +1,14 @@
1
+ export { dedupe } from './dedupe';
2
+ export { join } from './join';
3
+ export { mapFn } from './mapFn';
4
+ export { mapFnAsMap } from './mapFnAsMap';
5
+ export { mapKey } from './mapKey';
6
+ export { mapKeyAsMap } from './mapKeyAsMap';
7
+ export { mapPrimitive } from './mapPrimitive';
8
+ export { groupBy } from './groupBy';
9
+ export { shuffle } from './shuffle';
10
+ export { split } from './split';
11
+ export { sort } from './sort';
12
+ export { isArray } from './is';
13
+ export { isNotEmptyArray } from './isNotEmpty';
14
+ export { isNotEmptyArray as isNeArray } from './isNotEmpty';
@@ -0,0 +1,4 @@
1
+ function isArray(val) {
2
+ return Array.isArray(val);
3
+ }
4
+ export { isArray, isArray as default };
@@ -0,0 +1,4 @@
1
+ function isNotEmptyArray(val) {
2
+ return Array.isArray(val) && val.length !== 0;
3
+ }
4
+ export { isNotEmptyArray, isNotEmptyArray as default };
@@ -0,0 +1,58 @@
1
+ import { round } from '../number/round';
2
+ import { isIntegerAboveOrEqual } from '../number/isIntegerAboveOrEqual';
3
+ const SPACE_RGX = /(\s)+/g;
4
+ function join(val, opts) {
5
+ let normalized;
6
+ if (Array.isArray(val)) {
7
+ if (!val.length)
8
+ return '';
9
+ normalized = val;
10
+ }
11
+ else if (val instanceof Set) {
12
+ if (!val.size)
13
+ return '';
14
+ normalized = [...val];
15
+ }
16
+ else {
17
+ return '';
18
+ }
19
+ const DELIM = typeof opts?.delim === 'string' ? opts.delim : ' ';
20
+ const DEDUPE = opts?.dedupe === true ? new Set() : null;
21
+ const VALTRIM = opts?.valtrim ?? true;
22
+ const INNERTRIM = opts?.innertrim ?? false;
23
+ const VALROUND = isIntegerAboveOrEqual(opts?.valround, 0) ? opts.valround : false;
24
+ let result = '';
25
+ let has_val = false;
26
+ for (let i = 0; i < normalized.length; i++) {
27
+ const el = normalized[i];
28
+ let n_el;
29
+ if (typeof el === 'string') {
30
+ const trimmed = el.trim();
31
+ if (!trimmed)
32
+ continue;
33
+ n_el = VALTRIM ? trimmed : el;
34
+ if (INNERTRIM)
35
+ n_el = n_el.replace(SPACE_RGX, ' ');
36
+ }
37
+ else if (Number.isFinite(el)) {
38
+ n_el = '' + (VALROUND !== false ? round(el, VALROUND) : el);
39
+ }
40
+ else {
41
+ continue;
42
+ }
43
+ if (DEDUPE) {
44
+ if (DEDUPE.has(n_el))
45
+ continue;
46
+ DEDUPE.add(n_el);
47
+ }
48
+ if (has_val) {
49
+ result = result + DELIM + n_el;
50
+ }
51
+ else {
52
+ result = n_el;
53
+ has_val = true;
54
+ }
55
+ }
56
+ return opts?.trim ?? true ? result.trim() : result;
57
+ }
58
+ export { join, join as default };
@@ -0,0 +1,22 @@
1
+ import { merge } from '../object/merge';
2
+ function mapFn(arr, fn, opts) {
3
+ if ((!Array.isArray(arr) || !arr.length) ||
4
+ typeof fn !== 'function')
5
+ return {};
6
+ const MERGE = opts?.merge === true;
7
+ const TRANSFORM_FN = opts?.transform_fn;
8
+ const map = {};
9
+ for (let i = 0; i < arr.length; i++) {
10
+ const el = arr[i];
11
+ if (Object.prototype.toString.call(el) !== '[object Object]')
12
+ continue;
13
+ let hash = fn(el);
14
+ if (Number.isFinite(hash) || (typeof hash === 'string' && hash.length)) {
15
+ hash = hash + '';
16
+ const transformed = TRANSFORM_FN ? TRANSFORM_FN(el) : el;
17
+ map[hash] = MERGE && hash in map ? merge(map[hash], transformed, { union: true }) : transformed;
18
+ }
19
+ }
20
+ return map;
21
+ }
22
+ export { mapFn, mapFn as default };
@@ -0,0 +1,21 @@
1
+ import { merge } from '../object/merge';
2
+ function mapFnAsMap(arr, fn, opts) {
3
+ if ((!Array.isArray(arr) || !arr.length) ||
4
+ typeof fn !== 'function')
5
+ return new Map();
6
+ const MERGE = opts?.merge === true;
7
+ const TRANSFORM_FN = opts?.transform_fn;
8
+ const map = new Map();
9
+ for (let i = 0; i < arr.length; i++) {
10
+ const el = arr[i];
11
+ if (Object.prototype.toString.call(el) !== '[object Object]')
12
+ continue;
13
+ const hash = fn(el);
14
+ if (Number.isFinite(hash) || (typeof hash === 'string' && hash.length > 0)) {
15
+ const transformed = TRANSFORM_FN ? TRANSFORM_FN(el) : el;
16
+ map.set(hash, MERGE && map.has(hash) ? merge(map.get(hash), transformed, { union: true }) : transformed);
17
+ }
18
+ }
19
+ return map;
20
+ }
21
+ export { mapFnAsMap, mapFnAsMap as default };
@@ -0,0 +1,22 @@
1
+ import { merge } from '../object/merge';
2
+ function mapKey(arr, key, opts) {
3
+ if (!Array.isArray(arr) ||
4
+ !arr.length ||
5
+ typeof key !== 'string' ||
6
+ !key.length)
7
+ return {};
8
+ const FILTER_FN = opts?.filter_fn;
9
+ const MERGE = opts?.merge === true;
10
+ const TRANSFORMER = opts?.transform_fn;
11
+ const map = {};
12
+ for (let i = 0; i < arr.length; i++) {
13
+ const el = arr[i];
14
+ const el_key = el?.[key];
15
+ if (el_key !== undefined && (!FILTER_FN || FILTER_FN(el))) {
16
+ const transformed = TRANSFORMER ? TRANSFORMER(el) : el;
17
+ map[el_key] = MERGE && el_key in map ? merge(map[el_key], transformed, { union: true }) : transformed;
18
+ }
19
+ }
20
+ return map;
21
+ }
22
+ export { mapKey, mapKey as default };