@oscarpalmer/atoms 0.193.1 → 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 (79) 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 -4
@@ -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.1",
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",
@@ -256,8 +265,8 @@
256
265
  "watch": "npx vite build --watch"
257
266
  },
258
267
  "devDependencies": {
259
- "@oxlint/plugins": "^1.79",
260
- "@types/node": "^26.2",
268
+ "@oxlint/plugins": "^1.80",
269
+ "@types/node": "^26.4",
261
270
  "@vitest/coverage-istanbul": "^4.1",
262
271
  "eslint": "^10.9",
263
272
  "jsdom": "^30",
@@ -268,4 +277,4 @@
268
277
  "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
269
278
  },
270
279
  "packageManager": "npm@11.11.1"
271
- }
280
+ }