@oscarpalmer/atoms 0.193.0 → 0.194.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 (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
@@ -10,10 +10,10 @@ function getHandler(input) {
10
10
  case "string": return (item) => item[input];
11
11
  default:
12
12
  if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
13
- throw new TypeError(MESSAGE_HANDLER);
13
+ throw new TypeError(FUZZY_MESSAGE_HANDLER);
14
14
  }
15
15
  }
16
- function getItems(items) {
16
+ function getFuzzyItems(items) {
17
17
  return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
18
18
  }
19
19
  function getFuzzyOptions(input, state) {
@@ -37,22 +37,22 @@ function getFuzzyState(items, input) {
37
37
  }
38
38
  function getTolerance(input, state) {
39
39
  if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
40
- return state?.tolerance ?? PROXIMITY_THRESHOLD;
40
+ return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
41
41
  }
42
42
  function fuzzy(items, configuration) {
43
- if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
43
+ if (!Array.isArray(items)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
44
44
  const state = getFuzzyState(items, configuration);
45
45
  const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : getFuzzyOptions(options, state)) };
46
46
  Object.defineProperties(instance, {
47
47
  items: {
48
+ enumerable: true,
48
49
  get: () => state.items.slice(),
49
- set: (items) => {
50
- if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
51
- state.items = items.slice();
52
- state.strings = items.map(state.handler);
53
- }
50
+ set: (value) => setItems(state, value)
54
51
  },
55
- strings: { get: () => state.strings.slice() }
52
+ strings: {
53
+ enumerable: true,
54
+ get: () => state.strings.slice()
55
+ }
56
56
  });
57
57
  return Object.freeze(instance);
58
58
  }
@@ -96,14 +96,14 @@ function getScore(haystack, needle) {
96
96
  if (haystackIndex === 0) score += 1;
97
97
  if (previousMatchIndex !== -1) {
98
98
  const gap = haystackIndex - previousMatchIndex - 1;
99
- score += Math.max(0, PROXIMITY_THRESHOLD - gap);
99
+ score += Math.max(0, FUZZY_PROXIMITY_THRESHOLD - gap);
100
100
  }
101
101
  previousMatchIndex = haystackIndex;
102
102
  needleIndex += 1;
103
103
  }
104
104
  if (needleIndex === needleLength) break;
105
105
  }
106
- score -= Math.floor(lowerCaseHaystack.length / LENGTH_DIVISOR);
106
+ score -= Math.floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
107
107
  return Math.max(0, score);
108
108
  }
109
109
  function search(items, strings, input, options) {
@@ -146,17 +146,22 @@ function search(items, strings, input, options) {
146
146
  for (let index = 0; index < length; index += 1) {
147
147
  const key = keys[index];
148
148
  if (maxScore - key > options.tolerance) break;
149
- similar.push(...getItems(scored[key]));
149
+ similar.push(...getFuzzyItems(scored[key]));
150
150
  }
151
151
  }
152
- result.exact = getItems(options.limit == null ? exact : exact.slice(0, options.limit));
152
+ result.exact = getFuzzyItems(options.limit == null ? exact : exact.slice(0, options.limit));
153
153
  if (options.limit == null) result.similar = similar;
154
154
  else result.similar = similar.slice(0, options.limit - result.exact.length);
155
155
  return result;
156
156
  }
157
- const LENGTH_DIVISOR = 3;
158
- const MESSAGE_ARRAY = "Fuzzy requires an array of items";
159
- const MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
160
- const PROXIMITY_THRESHOLD = 5;
157
+ function setItems(state, value) {
158
+ if (!Array.isArray(value)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
159
+ state.items = value.slice();
160
+ state.strings = value.map(state.handler);
161
+ }
162
+ const FUZZY_LENGTH_DIVISOR = 3;
163
+ const FUZZY_MESSAGE_ARRAY = "Fuzzy requires an array of items";
164
+ const FUZZY_MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
165
+ const FUZZY_PROXIMITY_THRESHOLD = 5;
161
166
  //#endregion
162
167
  export { fuzzy, fuzzyMatch };
@@ -37,16 +37,16 @@ function getUuid(html) {
37
37
  crypto.getRandomValues(bytes);
38
38
  bytes[6] = bytes[6] & 15 | 64;
39
39
  bytes[8] = bytes[8] & 63 | 128;
40
- const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, ZERO)).join("");
40
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, STRING_ZERO)).join("");
41
41
  const first = hex.substring(0, 8);
42
- if (forHTML && NUMERICAL_PREFIX_PATTERN.test(first)) continue;
42
+ if (forHTML && STRING_NUMERICAL_PREFIX_PATTERN.test(first)) continue;
43
43
  return [
44
44
  first,
45
45
  hex.substring(8, 12),
46
46
  hex.substring(12, 16),
47
47
  hex.substring(16, 20),
48
48
  hex.substring(20, 32)
49
- ].join(forHTML ? DELIMITER_UUID_HTML : DELIMITER_UUID_DEFAULT);
49
+ ].join(forHTML ? STRING_DELIMITER_UUID_HTML : STRING_DELIMITER_UUID_DEFAULT);
50
50
  }
51
51
  }
52
52
  /**
@@ -89,9 +89,9 @@ function truncate(value, length, suffix) {
89
89
  const truncatedLength = length - actualSuffixLength;
90
90
  return `${value.slice(0, truncatedLength)}${actualSuffix}`;
91
91
  }
92
- const DELIMITER_UUID_DEFAULT = "-";
93
- const DELIMITER_UUID_HTML = "_";
94
- const NUMERICAL_PREFIX_PATTERN = /^\d/;
95
- const ZERO = "0";
92
+ const STRING_DELIMITER_UUID_DEFAULT = "-";
93
+ const STRING_DELIMITER_UUID_HTML = "_";
94
+ const STRING_NUMERICAL_PREFIX_PATTERN = /^\d/;
95
+ const STRING_ZERO = "0";
96
96
  //#endregion
97
97
  export { dedent, getString, getUuid, join, parse, trim, truncate, words };
@@ -11,8 +11,8 @@ import { lowerCase } from "./case.mjs";
11
11
  function deburr(value) {
12
12
  if (typeof value !== "string") return "";
13
13
  deburrMemoizer ??= memoize((value) => {
14
- let deburred = value.normalize(DEBURR_NORMALIZATION).replace(DEBURR_PATTERN_SIMPLE, "");
15
- deburred = deburred.replace(DEBURR_PATTERN_CHARACTERS, (_, character) => DEBURR_CHARACTERS[character]);
14
+ let deburred = value.normalize(NORMALIZE_DEBURR_NORMALIZATION).replace(NORMALIZE_DEBURR_PATTERN_SIMPLE, "");
15
+ deburred = deburred.replace(NORMALIZE_DEBURR_PATTERN_CHARACTERS, (_, character) => NORMALIZE_DEBURR_CHARACTERS[character]);
16
16
  return deburred;
17
17
  });
18
18
  return deburrMemoizer.run(value);
@@ -56,13 +56,13 @@ function normalizeString(value, options) {
56
56
  if (typeof value !== "string") return "";
57
57
  let result = value;
58
58
  if (options.trim) result = result.trim();
59
- if (options.whitespace) result = result.replace(WHITESPACE_PATTERN, WHITESPACE_REPLACEMENT);
59
+ if (options.whitespace) result = result.replace(NORMALIZE_WHITESPACE_PATTERN, NORMALIZE_WHITESPACE_REPLACEMENT);
60
60
  if (options.deburr) result = deburr(result);
61
61
  if (options.lowerCase) result = lowerCase(result);
62
- if (options.special) result = result.replace(SPECIAL_PATTERN, SPECIAL_REPLACEMENT);
63
- return result.normalize(NORMALIZATION_NORMALIZATION);
62
+ if (options.special) result = result.replace(NORMALIZE_SPECIAL_PATTERN, NORMALIZE_SPECIAL_REPLACEMENT);
63
+ return result.normalize(NORMALIZE_NORMALIZATION_NORMALIZATION);
64
64
  }
65
- const DEBURR_CHARACTERS = {
65
+ const NORMALIZE_DEBURR_CHARACTERS = {
66
66
  Æ: "AE",
67
67
  æ: "ae",
68
68
  Ð: "D",
@@ -94,14 +94,14 @@ const DEBURR_CHARACTERS = {
94
94
  Ŧ: "T",
95
95
  ŧ: "t"
96
96
  };
97
- const DEBURR_NORMALIZATION = "NFD";
98
- const DEBURR_PATTERN_CHARACTERS = new RegExp(`(${Object.keys(DEBURR_CHARACTERS).join("|")})`, "g");
99
- const DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
100
- const NORMALIZATION_NORMALIZATION = "NFC";
101
- const SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
102
- const SPECIAL_REPLACEMENT = "";
103
- const WHITESPACE_PATTERN = /\s+/g;
104
- const WHITESPACE_REPLACEMENT = " ";
97
+ const NORMALIZE_DEBURR_NORMALIZATION = "NFD";
98
+ const NORMALIZE_DEBURR_PATTERN_CHARACTERS = new RegExp(`(${Object.keys(NORMALIZE_DEBURR_CHARACTERS).join("|")})`, "g");
99
+ const NORMALIZE_DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
100
+ const NORMALIZE_NORMALIZATION_NORMALIZATION = "NFC";
101
+ const NORMALIZE_SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
102
+ const NORMALIZE_SPECIAL_REPLACEMENT = "";
103
+ const NORMALIZE_WHITESPACE_PATTERN = /\s+/g;
104
+ const NORMALIZE_WHITESPACE_REPLACEMENT = " ";
105
105
  let deburrMemoizer;
106
106
  //#endregion
107
107
  export { deburr, initializeNormalizer, normalize };
@@ -11,7 +11,7 @@ function getTemplateOptions(input) {
11
11
  const options = isPlainObject(input) ? input : {};
12
12
  return {
13
13
  ignoreCase: options.ignoreCase === true,
14
- pattern: options.pattern instanceof RegExp ? options.pattern : EXPRESSION_VARIABLE
14
+ pattern: options.pattern instanceof RegExp ? options.pattern : TEMPLATE_EXPRESSION_VARIABLE
15
15
  };
16
16
  }
17
17
  function handleTemplate(value, pattern, ignoreCase, variables) {
@@ -46,6 +46,6 @@ function template(value, ...parameters) {
46
46
  return handleTemplate(value, pattern, ignoreCase, parameters[0]);
47
47
  }
48
48
  template.initialize = initializeTemplater;
49
- const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
49
+ const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
50
50
  //#endregion
51
51
  export { initializeTemplater, template };
@@ -12,21 +12,21 @@ clone.handlers = getSelfHandlers(clone, {
12
12
  clone.deregister = deregisterCloner;
13
13
  clone.register = registerCloner;
14
14
  function cloneArrayBuffer(value, depth, references) {
15
- if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
15
+ if (typeof depth === "number" && depth >= CLONE_MAX_DEPTH) return value;
16
16
  const cloned = new ArrayBuffer(value.byteLength);
17
17
  new Uint8Array(cloned).set(new Uint8Array(value));
18
18
  references?.set(value, cloned);
19
19
  return cloned;
20
20
  }
21
21
  function cloneDataView(value, depth, references) {
22
- if (depth >= MAX_CLONE_DEPTH) return value;
22
+ if (depth >= CLONE_MAX_DEPTH) return value;
23
23
  const buffer = cloneArrayBuffer(value.buffer);
24
24
  const cloned = new DataView(buffer, value.byteOffset, value.byteLength);
25
25
  references.set(value, cloned);
26
26
  return cloned;
27
27
  }
28
28
  function cloneMap(map, depth, references, flat) {
29
- if (depth >= MAX_CLONE_DEPTH) return map;
29
+ if (depth >= CLONE_MAX_DEPTH) return map;
30
30
  const cloned = /* @__PURE__ */ new Map();
