@oscarpalmer/atoms 0.198.0 → 0.200.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 (48) hide show
  1. package/dist/array/flatten.d.mts +1 -1
  2. package/dist/array/from.d.mts +1 -1
  3. package/dist/array/group-by.d.mts +2 -2
  4. package/dist/array/sort.d.mts +4 -0
  5. package/dist/array/to-map.d.mts +2 -2
  6. package/dist/array/to-record.d.mts +2 -2
  7. package/dist/beacon.mjs +46 -43
  8. package/dist/color/instance.mjs +14 -10
  9. package/dist/function/retry.mjs +6 -8
  10. package/dist/index.d.mts +153 -53
  11. package/dist/index.mjs +347 -259
  12. package/dist/internal/array/compact.d.mts +2 -2
  13. package/dist/internal/array/find.d.mts +2 -2
  14. package/dist/internal/array/find.mjs +11 -11
  15. package/dist/internal/function/memoize.mjs +4 -3
  16. package/dist/internal/function/timer.mjs +3 -5
  17. package/dist/internal/herald.mjs +26 -23
  18. package/dist/internal/subscription.d.mts +72 -16
  19. package/dist/internal/subscription.mjs +94 -29
  20. package/dist/internal/value/compare.mjs +2 -2
  21. package/dist/internal/value/equal.mjs +30 -30
  22. package/dist/internal/value/handlers.d.mts +3 -3
  23. package/dist/internal/value/handlers.mjs +6 -6
  24. package/dist/promise/constants.d.mts +3 -1
  25. package/dist/promise/constants.mjs +3 -1
  26. package/dist/promise/delay.mjs +2 -2
  27. package/dist/promise/helpers.d.mts +4 -5
  28. package/dist/promise/helpers.mjs +13 -5
  29. package/dist/promise/index.d.mts +34 -36
  30. package/dist/promise/index.mjs +28 -23
  31. package/dist/promise/misc.mjs +2 -2
  32. package/dist/promise/models.d.mts +7 -6
  33. package/dist/promise/timed.mjs +2 -2
  34. package/dist/queue.d.mts +4 -0
  35. package/dist/queue.mjs +3 -3
  36. package/dist/string/fuzzy.d.mts +2 -0
  37. package/dist/string/fuzzy.mjs +20 -18
  38. package/dist/string/normalize.mjs +12 -12
  39. package/dist/string/template.mjs +8 -8
  40. package/dist/subscription.d.mts +2 -2
  41. package/dist/subscription.mjs +2 -2
  42. package/dist/value/clone.mjs +13 -13
  43. package/dist/value/freeze.d.mts +2 -0
  44. package/dist/value/freeze.mjs +2 -0
  45. package/dist/value/merge.d.mts +1 -1
  46. package/dist/value/merge.mjs +7 -6
  47. package/package.json +4 -4
  48. package/plugin/index.js +1 -1
package/dist/index.mjs CHANGED
@@ -16,10 +16,18 @@ function getArrayCallbacks(bool, key, value) {
16
16
  }
17
17
  //#endregion
18
18
  //#region src/internal/array/find.ts