31
31
  const entries = map.entries();
32
32
  for (const entry of entries) cloned.set(flat ? entry[0] : cloneValue(entry[0], depth + 1, references, false), flat ? entry[1] : cloneValue(entry[1], depth + 1, references, false));
@@ -34,13 +34,13 @@ function cloneMap(map, depth, references, flat) {
34
34
  return cloned;
35
35
  }
36
36
  function cloneNode(node, depth, references) {
37
- if (depth >= MAX_CLONE_DEPTH) return node;
37
+ if (depth >= CLONE_MAX_DEPTH) return node;
38
38
  const cloned = node.cloneNode(true);
39
39
  references.set(node, cloned);
40
40
  return cloned;
41
41
  }
42
42
  function cloneObject(value, depth, references, flat) {
43
- if (flat || depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
43
+ if (flat || depth >= CLONE_MAX_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
44
44
  const cloned = Array.isArray(value) ? [] : {};
45
45
  const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
46
46
  const { length } = keys;
@@ -52,14 +52,14 @@ function cloneObject(value, depth, references, flat) {
52
52
  return cloned;
53
53
  }
54
54
  function cloneRegularExpression(value, depth, references) {
55
- if (depth >= MAX_CLONE_DEPTH) return value;
55
+ if (depth >= CLONE_MAX_DEPTH) return value;
56
56
  const cloned = new RegExp(value.source, value.flags);
57
57
  cloned.lastIndex = value.lastIndex;
58
58
  references.set(value, cloned);
59
59
  return cloned;
60
60
  }
61
61
  function cloneSet(set, depth, references, flat) {
62
- if (depth >= MAX_CLONE_DEPTH) return set;
62
+ if (depth >= CLONE_MAX_DEPTH) return set;
63
63
  const cloned = /* @__PURE__ */ new Set();
64
64
  const values = [...set.values()];
65
65
  const { length } = values;
@@ -68,7 +68,7 @@ function cloneSet(set, depth, references, flat) {
68
68
  return cloned;
69
69
  }
70
70
  function cloneTypedArray(value, depth, references) {
71
- if (depth >= MAX_CLONE_DEPTH) return value;
71
+ if (depth >= CLONE_MAX_DEPTH) return value;
72
72
  const cloned = new value.constructor(value);
73
73
  references.set(value, cloned);
74
74
  return cloned;
@@ -129,7 +129,7 @@ function registerCloner(constructor, handler) {
129
129
  clone.handlers.register(constructor, handler);
130
130
  }
131
131
  function tryStructuredClone(value, depth, references) {
132
- if (depth >= MAX_CLONE_DEPTH) return value;
132
+ if (depth >= CLONE_MAX_DEPTH) return value;
133
133
  try {
134
134
  const cloned = structuredClone(value);
135
135
  references.set(value, cloned);
@@ -139,6 +139,6 @@ function tryStructuredClone(value, depth, references) {
139
139
  return value;
140
140
  }
141
141
  }
142
- const MAX_CLONE_DEPTH = 100;
142
+ const CLONE_MAX_DEPTH = 100;
143
143
  //#endregion
144
144
  export { clone, copy, deregisterCloner, registerCloner };
@@ -2,7 +2,7 @@ import { isArrayOrPlainObject } from "../internal/is.mjs";
2
2
  import { join } from "../internal/string.mjs";
3
3
  //#region src/value/smush.ts
4
4
  function flattenObject(value, depth, smushed, prefix) {
5
- if (depth >= MAX_DEPTH) return {};
5
+ if (depth >= SMUSH_MAX_DEPTH) return {};
6
6
  if (smushed.has(value)) return smushed.get(value);
7
7
  const keys = Object.keys(value);
8
8
  const { length } = keys;
@@ -34,6 +34,6 @@ function flattenObject(value, depth, smushed, prefix) {
34
34
  function smush(value) {
35
35
  return typeof value === "object" && value !== null ? flattenObject(value, 0, /* @__PURE__ */ new WeakMap()) : {};
36
36
  }
37
- const MAX_DEPTH = 100;
37
+ const SMUSH_MAX_DEPTH = 100;
38
38
  //#endregion
39
39
  export { smush };
package/package.json CHANGED
@@ -1,9 +1,18 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.193.0",
3
+ "version": "0.194.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
+ "array",
7
+ "color",
6
8
  "helper",
9
+ "observable",
10
+ "promise",
11
+ "query",
12
+ "queue",
13
+ "random",
14
+ "result",
15
+ "subscription",
7
16
  "utility"
8
17
  ],
9
18
  "license": "MIT",
@@ -17,8 +26,7 @@
17
26
  },
18
27
  "files": [
19
28
  "dist",
20
- "plugin",
21
- "src"
29
+ "plugin"
22
30
  ],
23
31
  "type": "module",
24
32
  "module": "./dist/index.mjs",
@@ -257,8 +265,8 @@
257
265
  "watch": "npx vite build --watch"
258
266
  },
259
267
  "devDependencies": {
260
- "@oxlint/plugins": "^1.79",
261
- "@types/node": "^26.2",
268
+ "@oxlint/plugins": "^1.80",
269
+ "@types/node": "^26.4",
262
270
  "@vitest/coverage-istanbul": "^4.1",
263
271
  "eslint": "^10.9",
264
272
  "jsdom": "^30",
@@ -1,73 +0,0 @@
1
- import {COMPARE_SETS_DIFFERENCE, compareSets} from '../internal/array/sets';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get the items from the first array that are not in the second array
8
- *
9
- * @param first First array
10
- * @param second Second array
11
- * @param callback Callback to get an item's value for comparison
12
- * @returns Unique values from the first array
13
- *
14
- * @example
15
- * ```typescript
16
- * difference(
17
- * [{id: 1}, {id: 2}, {id: 3}],
18
- * [{id: 2}, {id: 4}],
19
- * item => item.id,
20
- * ); // => [{id: 1}, {id: 3}]
21
- * ```
22
- */
23
- export function difference<First, Second>(
24
- first: First[],
25
- second: Second[],
26
- callback: (item: First | Second) => unknown,
27
- ): First[];
28
-
29
- /**
30
- * Get the items from the first array that are not in the second array
31
- *
32
- * @param first First array
33
- * @param second Second array
34
- * @param key Key to get an item's value for comparison
35
- * @returns Unique values from the first array
36
- *
37
- * @example
38
- * ```typescript
39
- * difference(
40
- * [{id: 1}, {id: 2}, {id: 3}],
41
- * [{id: 2}, {id: 4}],
42
- * 'id',
43
- * ); // => [{id: 1}, {id: 3}]
44
- * ```
45
- */
46
- export function difference<
47
- First extends PlainObject,
48
- Second extends PlainObject,
49
- SharedKey extends keyof First & keyof Second,
50
- >(first: First[], second: Second[], key: SharedKey): First[];
51
-
52
- /**
53
- * Get the items from the first array that are not in the second array
54
- *
55
- * @param first First array
56
- * @param second Second array
57
- * @returns Unique values from the first array
58
- *
59
- * @example
60
- * ```typescript
61
- * difference(
62
- * [1, 2, 3],
63
- * [2, 4],
64
- * ); // => [1, 3]
65
- * ```
66
- */
67
- export function difference<First, Second>(first: First[], second: Second[]): First[];
68
-
69
- export function difference(first: unknown[], second: unknown[], key?: unknown): unknown[] {
70
- return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
71
- }
72
-
73
- // #endregion
@@ -1,93 +0,0 @@
1
- import {FIND_VALUE_INDEX, findValue} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Does an item with a specific value exist in the array?
8
- *
9
- * @param array Array to search in
10
- * @param callback Callback to get an item's value for matching
11
- * @param value Value to match against
12
- * @returns `true` if the item exists in the array, otherwise `false`
13
- *
14
- * @example
15
- * ```typescript
16
- * exists(
17
- * [{id: 1}, {id: 2}, {id: 3}],
18
- * item => item.id,
19
- * 2,
20
- * ); // => true
21
- * ```
22
- */
23
- export function exists<
24
- Item,
25
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
26
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): boolean;
27
-
28
- /**
29
- * Does an item with a specific value exist in the array?
30
- *
31
- * @param array Array to search in
32
- * @param key Key to get an item's value for matching
33
- * @param value Value to match against
34
- * @returns `true` if the item exists in the array, otherwise `false`
35
- *
36
- * @example
37
- * ```typescript
38
- * exists(
39
- * [{id: 1}, {id: 2}, {id: 3}],
40
- * 'id',
41
- * 2,
42
- * ); // => true
43
- * ```
44
- */
45
- export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
46
- array: Item[],
47
- key: ItemKey,
48
- value: Item[ItemKey],
49
- ): boolean;
50
-
51
- /**
52
- * Does an item in the array match the filter?
53
- *
54
- * @param array Array to search in
55
- * @param filter Filter callback to match items
56
- * @returns `true` if a matching item exists, otherwise `false`
57
- *
58
- * @example
59
- * ```typescript
60
- * exists(
61
- * [{id: 1}, {id: 2}, {id: 3}],
62
- * item => item.id === 2,
63
- * ); // => true
64
- * ```
65
- */
66
- export function exists<Item>(
67
- array: Item[],
68
- filter: (item: Item, index: number, array: Item[]) => boolean,
69
- ): boolean;
70
-
71
- /**
72
- * Does the item exist in the array?
73
- *
74
- * @param array Array to search in
75
- * @param item Item to search for
76
- * @returns `true` if the item exists in the array, otherwise `false`
77
- *
78
- * @example
79
- * ```typescript
80
- * exists([1, 2, 3], 2); // => true
81
- * ```
82
- */
83
- export function exists<Item>(array: Item[], item: Item): boolean;
84
-
85
- export function exists(array: unknown[], ...parameters: unknown[]): boolean {
86
- if (parameters.length === 1 && typeof parameters[0] !== 'function') {
87
- return Array.isArray(array) ? array.includes(parameters[0]) : false;
88
- }
89
-
90
- return findValue(FIND_VALUE_INDEX, array, parameters, false) > -1;
91
- }
92
-
93
- // #endregion
@@ -1,182 +0,0 @@
1
- import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Get a filtered array of items that do not match the value
8
- *
9
- * _Available as `exclude` and `filter.remove`_
10
- *
11
- * @param array Array to search in
12
- * @param callback Callback to get an item's value for matching
13
- * @param value Value to match against
14
- * @returns Filtered array of items that do not match the filter
15
- *
16
- * @example
17
- * ```typescript
18
- * exclude(
19
- * [{id: 1}, {id: 2}, {id: 3}],
20
- * item => item.id,
21
- * 2,
22
- * ); // => [{id: 1}, {id: 3}]
23
- * ```
24
- */
25
- export function exclude<
26
- Item,
27
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
28
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
29
-
30
- /**
31
- * Get a filtered array of items that do not match the value
32
- *
33
- * _Available as `exclude` and `filter.remove`_
34
- *
35
- * @param array Array to search in
36
- * @param key Key to get an item's value for matching
37
- * @param value Value to match against
38
- * @returns Filtered array of items that do not match the filter
39
- *
40
- * @example
41
- * ```typescript
42
- * exclude(
43
- * [{id: 1}, {id: 2}, {id: 3}],
44
- * 'id',
45
- * 2,
46
- * ); // => [{id: 1}, {id: 3}]
47
- * ```
48
- */
49
- export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
50
- array: Item[],
51
- key: ItemKey,
52
- value: Item[ItemKey],
53
- ): unknown[];
54
-
55
- /**
56
- * Get a filtered array of items that do not match the filter
57
- *
58
- * _Available as `exclude` and `filter.remove`_
59
- *
60
- * @param array Array to search in
61
- * @param filter Filter callback to match items
62
- * @returns Filtered array of items that do not match the filter
63
- *
64
- * @example
65
- * ```typescript
66
- * exclude(
67
- * [{id: 1}, {id: 2}, {id: 3}],
68
- * item => item.id === 2,
69
- * ); // => [{id: 1}, {id: 3}]
70
- * ```
71
- */
72
- export function exclude<Item>(
73
- array: Item[],
74
- filter: (item: Item, index: number, array: Item[]) => boolean,
75
- ): unknown[];
76
-
77
- /**
78
- * Get a filtered array of items that do not match the given item
79
- *
80
- * _Available as `exclude` and `filter.remove`_
81
- *
82
- * @param array Array to search in
83
- * @param item Item to match against
84
- * @returns Filtered array of items that do not match the given item
85
- *
86
- * @example
87
- * ```typescript
88
- * exclude([1, 2, 3], 2); // => [1, 3]
89
- * ```
90
- */
91
- export function exclude<Item>(array: Item[], item: Item): unknown[];
92
-
93
- export function exclude(array: unknown[], ...parameters: unknown[]): unknown[] {
94
- return findValues(FIND_VALUES_ALL, array, parameters).notMatched;
95
- }
96
-
97
- /**
98
- * Get a filtered array of items
99
- *
100
- * @param array Array to search in
101
- * @param callback Callback to get an item's value for matching
102
- * @param value Value to match against
103
- * @returns Filtered array of items
104
- *
105
- * @example
106
- * ```typescript
107
- * filter(
108
- * [{id: 1}, {id: 2}, {id: 3}],
109
- * item => item.id,
110
- * 2,
111
- * ); // => [{id: 2}]
112
- * ```
113
- */
114
- export function filter<
115
- Item,
116
- Callback extends (item: Item, index: number, array: Item[]) => unknown,
117
- >(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
118
-
119
- /**
120
- * Get a filtered array of items
121
- *
122
- * @param array Array to search in
123
- * @param key Key to get an item's value for matching
124
- * @param value Value to match against
125
- * @returns Filtered array of items
126
- *
127
- * @example
128
- * ```typescript
129
- * filter(
130
- * [{id: 1}, {id: 2}, {id: 3}],
131
- * 'id',
132
- * 2,
133
- * ); // => [{id: 2}]
134
- * ```
135
- */
136
- export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
137
- array: Item[],
138
- key: ItemKey,
139
- value: Item[ItemKey],
140
- ): Item[];
141
-
142
- /**
143
- * Get a filtered array of items matching the filter
144
- *
145
- * @param array Array to search in
146
- * @param filter Filter callback to match items
147
- * @returns Filtered array of items
148
- *
149
- * @example
150
- * ```typescript
151
- * filter(
152
- * [{id: 1}, {id: 2}, {id: 3}],
153
- * item => item.id === 2,
154
- * ); // => [{id: 2}]
155
- * ```
156
- */
157
- export function filter<Item>(
158
- array: Item[],
159
- filter: (item: Item, index: number, array: Item[]) => boolean,
160
- ): Item[];
161
-
162
- /**
163
- * Get a filtered array of items matching the given item
164
- *
165
- * @param array Array to search in
166
- * @param item Item to match against
167
- * @returns Filtered array of items
168
- *
169
- * @example
170
- * ```typescript
171
- * filter([1, 2, 3], 2); // => [2]
172
- * ```
173
- */
174
- export function filter<Item>(array: Item[], item: Item): Item[];
175
-
176
- export function filter(array: unknown[], ...parameters: unknown[]): unknown[] {
177
- return findValues(FIND_VALUES_ALL, array, parameters).matched;
178
- }
179
-
180
- filter.remove = exclude;
181
-
182
- // #endregion