19
+ function createFindParameters(original) {
20
+ const { length } = original;
21
+ return {
22
+ bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
23
+ key: length === 2 ? original[0] : void 0,
24
+ value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
25
+ };
26
+ }
19
27
  function findValue(type, array, parameters, reversed) {
20
28
  const findIndex = type === FIND_VALUE_INDEX;
21
29
  if (!Array.isArray(array) || array.length === 0) return findIndex ? -1 : void 0;
22
- const { bool, key, value } = getFindParameters(parameters);
30
+ const { bool, key, value } = createFindParameters(parameters);
23
31
  const callbacks = getArrayCallbacks(bool, key);
24
32
  if (callbacks?.bool == null && callbacks?.keyed == null) {
25
33
  if (findIndex) return reversed ? array.lastIndexOf(value) : array.indexOf(value);
@@ -54,7 +62,7 @@ function findValues(type, array, parameters, mapper) {
54
62
  };
55
63
  if (!Array.isArray(array) || array.length === 0) return result;
56
64
  const { length } = array;
57
- const { bool, key, value } = getFindParameters(parameters);
65
+ const { bool, key, value } = createFindParameters(parameters);
58
66
  const callbacks = getArrayCallbacks(bool, key);
59
67
  if (type === "unique" && callbacks?.keyed == null && length >= FIND_UNIQUE_THRESHOLD) {
60
68
  result.matched = [...new Set(array)];
@@ -81,14 +89,6 @@ function findValues(type, array, parameters, mapper) {
81
89
  }
82
90
  return result;
83
91
  }
84
- function getFindParameters(original) {
85
- const { length } = original;
86
- return {
87
- bool: length === 1 && typeof original[0] === "function" ? original[0] : void 0,
88
- key: length === 2 ? original[0] : void 0,
89
- value: length === 1 && typeof original[0] !== "function" ? original[0] : original[1]
90
- };
91
- }
92
92
  const FIND_VALUE_INDEX = "index";
93
93
  const FIND_VALUE_ITEM = "item";
94
94
  const FIND_VALUES_UNIQUE = "unique";
@@ -1043,8 +1043,8 @@ const STRING_EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)
1043
1043
  const STRING_EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
1044
1044
  //#endregion
1045
1045
  //#region src/internal/value/handlers.ts
1046
- function getCompareHandlers(owner, options) {
1047
- const handlers = getHandlers(owner, options);
1046
+ function createCompareHandlers(owner, options) {
1047
+ const handlers = createHandlers(owner, options);
1048
1048
  return {
1049
1049
  deregister(constructor) {
1050
1050
  handlers.deregister(constructor);
@@ -1059,7 +1059,7 @@ function getCompareHandlers(owner, options) {
1059
1059
  }
1060
1060
  };
1061
1061
  }
1062
- function getHandlers(owner, options) {
1062
+ function createHandlers(owner, options) {
1063
1063
  const handlers = /* @__PURE__ */ new WeakMap();
1064
1064
  return {
1065
1065
  deregister(constructor) {
@@ -1077,8 +1077,8 @@ function getHandlers(owner, options) {
1077
1077
  }
1078
1078
  };
1079
1079
  }
1080
- function getSelfHandlers(owner, options) {
1081
- const handlers = getHandlers(owner, options);
1080
+ function createSelfHandlers(owner, options) {
1081
+ const handlers = createHandlers(owner, options);
1082
1082
  return {
1083
1083
  deregister(constructor) {
1084
1084
  handlers.deregister(constructor);
@@ -1174,7 +1174,7 @@ const comparators = {
1174
1174
  number: compareNumbers,
1175
1175
  symbol: compareSymbols
1176
1176
  };
1177
- const compareHandlers = getCompareHandlers(compare, {
1177
+ const compareHandlers = createCompareHandlers(compare, {
1178
1178
  callback: (first, second, compareStrings) => compareStrings ? getString(first).localeCompare(getString(second)) : void 0,
1179
1179
  method: COMPARE_NAME
1180
1180
  });
@@ -1431,6 +1431,14 @@ Object.defineProperty(toRecord, "arrays", { value: toRecordArrays });
1431
1431
  */
1432
1432
  function noop() {}
1433
1433
  //#endregion
1434
+ //#region src/internal/defaults.ts
1435
+ function getBooleanOrDefault(value, defaultValue) {
1436
+ return typeof value === "boolean" ? value : defaultValue;
1437
+ }
1438
+ function getNumberOrDefault(value, defaultValue, minimum) {
1439
+ return typeof value === "number" && !Number.isNaN(value) && value >= (minimum ?? 0) ? value : defaultValue;
1440
+ }
1441
+ //#endregion
1434
1442
  //#region src/internal/function/timer.ts
1435
1443
  function getAsyncTimer(type, callback, time) {
1436
1444
  function cancel() {
@@ -1457,7 +1465,7 @@ function getAsyncTimer(type, callback, time) {
1457
1465
  }
1458
1466
  } else id = startTimer(() => run(item));
1459
1467
  }
1460
- const interval = getInterval(time);
1468
+ const interval = getNumberOrDefault(time, 0);
1461
1469
  const throttle = type === TIMER_THROTTLE;
1462
1470
  let id;
1463
1471
  let last;
@@ -1480,9 +1488,6 @@ function getAsyncTimer(type, callback, time) {
1480
1488
  Object.defineProperty(timer, TIMER_CANCEL, { value: () => cancel() });
1481
1489
  return timer;
1482
1490
  }
1483
- function getInterval(value) {
1484
- return typeof value === "number" && value > 0 ? value : 0;
1485
- }
1486
1491
  function getTimer(type, callback, time) {
1487
1492
  function cancel() {
1488
1493
  clearTimer(id);
@@ -1495,7 +1500,7 @@ function getTimer(type, callback, time) {
1495
1500
  callback(...args);
1496
1501
  } else id = startTimer(run);
1497
1502
  }
1498
- const interval = getInterval(time);
1503
+ const interval = getNumberOrDefault(time, 0);
1499
1504
  const throttle = type === TIMER_THROTTLE;
1500
1505
  let args;
1501
1506
  let id;
@@ -1933,7 +1938,7 @@ async function asyncRetry(callback, options) {
1933
1938
  }
1934
1939
  }
1935
1940
  }
1936
- const { delay, times, when } = getRetryOptions(options);
1941
+ const { delay, times, when } = createRetryOptions(options);
1937
1942
  const timer = getTimer(TIMER_WAIT, handle, delay);
1938
1943
  let attempts = 0;
1939
1944
  let rejector;
@@ -1944,14 +1949,11 @@ async function asyncRetry(callback, options) {
1944
1949
  handle();
1945
1950
  });
1946
1951
  }
1947
- function getRetryNumber(value) {
1948
- return typeof value === "number" && value > 0 ? value : 0;
1949
- }
1950
- function getRetryOptions(input) {
1952
+ function createRetryOptions(input) {
1951
1953
  const options = isPlainObject(input) ? input : {};
1952
1954
  return {
1953
- delay: getRetryNumber(options.delay),
1954
- times: getRetryNumber(options.times),
1955
+ delay: getNumberOrDefault(options.delay, 0),
1956
+ times: getNumberOrDefault(options.times, 0),
1955
1957
  when: typeof options.when === "function" ? options.when : shouldRetry
1956
1958
  };
1957
1959
  }
@@ -1964,7 +1966,7 @@ function getRetryOptions(input) {
1964
1966
  */
1965
1967
  function retry(callback, options) {
1966
1968
  if (typeof callback !== "function") throw new TypeError(RETRY_MESSAGE_EXPECTATION);
1967
- const { times, when } = getRetryOptions(options);
1969
+ const { times, when } = createRetryOptions(options);
1968
1970
  let last;
1969
1971
  for (let index = 0; index <= times; index += 1) try {
1970
1972
  return callback();
@@ -2183,11 +2185,11 @@ var SizedMap = class extends Map {
2183
2185
  };
2184
2186
  //#endregion
2185
2187
  //#region src/internal/function/memoize.ts
2186
- function getMemoizationOptions(input) {
2188
+ function createMemoizationOptions(input) {
2187
2189
  const { cacheKey, cacheSize } = isPlainObject(input) ? input : {};
2188
2190
  return {
2189
2191
  cacheKey: typeof cacheKey === "function" ? cacheKey : void 0,
2190
- cacheSize: typeof cacheSize === "number" && cacheSize > 0 ? cacheSize : MEMOIZED_CACHE_SIZE_DEFAULT
2192
+ cacheSize: getNumberOrDefault(cacheSize, MEMOIZED_CACHE_SIZE_DEFAULT)
2191
2193
  };
2192
2194
  }
2193
2195
  /**
@@ -2202,7 +2204,7 @@ function memoize(callback, options) {
2202
2204
  const state = {
2203
2205
  cache: void 0,
2204
2206
  getter: void 0,
2205
- options: getMemoizationOptions(options)
2207
+ options: createMemoizationOptions(options)
2206
2208
  };
2207
2209
  state.cache = new SizedMap(state.options.cacheSize);
2208
2210
  state.getter = (...parameters) => {
@@ -2371,6 +2373,32 @@ let memoizedTitleCase;
2371
2373
  let memoizedUpperCase;
2372
2374
  //#endregion
2373
2375
  //#region src/internal/value/equal.ts
2376
+ function createEqualOptions(input) {
2377
+ const options = {
2378
+ ignoreCase: false,
2379
+ ignoreExpressions: {
2380
+ enabled: false,
2381
+ values: []
2382
+ },
2383
+ ignoreKeys: {
2384
+ enabled: false,
2385
+ values: /* @__PURE__ */ new Set()
2386
+ },
2387
+ relaxedNullish: false
2388
+ };
2389
+ if (typeof input === "boolean") {
2390
+ options.ignoreCase = input;
2391
+ return options;
2392
+ }
2393
+ if (isNonPlainObject(input)) return options;
2394
+ options.ignoreCase = typeof input.ignoreCase === "boolean" ? input.ignoreCase : false;
2395
+ options.ignoreExpressions.values = (Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter((key) => key instanceof RegExp);
2396
+ options.ignoreKeys.values = new Set((Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter((key) => typeof key === "string"));
2397
+ options.ignoreExpressions.enabled = options.ignoreExpressions.values.length > 0;
2398
+ options.ignoreKeys.enabled = options.ignoreKeys.values.size > 0;
2399
+ options.relaxedNullish = input.relaxedNullish === true;
2400
+ return options;
2401
+ }
2374
2402
  /**
2375
2403
  * Deregister a equality comparison handler for a specific class
2376
2404
  *
@@ -2388,9 +2416,9 @@ function filterKey(key, options) {
2388
2416
  return true;
2389
2417
  }
2390
2418
  function equal(first, second, options) {
2391
- return equalValue(first, second, getEqualOptions(options));
2419
+ return equalValue(first, second, createEqualOptions(options));
2392
2420
  }
2393
- equal.handlers = getCompareHandlers(equal, { callback: Object.is });
2421
+ equal.handlers = createCompareHandlers(equal, { callback: Object.is });
2394
2422
  equal.deregister = deregisterEqualizer;
2395
2423
  equal.initialize = initializeEqualizer;
2396
2424
  equal.register = registerEqualizer;
@@ -2485,32 +2513,6 @@ function equalValue(first, second, options) {
2485
2513
  default: return equal.handlers.handle(first, second, options);
2486
2514
  }
2487
2515
  }
2488
- function getEqualOptions(input) {
2489
- const options = {
2490
- ignoreCase: false,
2491
- ignoreExpressions: {
2492
- enabled: false,
2493
- values: []
2494
- },
2495
- ignoreKeys: {
2496
- enabled: false,
2497
- values: /* @__PURE__ */ new Set()
2498
- },
2499
- relaxedNullish: false
2500
- };
2501
- if (typeof input === "boolean") {
2502
- options.ignoreCase = input;
2503
- return options;
2504
- }
2505
- if (isNonPlainObject(input)) return options;
2506
- options.ignoreCase = typeof input.ignoreCase === "boolean" ? input.ignoreCase : false;
2507
- options.ignoreExpressions.values = (Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter((key) => key instanceof RegExp);
2508
- options.ignoreKeys.values = new Set((Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter((key) => typeof key === "string"));
2509
- options.ignoreExpressions.enabled = options.ignoreExpressions.values.length > 0;
2510
- options.ignoreKeys.enabled = options.ignoreKeys.values.size > 0;
2511
- options.relaxedNullish = input.relaxedNullish === true;
2512
- return options;
2513
- }
2514
2516
  /**
2515
2517
  * Create an equalizer with predefined options
2516
2518
  *
@@ -2520,7 +2522,7 @@ function getEqualOptions(input) {
2520
2522
  * @returns Equalizer function
2521
2523
  */
2522
2524
  function initializeEqualizer(options) {
2523
- const actual = getEqualOptions(options);
2525
+ const actual = createEqualOptions(options);
2524
2526
  const equalizer = (first, second) => equalValue(first, second, actual);
2525
2527
  equalizer.deregister = deregisterEqualizer;
2526
2528
  equalizer.register = registerEqualizer;
@@ -2592,17 +2594,11 @@ function createAborter(value, onAbort) {
2592
2594
  const ABORT_EVENT = "abort";
2593
2595
  const ABORT_OPTIONS = { once: true };
2594
2596
  //#endregion
2595
- //#region src/internal/defaults.ts
2596
- function getBooleanOrDefault(value, defaultValue) {
2597
- return typeof value === "boolean" ? value : defaultValue;
2598
- }
2599
- function getNumberOrDefault(value, defaultValue, minimum) {
2600
- return typeof value === "number" && !Number.isNaN(value) && value >= (minimum ?? 0) ? value : defaultValue;
2601
- }
2602
- //#endregion
2603
2597
  //#region src/promise/constants.ts
2604
2598
  const PROMISE_ERROR_NAME = "PromiseTimeoutError";
2605
2599
  const PROMISE_MESSAGE_EXPECTATION_ATTEMPT = "Attempt expected a function or a promise";
2600
+ const PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY = "promises expected at least one promise-function or promise in the array or object";
2601
+ const PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE = "promises expected an array or object holding promise-functions or promises";
2606
2602
  const PROMISE_MESSAGE_EXPECTATION_RESULT = "toResult expected a Promise";
2607
2603
  const PROMISE_MESSAGE_EXPECTATION_TIMED = "Timed function expected a Promise";
2608
2604
  const PROMISE_MESSAGE_TIMEOUT = "Promise timed out";
@@ -2646,7 +2642,7 @@ var PromiseTimeoutError = class extends Error {
2646
2642
  };
2647
2643
  //#endregion
2648
2644
  //#region src/promise/helpers.ts
2649
- function getPromiseOptions(input) {
2645
+ function createPromiseOptions(input) {
2650
2646
  if (typeof input === "number") return { time: getNumberOrDefault(input, 0) };
2651
2647
  if (input instanceof AbortSignal) return {
2652
2648
  signal: input,
@@ -2658,7 +2654,7 @@ function getPromiseOptions(input) {
2658
2654
  time: getNumberOrDefault(options.time, 0)
2659
2655
  };
2660
2656
  }
2661
- function getPromisesOptions(input) {
2657
+ function createPromisesOptions(input) {
2662
2658
  if (typeof input === "string") return { strategy: getStrategyOrDefault(input) };
2663
2659
  if (input instanceof AbortSignal) return {
2664
2660
  signal: input,
@@ -2671,7 +2667,15 @@ function getPromisesOptions(input) {
2671
2667
  };
2672
2668
  }
2673
2669
  function getResultsFromPromises(promised) {
2674
- return promised.map((result) => isFulfilled(result) ? ok(result.value) : error(result.reason));
2670
+ const isArray = Array.isArray(promised);
2671
+ const entries = isArray ? promised.map((value, index) => [index, value]) : Object.entries(promised);
2672
+ const { length } = entries;
2673
+ const results = isArray ? [] : {};
2674
+ for (let index = 0; index < length; index += 1) {
2675
+ const [key, value] = entries[index];
2676
+ results[key] = isFulfilled(value) ? ok(value.value) : error(value.reason);
2677
+ }
2678
+ return results;
2675
2679
  }
2676
2680
  function getStrategyOrDefault(value) {
2677
2681
  return PROMISE_STRATEGY_ALL.has(value) ? value : PROMISE_STRATEGY_DEFAULT;
@@ -2725,13 +2729,13 @@ function cancelable(executor) {
2725
2729
  return new CancelablePromise(executor);
2726
2730
  }
2727
2731
  function handleResult(status, parameters) {
2728
- const { aborter, complete, data, handlers, index, value } = parameters;
2732
+ const { aborter, complete, data, handlers, index, key, value } = parameters;
2729
2733
  if (aborter?.signal.aborted ?? false) return;
2730
2734
  if (!complete && status === "rejected") {
2731
2735
  settlePromise(handlers.reject, value, aborter);
2732
2736
  return;
2733
2737
  }
2734
- data.result[index] = !complete ? value : status === "fulfilled" ? {
2738
+ data.result[key] = !complete ? value : status === "fulfilled" ? {
2735
2739
  status,
2736
2740
  value
2737
2741
  } : {
@@ -2752,7 +2756,7 @@ async function toResult(value) {
2752
2756
  //#endregion
2753
2757
  //#region src/promise/delay.ts
2754
2758
  function delay(options) {
2755
- const { signal, time } = getPromiseOptions(options);
2759
+ const { signal, time } = createPromiseOptions(options);
2756
2760
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
2757
2761
  const aborter = createAborter(signal, () => {
2758
2762
  timer.cancel();
@@ -2789,7 +2793,7 @@ async function getTimedPromise(promise, time, signal) {
2789
2793
  }
2790
2794
  async function timed(promise, options) {
2791
2795
  if (!(promise instanceof Promise)) return Promise.reject(/* @__PURE__ */ new TypeError(PROMISE_MESSAGE_EXPECTATION_TIMED));
2792
- const { signal, time } = getPromiseOptions(options);
2796
+ const { signal, time } = createPromiseOptions(options);
2793
2797
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
2794
2798
  return time > 0 ? getTimedPromise(promise, time, signal) : promise;
2795
2799
  }
@@ -2798,7 +2802,7 @@ async function timed(promise, options) {
2798
2802
  async function attemptPromise(value, options) {
2799
2803
  const isFunction = typeof value === "function";
2800
2804
  if (!isFunction && !(value instanceof Promise)) return Promise.reject(/* @__PURE__ */ new TypeError(PROMISE_MESSAGE_EXPECTATION_ATTEMPT));
2801
- const { signal, time } = getPromiseOptions(options);
2805
+ const { signal, time } = createPromiseOptions(options);
2802
2806
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
2803
2807
  const aborter = createAborter(signal, () => {
2804
2808
  rejector(signal?.reason);
@@ -2820,19 +2824,20 @@ async function attemptPromise(value, options) {
2820
2824
  return time > 0 ? getTimedPromise(promise, time, signal) : promise;
2821
2825
  }
2822
2826
  async function promises(items, options) {
2823
- const { signal, strategy } = getPromisesOptions(options);
2827
+ const { signal, strategy } = createPromisesOptions(options);
2824
2828
  if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
2825
- if (!Array.isArray(items)) return Promise.resolve([]);
2826
- const actual = items.map((item) => typeof item === "function" ? item() : item).filter((item) => item instanceof Promise);
2829
+ if (!isArrayOrPlainObject(items)) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_TYPE);
2830
+ const isArray = Array.isArray(items);
2831
+ const actual = (isArray ? items.map((item, index) => [index, item]) : Object.entries(items)).map(([key, value]) => [key, typeof value === "function" ? value() : value]).filter(([, value]) => value instanceof Promise);
2827
2832
  const { length } = actual;
2828
- if (length === 0) return Promise.resolve([]);
2833
+ if (length === 0) return Promise.reject(PROMISE_MESSAGE_EXPECTATION_ITEMS_EMPTY);
2829
2834
  const complete = strategy === PROMISE_STRATEGY_DEFAULT;
2830
2835
  const aborter = createAborter(signal, () => {
2831
2836
  handlers.reject(signal?.reason);
2832
2837
  });
2833
2838
  const data = {
2834
2839
  last: length - 1,
2835
- result: []
2840
+ result: isArray ? [] : {}
2836
2841
  };
2837
2842
  let handlers;
2838
2843
  return new Promise((resolve, reject) => {
@@ -2840,21 +2845,24 @@ async function promises(items, options) {
2840
2845
  reject,
2841
2846
  resolve
2842
2847
  };
2843
- for (let index = 0; index < length; index += 1) actual[index].then((value) => handleResult(PROMISE_TYPE_FULFILLED, {
2844
- aborter,
2845
- complete,
2846
- data,
2847
- handlers,
2848
- index,
2849
- value
2850
- })).catch((reason) => handleResult(PROMISE_TYPE_REJECTED, {
2851
- aborter,
2852
- complete,
2853
- data,
2854
- handlers,
2855
- index,
2856
- value: reason
2857
- }));
2848
+ for (let index = 0; index < length; index += 1) {
2849
+ const [key, promise] = actual[index];
2850
+ const parameters = {
2851
+ aborter,
2852
+ complete,
2853
+ data,
2854
+ handlers,
2855
+ index,
2856
+ key
2857
+ };
2858
+ promise.then((value) => {
2859
+ parameters.value = value;
2860
+ handleResult(PROMISE_TYPE_FULFILLED, parameters);
2861
+ }).catch((reason) => {
2862
+ parameters.value = reason;
2863
+ handleResult(PROMISE_TYPE_REJECTED, parameters);
2864
+ });
2865
+ }
2858
2866
  });
2859
2867
  }
2860
2868
  async function resultPromises(items, signal) {
@@ -3001,20 +3009,7 @@ const MATCH_STARTS_WITH = "startsWith";
3001
3009
  const matchMemoizers = {};
3002
3010
  //#endregion
3003
3011
  //#region src/string/fuzzy.ts
3004
- function getHandler(input) {
3005
- if (input == null || input === getString) return getString;
3006
- switch (typeof input) {
3007
- case "function": return input;
3008
- case "string": return (item) => item[input];
3009
- default:
3010
- if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
3011
- throw new TypeError(FUZZY_MESSAGE_HANDLER);
3012
- }
3013
- }
3014
- function getFuzzyItems(items) {
3015
- return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
3016
- }
3017
- function getFuzzyOptions(input, state) {
3012
+ function createFuzzyOptions(input, state) {
3018
3013
  const options = isPlainObject(input) ? input : {};
3019
3014
  const limit = typeof input === "number" ? input : options.limit;
3020
3015
  if (typeof limit === "number" && !Number.isNaN(limit) && limit >= 1) options.limit = Math.floor(limit);
@@ -3022,9 +3017,9 @@ function getFuzzyOptions(input, state) {
3022
3017
  options.tolerance = getTolerance(options.tolerance, state);
3023
3018
  return options;
3024
3019
  }
3025
- function getFuzzyState(items, input) {
3020
+ function createFuzzyState(items, input) {
3026
3021
  const handler = getHandler(input);
3027
- const options = getFuzzyOptions(input);
3022
+ const options = createFuzzyOptions(input);
3028
3023
  return {
3029
3024
  handler,
3030
3025
  items: items.slice(),
@@ -3033,14 +3028,27 @@ function getFuzzyState(items, input) {
3033
3028
  tolerance: options.tolerance
3034
3029
  };
3035
3030
  }
3031
+ function getHandler(input) {
3032
+ if (input == null || input === getString) return getString;
3033
+ switch (typeof input) {
3034
+ case "function": return input;
3035
+ case "string": return (item) => item[input];
3036
+ default:
3037
+ if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
3038
+ throw new TypeError(FUZZY_MESSAGE_HANDLER);
3039
+ }
3040
+ }
3041
+ function getFuzzyItems(items) {
3042
+ return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
3043
+ }
3036
3044
  function getTolerance(input, state) {
3037
3045
  if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
3038
3046
  return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
3039
3047
  }
3040
3048
  function fuzzy(items, configuration) {
3041
3049
  if (!Array.isArray(items)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
3042
- const state = getFuzzyState(items, configuration);
3043
- const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : getFuzzyOptions(options, state)) };
3050
+ const state = createFuzzyState(items, configuration);
3051
+ const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : createFuzzyOptions(options, state)) };
3044
3052
  Object.defineProperties(instance, {
3045
3053
  items: {
3046
3054
  enumerable: true,
@@ -3056,6 +3064,8 @@ function fuzzy(items, configuration) {
3056
3064
  }
3057
3065
  /**
3058
3066
  * Does the needle match the haystack in a fuzzy way?
3067
+ *
3068
+ * _Available as `fuzzyMatch` and `fuzzy.match`_
3059
3069
  *
3060
3070
  * @param haystack Haystack to search through
3061
3071
  * @param needle Needle to search for
@@ -3258,6 +3268,16 @@ const STRING_NUMERICAL_PREFIX_PATTERN = /^\d/;
3258
3268
  const STRING_ZERO = "0";
3259
3269
  //#endregion
3260
3270
  //#region src/string/normalize.ts
3271
+ function createNormalizeOptions(input) {
3272
+ const options = isPlainObject(input) ? input : {};
3273
+ return {
3274
+ deburr: options.deburr !== false,
3275
+ lowerCase: options.lowerCase !== false,
3276
+ special: options.special === true,
3277
+ trim: options.trim !== false,
3278
+ whitespace: options.whitespace !== false
3279
+ };
3280
+ }
3261
3281
  /**
3262
3282
  * Deburr a string, removing diacritical marks
3263
3283
  *
@@ -3273,16 +3293,6 @@ function deburr(value) {
3273
3293
  });
3274
3294
  return deburrMemoizer.run(value);
3275
3295
  }
3276
- function getNormalizeOptions(input) {
3277
- const options = isPlainObject(input) ? input : {};
3278
- return {
3279
- deburr: options.deburr !== false,
3280
- lowerCase: options.lowerCase !== false,
3281
- special: options.special === true,
3282
- trim: options.trim !== false,
3283
- whitespace: options.whitespace !== false
3284
- };
3285
- }
3286
3296
  /**
3287
3297
  * Initialize a string normalizer
3288
3298
  *
@@ -3292,7 +3302,7 @@ function getNormalizeOptions(input) {
3292
3302
  * @returns Normalizer function
3293
3303
  */
3294
3304
  function initializeNormalizer(options) {
3295
- const normalization = getNormalizeOptions(options);
3305
+ const normalization = createNormalizeOptions(options);
3296
3306
  return (value) => normalizeString(value, normalization);
3297
3307
  }
3298
3308
  /**
@@ -3305,7 +3315,7 @@ function initializeNormalizer(options) {
3305
3315
  * @returns Normalized string
3306
3316
  */
3307
3317
  function normalize(value, options) {
3308
- return normalizeString(value, getNormalizeOptions(options));
3318
+ return normalizeString(value, createNormalizeOptions(options));
3309
3319
  }
3310
3320
  function normalizeString(value, options) {
3311
3321
  if (typeof value !== "string") return "";
@@ -3362,18 +3372,18 @@ normalize.initialize = initializeNormalizer;
3362
3372
  Object.defineProperty(normalize, "initialize", { value: initializeNormalizer });
3363
3373
  //#endregion
3364
3374
  //#region src/string/template.ts
3365
- function getRenderer(strings, values) {
3366
- return (variables, options) => {
3367
- return template(interpolate(strings, values), variables, options);
3368
- };
3369
- }
3370
- function getTemplateOptions(input) {
3375
+ function createTemplateOptions(input) {
3371
3376
  const options = isPlainObject(input) ? input : {};
3372
3377
  return {
3373
3378
  ignoreCase: options.ignoreCase === true,
3374
3379
  pattern: options.pattern instanceof RegExp ? options.pattern : TEMPLATE_EXPRESSION_VARIABLE
3375
3380
  };
3376
3381
  }
3382
+ function getRenderer(strings, values) {
3383
+ return (variables, options) => {
3384
+ return template(interpolate(strings, values), variables, options);
3385
+ };
3386
+ }
3377
3387
  function handleTemplate(value, pattern, ignoreCase, variables) {
3378
3388
  if (typeof value !== "string") return "";
3379
3389
  if (typeof variables !== "object" || variables === null || Object.keys(variables).length === 0) return value;
@@ -3395,14 +3405,14 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
3395
3405
  * @returns _Templater_ function
3396
3406
  */
3397
3407
  function initializeTemplater(options) {
3398
- const { ignoreCase, pattern } = getTemplateOptions(options);
3408
+ const { ignoreCase, pattern } = createTemplateOptions(options);
3399
3409
  return ((value, ...parameters) => {
3400
3410
  return isTemplateStringsArray(value) ? (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables) : handleTemplate(value, pattern, ignoreCase, parameters[0]);
3401
3411
  });
3402
3412
  }
3403
3413
  function template(value, ...parameters) {
3404
3414
  if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
3405
- const { ignoreCase, pattern } = getTemplateOptions(parameters[1]);
3415
+ const { ignoreCase, pattern } = createTemplateOptions(parameters[1]);
3406
3416
  return handleTemplate(value, pattern, ignoreCase, parameters[0]);
3407
3417
  }
3408
3418
  const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
@@ -3419,13 +3429,13 @@ function cloneAny(value, parameters, depth, options) {
3419
3429
  case value === null || CLONE_PRIMITIVES[typeof value]: return value;
3420
3430
  case value instanceof Date: return new Date(value.getTime());
3421
3431
  case typeof value === "function":
3422
- parameters.options ??= getCloneOptions(options);
3432
+ parameters.options ??= createCloneOptions(options);
3423
3433
  return parameters.options.copyFunctions ? value : void 0;
3424
3434
  case typeof value === "symbol":
3425
- parameters.options ??= getCloneOptions(options);
3435
+ parameters.options ??= createCloneOptions(options);
3426
3436
  return parameters.options.copySymbols ? value : Symbol(value.description);
3427
3437
  }
3428
- parameters.options ??= getCloneOptions(options);
3438
+ parameters.options ??= createCloneOptions(options);
3429
3439
  parameters.references ??= /* @__PURE__ */ new WeakMap();
3430
3440
  switch (true) {
3431
3441
  case parameters.references.has(value): return parameters.references.get(value);
@@ -3510,6 +3520,13 @@ function copy(value) {
3510
3520
  references: void 0
3511
3521
  }, 0);
3512
3522
  }
3523
+ function createCloneOptions(input) {
3524
+ if (typeof input !== "object" || input === null) return CLONE_DEFAULT_OPTIONS;
3525
+ return {
3526
+ copyFunctions: input.copyFunctions === true,
3527
+ copySymbols: input.copySymbols === true
3528
+ };
3529
+ }
3513
3530
  /**
3514
3531
  * Deregister a clone handler for a specific class
3515
3532
  *
@@ -3520,13 +3537,6 @@ function copy(value) {
3520
3537
  function deregisterCloner(constructor) {
3521
3538
  clone.handlers.deregister(constructor);
3522
3539
  }
3523
- function getCloneOptions(input) {
3524
- if (typeof input !== "object" || input === null) return CLONE_DEFAULT_OPTIONS;
3525
- return {
3526
- copyFunctions: input.copyFunctions === true,
3527
- copySymbols: input.copySymbols === true
3528
- };
3529
- }
3530
3540
  /**
3531
3541
  * Create a cloner with predefined options
3532
3542
  *
@@ -3536,7 +3546,7 @@ function getCloneOptions(input) {
3536
3546
  * @returns Cloner function
3537
3547
  */
3538
3548
  function initializeCloner(options) {
3539
- const opts = getCloneOptions(options);
3549
+ const opts = createCloneOptions(options);
3540
3550
  function cloner(value) {
3541
3551
  return cloneAny(value, {
3542
3552
  copy: false,
@@ -3582,7 +3592,7 @@ const CLONE_DEFAULT_OPTIONS = {
3582
3592
  copySymbols: false
3583
3593
  };
3584
3594
  const CLONE_MAX_DEPTH = 100;
3585
- const cloneHandlers = getSelfHandlers(clone, {
3595
+ const cloneHandlers = createSelfHandlers(clone, {
3586
3596
  callback: tryStructuredClone,
3587
3597
  method: CLONE_NAME
3588
3598
  });
@@ -3798,6 +3808,8 @@ function freezeValue(value, references, flat) {
3798
3808
  }
3799
3809
  /**
3800
3810
  * Is the value frozen?
3811
+ *
3812
+ * _Available as `isFrozen` and `freeze.is`_
3801
3813
  *
3802
3814
  * @param value Value to check
3803
3815
  * @returns `true` if the value is frozen, otherwise `false`
@@ -3954,11 +3966,11 @@ function unsmush(value) {
3954
3966
  * @returns Assigned value
3955
3967
  */
3956
3968
  function assign(to, from, options) {
3957
- const actual = getMergeOptions(options);
3969
+ const actual = createMergeOptions(options);
3958
3970
  actual.assignValues = true;
3959
3971
  return mergeValues([to, ...from], actual);
3960
3972
  }
3961
- function getMergeOptions(options) {
3973
+ function createMergeOptions(options) {
3962
3974
  const actual = {
3963
3975
  assignValues: false,
3964
3976
  replaceableObjects: void 0,
@@ -3974,7 +3986,8 @@ function getMergeOptions(options) {
3974
3986
  }
3975
3987
  function getReplaceableObjects(value) {
3976
3988
  const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
3977
- if (items.length > 0) return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
3989
+ if (items.length === 0) return;
3990
+ return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
3978
3991
  }
3979
3992
  /**
3980
3993
  * Create an assigner with predefined options
@@ -3985,7 +3998,7 @@ function getReplaceableObjects(value) {
3985
3998
  * @returns Assigner function
3986
3999
  */
3987
4000
  function initializeAssigner(options) {
3988
- const actual = getMergeOptions(options);
4001
+ const actual = createMergeOptions(options);
3989
4002
  actual.assignValues = true;
3990
4003
  return ((to, from) => mergeValues([to, ...from], actual));
3991
4004
  }
@@ -3998,7 +4011,7 @@ function initializeAssigner(options) {
3998
4011
  * @returns Merger function
3999
4012
  */
4000
4013
  function initializeMerger(options) {
4001
- const actual = getMergeOptions(options);
4014
+ const actual = createMergeOptions(options);
4002
4015
  return ((values) => mergeValues(values, actual));
4003
4016
  }
4004
4017
  /**
@@ -4009,7 +4022,7 @@ function initializeMerger(options) {
4009
4022
  * @returns Merged value
4010
4023
  */
4011
4024
  function merge(values, options) {
4012
- return mergeValues(values, getMergeOptions(options));
4025
+ return mergeValues(values, createMergeOptions(options));
4013
4026
  }
4014
4027
  function mergeObjects(values, options, destination, prefix) {
4015
4028
  const { length } = values;
@@ -4084,8 +4097,8 @@ Object.defineProperty(transform, "initialize", { value: initializeTransformer })
4084
4097
  //#endregion
4085
4098
  //#region src/internal/subscription.ts
4086
4099
  function addSubscription(subscriptions, subscription, state) {
4100
+ const { items, values } = subscriptions;
4087
4101
  const { key, value } = state.parameters;
4088
- const { items, values } = subscriptions.state;
4089
4102
  if (!isKey(key)) {
4090
4103
  items.any.add(subscription);
4091
4104
  values.from.any.set(value, subscription);
@@ -4119,7 +4132,8 @@ function clearSubscriptions(store) {
4119
4132
  for (const susbcription of store.values.to.any.keys()) susbcription.unsubscribe();
4120
4133
  if (store.values.to.keyed != null) for (const values of store.values.to.keyed.values()) for (const susbcription of values.keys()) susbcription.unsubscribe();
4121
4134
  }
4122
- function createSubscription(subscriptions, property, parameters) {
4135
+ function createSubscription(subscriptions, property, params) {
4136
+ const parameters = createSubscriptionParameters(params);
4123
4137
  if (parameters.signal?.aborted ?? false) throw new Error(parameters.signal?.reason);
4124
4138
  const state = {
4125
4139
  parameters,
@@ -4127,12 +4141,15 @@ function createSubscription(subscriptions, property, parameters) {
4127
4141
  };
4128
4142
  const existing = getExistingSubscription(subscriptions, state);
4129
4143
  if (existing != null) return [existing, true];
4130
- if (subscriptions.state.keys != null && isKey(parameters.key) && !subscriptions.state.keys.has(parameters.key)) throw new Error(SUBSCRIPTION_INVALID_KEY);
4144
+ if (subscriptions.keys != null && isKey(parameters.key)) {
4145
+ if (subscriptions.keys === false) throw new Error(SUBSCRIPTION_DISALLOWED_KEY);
4146
+ else if (subscriptions.keys !== true && !subscriptions.keys.has(parameters.key)) throw new Error(SUBSCRIPTION_INVALID_KEY);
4147
+ }
4131
4148
  state.aborter = createAborter(parameters.signal, () => unsubscribe(subscriptions, instance, state));
4132
4149
  const instance = { unsubscribe: () => unsubscribe(subscriptions, instance, state) };
4133
4150
  Object.defineProperties(instance, {
4134
- [SUBSCRIPTION_PROPERTY]: { value: true },
4135
- [property.key]: { value: property.value ?? "subscription" },
4151
+ [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
4152
+ [property.key]: { value: property.value },
4136
4153
  active: {
4137
4154
  enumerable: true,
4138
4155
  get: () => (parameters.isActive?.() ?? true) && state.active
@@ -4141,36 +4158,56 @@ function createSubscription(subscriptions, property, parameters) {
4141
4158
  addSubscription(subscriptions, instance, state);
4142
4159
  return [Object.freeze(instance), false];
4143
4160
  }
4144
- function createSubscriptions(parameters) {
4145
- const { keys, property } = parameters;
4146
- const state = {
4161
+ function getExistingSubscription(subscriptions, state) {
4162
+ const { values } = subscriptions;
4163
+ const { parameters } = state;
4164
+ return isKey(parameters.key) ? values.from.keyed?.get(parameters.key)?.get(parameters.value) : values.from.any.get(parameters.value);
4165
+ }
4166
+ function createSubscriptionParameters(input) {
4167
+ const values = isPlainObject(input) ? input : {};
4168
+ if (values.value == null) throw new Error(SUBSCRIPTION_INVALID_VALUE);
4169
+ return {
4170
+ isActive: typeof values.isActive === "function" ? values.isActive : void 0,
4171
+ key: isKey(values.key) ? values.key : void 0,
4172
+ signal: values.signal instanceof AbortSignal ? values.signal : void 0,
4173
+ value: values.value
4174
+ };
4175
+ }
4176
+ function createSubscriptionsParameters(input) {
4177
+ const values = isPlainObject(input) ? input : {};
4178
+ let keys;
4179
+ if (values.keys instanceof Set) keys = values.keys;
4180
+ else keys = typeof values.keys === "boolean" ? values.keys : false;
4181
+ return {
4182
+ keys,
4183
+ property: createSubscriptionsProperty(values.property)
4184
+ };
4185
+ }
4186
+ function createSubscriptionsProperty(input) {
4187
+ const values = isPlainObject(input) ? input : {};
4188
+ return {
4189
+ key: typeof values.key === "string" ? values.key : SUBSCRIPTION_PROPERTY,
4190
+ value: values.value == null ? SUBSCRIPTION_NAME : values.value
4191
+ };
4192
+ }
4193
+ function createSubscriptionsState(keys) {
4194
+ return {
4147
4195
  keys,
4148
4196
  items: {
4149
4197
  any: /* @__PURE__ */ new Set(),
4150
- keyed: keys == null ? void 0 : /* @__PURE__ */ new Map()
4198
+ keyed: keys === false ? void 0 : /* @__PURE__ */ new Map()
4151
4199
  },
4152
4200
  values: {
4153
4201
  from: {
4154
4202
  any: /* @__PURE__ */ new Map(),
4155
- keyed: keys == null ? void 0 : /* @__PURE__ */ new Map()
4203
+ keyed: keys === false ? void 0 : /* @__PURE__ */ new Map()
4156
4204
  },
4157
4205
  to: {
4158
4206
  any: /* @__PURE__ */ new Map(),
4159
- keyed: keys == null ? void 0 : /* @__PURE__ */ new Map()
4207
+ keyed: keys === false ? void 0 : /* @__PURE__ */ new Map()
4160
4208
  }
4161
4209
  }
4162
4210
  };
4163
- const instance = {
4164
- state,
4165
- clear: () => clearSubscriptions(state),
4166
- create: (parameters) => createSubscription(instance, property, parameters)
4167
- };
4168
- return instance;
4169
- }
4170
- function getExistingSubscription(subscriptions, state) {
4171
- const { parameters } = state;
4172
- const { values } = subscriptions.state;
4173
- return isKey(parameters.key) ? values.from.keyed?.get(parameters.key)?.get(parameters.value) : values.from.any.get(parameters.value);
4174
4211
  }
4175
4212
  /**
4176
4213
  * Is the value a subscription?
@@ -4179,7 +4216,19 @@ function getExistingSubscription(subscriptions, state) {
4179
4216
  * @returns `true` if the value is a subscription, otherwise `false`
4180
4217
  */
4181
4218
  function isSubscription(value) {
4182
- return isPlainObject(value) && SUBSCRIPTION_PROPERTY in value && value[SUBSCRIPTION_PROPERTY] === true;
4219
+ return isSubscriptionInstance(value, SUBSCRIPTION_NAME);
4220
+ }
4221
+ function isSubscriptionInstance(value, name) {
4222
+ return isPlainObject(value) && SUBSCRIPTION_PROPERTY in value && value[SUBSCRIPTION_PROPERTY] === name;
4223
+ }
4224
+ /**
4225
+ * Is the value a subscriptions store?
4226
+ *
4227
+ * @param value Value to check
4228
+ * @returns `true` if the value is a subscriptions store, otherwise `false`
4229
+ */
4230
+ function isSubscriptions(value) {
4231
+ return isSubscriptionInstance(value, SUBSCRIPTION_STORE);
4183
4232
  }
4184
4233
  function removeFromStore(items, values, subscription, value, key) {
4185
4234
  items.delete(subscription);
@@ -4191,14 +4240,14 @@ function removeFromStore(items, values, subscription, value, key) {
4191
4240
  values.to.keyed?.get(key)?.delete(subscription);
4192
4241
  }
4193
4242
  }
4194
- function removeSubscription(subscriptions, subscription, state) {
4243
+ function removeSubscription(subscriptionsState, subscription, state) {
4195
4244
  if (!state.active) return;
4196
4245
  state.aborter = void 0;
4197
4246
  state.active = false;
4198
4247
  state.parameters.isActive = void 0;
4199
4248
  state.parameters.signal = void 0;
4249
+ const { items, values } = subscriptionsState;
4200
4250
  const { key, value } = state.parameters;
4201
- const { items, values } = subscriptions.state;
4202
4251
  if (!isKey(key)) {
4203
4252
  removeFromStore(items.any, values, subscription, value);
4204
4253
  return;
@@ -4211,12 +4260,42 @@ function removeSubscription(subscriptions, subscription, state) {
4211
4260
  removeFromStore(keyed, values, subscription, value, key);
4212
4261
  if (keyed.size === 0) items.keyed.delete(key);
4213
4262
  }
4214
- function unsubscribe(subscriptions, subscription, state) {
4263
+ /**
4264
+ * Create a subscription store
4265
+ *
4266
+ * @param parameters Store parameters
4267
+ * @returns Subscription store
4268
+ */
4269
+ function subscriptions(parameters) {
4270
+ const { keys, property } = createSubscriptionsParameters(parameters);
4271
+ const state = createSubscriptionsState(keys);
4272
+ const instance = {
4273
+ clear: () => clearSubscriptions(state),
4274
+ create: (parameters) => createSubscription(state, property, parameters)
4275
+ };
4276
+ Object.defineProperties(instance, {
4277
+ [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
4278
+ items: {
4279
+ enumerable: true,
4280
+ value: state.items
4281
+ },
4282
+ values: {
4283
+ enumerable: true,
4284
+ value: state.values
4285
+ }
4286
+ });
4287
+ return Object.freeze(instance);
4288
+ }
4289
+ function unsubscribe(subscriptionsState, subscription, state) {
4215
4290
  state.aborter?.cancel();
4216
- removeSubscription(subscriptions, subscription, state);
4291
+ removeSubscription(subscriptionsState, subscription, state);
4217
4292
  }
4293
+ const SUBSCRIPTION_DISALLOWED_KEY = "Disallowed key for subscription";
4218
4294
  const SUBSCRIPTION_INVALID_KEY = "Invalid key for subscription";
4219
- const SUBSCRIPTION_PROPERTY = "$subscription";
4295
+ const SUBSCRIPTION_INVALID_VALUE = "A subscription requires a non-null value to identify it";
4296
+ const SUBSCRIPTION_NAME = "subscription";
4297
+ const SUBSCRIPTION_PROPERTY = "$subscriptions";
4298
+ const SUBSCRIPTION_STORE = "subscriptions";
4220
4299
  //#endregion
4221
4300
  //#region src/beacon.ts
4222
4301
  /**
@@ -4231,8 +4310,8 @@ function beacon(value, options) {
4231
4310
  value,
4232
4311
  active: true,
4233
4312
  observable: void 0,
4234
- options: getBeaconOptions(options),
4235
- subscriptions: createSubscriptions({ property: beaconSubscription })
4313
+ options: createBeaconOptions(options),
4314
+ subscriptions: subscriptions({ property: beaconSubscription })
4236
4315
  };
4237
4316
  const instance = {
4238
4317
  deactivate: () => finishBeacon(state, false),
@@ -4257,28 +4336,32 @@ function beacon(value, options) {
4257
4336
  });
4258
4337
  return Object.freeze(instance);
4259
4338
  }
4260
- function finishBeacon(state, emit) {
4261
- if (!state.active) return;
4262
- state.active = false;
4263
- for (const [, observer] of state.subscriptions.state.values.to.any) if (emit) observer.complete?.();
4264
- state.subscriptions.clear();
4265
- state.observable?.deactivate();
4266
- state.observable = void 0;
4267
- }
4268
- function getBeaconOptions(input) {
4339
+ function createBeaconOptions(input) {
4269
4340
  const options = isPlainObject(input) ? input : {};
4270
4341
  options.equal = typeof options.equal === "function" ? options.equal : Object.is;
4271
4342
  return options;
4272
4343
  }
4273
- function getObservable(state) {
4274
- if (!state.active) throw new Error(BEACON_MESSAGE_RETRIEVE);
4275
- state.observable ??= observeBeacon(state);
4276
- return state.observable;
4277
- }
4278
- function getObservableCallback(value) {
4279
- return typeof value === "function" ? value : noop;
4344
+ function createObservable(beacon) {
4345
+ const state = {
4346
+ beacon,
4347
+ active: beacon.active
4348
+ };
4349
+ const instance = {
4350
+ deactivate: () => {
4351
+ state.active = false;
4352
+ },
4353
+ subscribe: (first, second, third) => subscribeToObservable(state, first, second, third)
4354
+ };
4355
+ Object.defineProperties(instance, {
4356
+ [BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
4357
+ active: {
4358
+ enumerable: true,
4359
+ get: () => beacon.active && state.active
4360
+ }
4361
+ });
4362
+ return Object.freeze(instance);
4280
4363
  }
4281
- function getObserver(first, second, third) {
4364
+ function createObserver(first, second, third) {
4282
4365
  let observer = { next: noop };
4283
4366
  if (typeof first === "function") observer = {
4284
4367
  error: getObservableCallback(second),
@@ -4292,6 +4375,22 @@ function getObserver(first, second, third) {
4292
4375
  }
4293
4376
  return observer;
4294
4377
  }
4378
+ function finishBeacon(state, emit) {
4379
+ if (!state.active) return;
4380
+ state.active = false;
4381
+ for (const [, observer] of state.subscriptions.values.to.any) if (emit) observer.complete?.();
4382
+ state.subscriptions.clear();
4383
+ state.observable?.deactivate();
4384
+ state.observable = void 0;
4385
+ }
4386
+ function getObservable(state) {
4387
+ if (!state.active) throw new Error(BEACON_MESSAGE_RETRIEVE);
4388
+ state.observable ??= createObservable(state);
4389
+ return state.observable;
4390
+ }
4391
+ function getObservableCallback(value) {
4392
+ return typeof value === "function" ? value : noop;
4393
+ }
4295
4394
  /**
4296
4395
  * Is the value a beacon?
4297
4396
  *
@@ -4322,29 +4421,9 @@ function isBeaconSubscription(value) {
4322
4421
  function isObservable(value) {
4323
4422
  return isBeaconInstance(BEACON_OBSERVABLE, value);
4324
4423
  }
4325
- function observeBeacon(beacon) {
4326
- const state = {
4327
- beacon,
4328
- active: beacon.active
4329
- };
4330
- const instance = {
4331
- deactivate: () => {
4332
- state.active = false;
4333
- },
4334
- subscribe: (first, second, third) => subscribeToObservable(state, first, second, third)
4335
- };
4336
- Object.defineProperties(instance, {
4337
- [BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
4338
- active: {
4339
- enumerable: true,
4340
- get: () => beacon.active && state.active
4341
- }
4342
- });
4343
- return Object.freeze(instance);
4344
- }
4345
4424
  function subscribeToObservable(state, first, second, third) {
4346
4425
  if (!state.beacon.active || !state.active) throw new Error(BEACON_MESSAGE_SUBSCRIBE);
4347
- const observer = getObserver(first, second, third);
4426
+ const observer = createObserver(first, second, third);
4348
4427
  const [subscription] = state.beacon.subscriptions.create({
4349
4428
  isActive: () => state.beacon.active && state.active,
4350
4429
  value: observer
@@ -4358,7 +4437,7 @@ function updateBeacon(type, state, value, finish) {
4358
4437
  if (state.options.equal(state.value, value)) return;
4359
4438
  state.value = value;
4360
4439
  }
4361
- for (const [, observer] of state.subscriptions.state.values.to.any) observer[type]?.(value);
4440
+ for (const [, observer] of state.subscriptions.values.to.any) observer[type]?.(value);
4362
4441
  if (finish === true) finishBeacon(state, true);
4363
4442
  }
4364
4443
  const BEACON_MESSAGE_RETRIEVE = "Cannot retrieve observable from a closed beacon";
@@ -4368,7 +4447,10 @@ const BEACON_NAME = "beacon";
4368
4447
  const BEACON_OBSERVABLE = "observable";
4369
4448
  const BEACON_TYPE_ERROR = "error";
4370
4449
  const BEACON_TYPE_NEXT = "next";
4371
- const beaconSubscription = { key: BEACON_PROPERTY };
4450
+ const beaconSubscription = {
4451
+ key: BEACON_PROPERTY,
4452
+ value: SUBSCRIPTION_NAME
4453
+ };
4372
4454
  //#endregion
4373
4455
  //#region src/internal/herald.ts
4374
4456
  function createEvents(herald, state) {
@@ -4377,34 +4459,34 @@ function createEvents(herald, state) {
4377
4459
  for (const key of state.keys) events[key] = (callback, signal) => herald.subscribe(key, callback, signal);
4378
4460
  return Object.freeze(events);
4379
4461
  }
4380
- function emitForHerald(state, event, ...parameters) {
4381
- const items = state.subscriptions.state.values.from.keyed?.get(event);
4382
- if (items == null || items.size === 0) return;
4383
- for (const [callback] of items) callback(...parameters);
4384
- }
4385
- function getHeraldSubscriptionProperty(input) {
4386
- if (input == null) return heraldSubscription;
4387
- const property = isPlainObject(input) ? input : {};
4388
- if (typeof property.key !== "string" || property.value != null && typeof property.value !== "string") throw new Error(HERALD_MESSAGE_PROPERTY);
4389
- return {
4390
- key: property.key,
4391
- value: property.value
4392
- };
4393
- }
4394
- function getHeraldState(input) {
4462
+ function createHeraldState(input) {
4395
4463
  const options = isPlainObject(input) ? input : {};
4396
4464
  if (!Array.isArray(options.names) || options.names.length === 0 || !options.names.every((name) => typeof name === "string")) throw new Error(HERALD_MESSAGE_ARRAY);
4397
4465
  if (options.onCreate != null && typeof options.onCreate !== "function") throw new Error(HERALD_MESSAGE_ONCREATE);
4398
4466
  const keys = new Set(options.names);
4399
4467
  return {
4400
4468
  keys,
4401
- subscriptions: createSubscriptions({
4469
+ store: subscriptions({
4402
4470
  keys,
4403
- property: getHeraldSubscriptionProperty(options.property)
4471
+ property: createHeraldSubscriptionProperty(options.property)
4404
4472
  }),
4405
4473
  onCreate: options.onCreate
4406
4474
  };
4407
4475
  }
4476
+ function createHeraldSubscriptionProperty(input) {
4477
+ if (input == null) return heraldSubscription;
4478
+ const property = isPlainObject(input) ? input : {};
4479
+ if (typeof property.key !== "string" || property.value != null && typeof property.value !== "string") throw new Error(HERALD_MESSAGE_PROPERTY);
4480
+ return {
4481
+ key: property.key,
4482
+ value: property.value
4483
+ };
4484
+ }
4485
+ function emitForHerald(state, event, ...parameters) {
4486
+ const items = state.store.values.from.keyed?.get(event);
4487
+ if (items == null || items.size === 0) return;
4488
+ for (const [callback] of items) callback(...parameters);
4489
+ }
4408
4490
  /**
4409
4491
  * Create a _Herald_ for announcing named events
4410
4492
  *
@@ -4413,11 +4495,11 @@ function getHeraldState(input) {
4413
4495
  * @returns _Herald_ instance
4414
4496
  */
4415
4497
  function herald(options) {
4416
- const state = getHeraldState(options);
4498
+ const state = createHeraldState(options);
4417
4499
  const instance = {
4418
- clear: () => state.subscriptions.clear(),
4500
+ clear: () => state.store.clear(),
4419
4501
  emit: (event, ...parameters) => emitForHerald(state, event, ...parameters),
4420
- observed: (event) => (state.subscriptions.state.items.keyed?.get(event)?.size ?? 0) > 0,
4502
+ observed: (event) => (state.store.items.keyed?.get(event)?.size ?? 0) > 0,
4421
4503
  subscribe: (key, callback, signal) => subscribeToHerald(state, key, callback, signal)
4422
4504
  };
4423
4505
  Object.defineProperties(instance, {
@@ -4460,7 +4542,7 @@ function isHeraldSubscription(value) {
4460
4542
  return isSubscription(value) && value[HERALD_PROPERTY] === "subscription";
4461
4543
  }
4462
4544
  function subscribeToHerald(state, key, callback, signal) {
4463
- const [subscription, existing] = state.subscriptions.create({
4545
+ const [subscription, existing] = state.store.create({
4464
4546
  key,
4465
4547
  signal,
4466
4548
  value: callback
@@ -4474,7 +4556,10 @@ const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for s
4474
4556
  const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
4475
4557
  const HERALD_NAME_EVENTS = "events";
4476
4558
  const HERALD_NAME_HERALD = "herald";
4477
- const heraldSubscription = { key: HERALD_PROPERTY };
4559
+ const heraldSubscription = {
4560
+ key: HERALD_PROPERTY,
4561
+ value: SUBSCRIPTION_NAME
4562
+ };
4478
4563
  //#endregion
4479
4564
  //#region src/color/constants.ts
4480
4565
  const COLOR_ALPHA = {
@@ -5563,22 +5648,22 @@ function color(value) {
5563
5648
  enumerable: true,
5564
5649
  value: changes.events
5565
5650
  },
5566
- hex: getColorProperty(COLOR_TYPE.hex, instance, state, changes, false),
5567
- hexa: getColorProperty(COLOR_TYPE.hex, instance, state, changes, true),
5568
- hsl: getColorProperty(COLOR_TYPE.hsl, instance, state, changes, false),
5569
- hsla: getColorProperty(COLOR_TYPE.hsl, instance, state, changes, true),
5570
- hwb: getColorProperty(COLOR_TYPE.hwb, instance, state, changes, false),
5571
- hwba: getColorProperty(COLOR_TYPE.hwb, instance, state, changes, true),
5651
+ hex: createColorProperty(COLOR_TYPE.hex, instance, state, changes, false),
5652
+ hexa: createColorProperty(COLOR_TYPE.hex, instance, state, changes, true),
5653
+ hsl: createColorProperty(COLOR_TYPE.hsl, instance, state, changes, false),
5654
+ hsla: createColorProperty(COLOR_TYPE.hsl, instance, state, changes, true),
5655
+ hwb: createColorProperty(COLOR_TYPE.hwb, instance, state, changes, false),
5656
+ hwba: createColorProperty(COLOR_TYPE.hwb, instance, state, changes, true),
5572
5657
  origin: {
5573
5658
  enumerable: true,
5574
5659
  get: () => state.origin
5575
5660
  },
5576
- rgb: getColorProperty(COLOR_TYPE.rgb, instance, state, changes, false),
5577
- rgba: getColorProperty(COLOR_TYPE.rgb, instance, state, changes, true)
5661
+ rgb: createColorProperty(COLOR_TYPE.rgb, instance, state, changes, false),
5662
+ rgba: createColorProperty(COLOR_TYPE.rgb, instance, state, changes, true)
5578
5663
  });
5579
5664
  return Object.freeze(instance);
5580
5665
  }
5581
- function getColorProperty(space, color, state, changes, alpha) {
5666
+ function createColorProperty(space, color, state, changes, alpha) {
5582
5667
  const setValue = setters[space];
5583
5668
  return {
5584
5669
  enumerable: true,
@@ -5603,7 +5688,10 @@ function onCreateSubscription(instance, event, callback) {
5603
5688
  function setAlphaValue(state, value) {
5604
5689
  if (typeof value === "number" && !Number.isNaN(value)) state.alpha = getAlpha(value, false);
5605
5690
  }
5606
- const colorSubscription = { key: COLOR_PROPERTY.name };
5691
+ const colorSubscription = {
5692
+ key: COLOR_PROPERTY.name,
5693
+ value: SUBSCRIPTION_NAME
5694
+ };
5607
5695
  const setters = {
5608
5696
  hex: setHexColor,
5609
5697
  hsl: setHSLColor,
@@ -6019,7 +6107,7 @@ function createQueue(callback, options, key) {
6019
6107
  handled: [],
6020
6108
  id: 0,
6021
6109
  items: [],
6022
- options: getOptions(options),
6110
+ options: createQueueOptions(options),
6023
6111
  paused: !getBooleanOrDefault(options?.autostart, true),
6024
6112
  runners: 0
6025
6113
  };
@@ -6069,7 +6157,7 @@ function createQueue(callback, options, key) {
6069
6157
  });
6070
6158
  return Object.freeze(instance);
6071
6159
  }
6072
- function getOptions(input) {
6160
+ function createQueueOptions(input) {
6073
6161
  const options = typeof input === "object" && input != null ? input : {};
6074
6162
  return {
6075
6163
  autostart: getBooleanOrDefault(options.autostart, true),
@@ -6147,7 +6235,7 @@ function keyedQueue(callback, options) {
6147
6235
  if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
6148
6236
  const state = {
6149
6237
  callback,
6150
- options: getOptions(options),
6238
+ options: createQueueOptions(options),
6151
6239
  queues: /* @__PURE__ */ new Map()
6152
6240
  };
6153
6241
  const instance = {
@@ -6400,4 +6488,4 @@ var SizedSet = class extends Set {
6400
6488
  }
6401
6489
  };
6402
6490
  //#endregion
6403
- export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isTimedLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
6491
+ export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTimedLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };