@oscarpalmer/atoms 0.201.0 → 0.203.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 (156) hide show
  1. package/dist/array/difference.d.mts +4 -5
  2. package/dist/array/exists.d.mts +5 -6
  3. package/dist/array/filter.d.mts +10 -11
  4. package/dist/array/find.d.mts +10 -11
  5. package/dist/array/first.d.mts +10 -11
  6. package/dist/array/flatten.d.mts +2 -3
  7. package/dist/array/from.d.mts +7 -8
  8. package/dist/array/group-by.d.mts +16 -185
  9. package/dist/array/insert.d.mts +3 -4
  10. package/dist/array/intersection.d.mts +4 -5
  11. package/dist/array/last.d.mts +10 -11
  12. package/dist/array/move.d.mts +9 -10
  13. package/dist/array/partition.d.mts +5 -6
  14. package/dist/array/push.d.mts +2 -3
  15. package/dist/array/reverse.d.mts +2 -3
  16. package/dist/array/select.d.mts +11 -12
  17. package/dist/array/single.d.mts +4 -5
  18. package/dist/array/slice.d.mts +12 -13
  19. package/dist/array/sort.d.mts +31 -32
  20. package/dist/array/sort.mjs +41 -33
  21. package/dist/array/splice.d.mts +5 -6
  22. package/dist/array/swap.d.mts +8 -9
  23. package/dist/array/to-map.d.mts +18 -175
  24. package/dist/array/to-record.d.mts +18 -175
  25. package/dist/array/to-set.d.mts +4 -5
  26. package/dist/array/toggle.d.mts +4 -5
  27. package/dist/array/union.d.mts +4 -5
  28. package/dist/array/unique.d.mts +4 -5
  29. package/dist/array/update.d.mts +4 -5
  30. package/dist/beacon.d.mts +8 -9
  31. package/dist/beacon.mjs +90 -65
  32. package/dist/color/constants.d.mts +14 -13
  33. package/dist/color/constants.mjs +9 -2
  34. package/dist/color/index.d.mts +2 -2
  35. package/dist/color/instance.d.mts +3 -3
  36. package/dist/color/instance.mjs +125 -61
  37. package/dist/color/misc/alpha.d.mts +4 -5
  38. package/dist/color/misc/format.d.mts +6 -7
  39. package/dist/color/misc/format.mjs +15 -12
  40. package/dist/color/misc/get.d.mts +14 -15
  41. package/dist/color/misc/is.d.mts +16 -17
  42. package/dist/color/misc/is.mjs +3 -4
  43. package/dist/color/misc/state.d.mts +8 -10
  44. package/dist/color/misc/state.mjs +22 -20
  45. package/dist/color/models.d.mts +25 -19
  46. package/dist/color/space/hex.d.mts +9 -10
  47. package/dist/color/space/hsl.d.mts +8 -9
  48. package/dist/color/space/hwb.d.mts +9 -10
  49. package/dist/color/space/rgb.d.mts +11 -12
  50. package/dist/function/limit.d.mts +9 -8
  51. package/dist/function/limit.mjs +5 -5
  52. package/dist/function/once.d.mts +26 -6
  53. package/dist/function/once.mjs +135 -76
  54. package/dist/function/retry.d.mts +5 -6
  55. package/dist/function/retry.mjs +3 -3
  56. package/dist/index.d.mts +244 -584
  57. package/dist/index.mjs +1191 -810
  58. package/dist/internal/abort.d.mts +3 -4
  59. package/dist/internal/array/callbacks.d.mts +4 -5
  60. package/dist/internal/array/chunk.d.mts +2 -3
  61. package/dist/internal/array/compact.d.mts +3 -4
  62. package/dist/internal/array/find.d.mts +10 -11
  63. package/dist/internal/array/get.d.mts +7 -8
  64. package/dist/internal/array/group.d.mts +2 -3
  65. package/dist/internal/array/index-of.d.mts +10 -11
  66. package/dist/internal/array/insert.d.mts +5 -6
  67. package/dist/internal/array/match.d.mts +17 -18
  68. package/dist/internal/array/overlap.d.mts +2 -3
  69. package/dist/internal/array/sets.d.mts +5 -6
  70. package/dist/internal/array/shuffle.d.mts +2 -3
  71. package/dist/internal/array/update.d.mts +2 -3
  72. package/dist/internal/defaults.d.mts +3 -4
  73. package/dist/internal/function/assert.d.mts +10 -11
  74. package/dist/internal/function/limit.d.mts +41 -0
  75. package/dist/internal/function/limit.mjs +110 -0
  76. package/dist/internal/function/memoize.d.mts +4 -5
  77. package/dist/internal/function/memoize.mjs +53 -31
  78. package/dist/internal/function/misc.d.mts +2 -3
  79. package/dist/internal/function/work.d.mts +53 -54
  80. package/dist/internal/herald.d.mts +8 -9
  81. package/dist/internal/herald.mjs +38 -26
  82. package/dist/internal/is.d.mts +19 -20
  83. package/dist/internal/math/aggregate.d.mts +14 -15
  84. package/dist/internal/math/misc.d.mts +3 -4
  85. package/dist/internal/number.d.mts +4 -5
  86. package/dist/internal/random.d.mts +3 -4
  87. package/dist/internal/result/misc.d.mts +29 -14
  88. package/dist/internal/result/misc.mjs +4 -0
  89. package/dist/internal/result/models.d.mts +9 -10
  90. package/dist/internal/sized/map.d.mts +2 -3
  91. package/dist/internal/sized/misc.d.mts +2 -3
  92. package/dist/internal/string/case.d.mts +9 -10
  93. package/dist/internal/string/misc.d.mts +8 -9
  94. package/dist/internal/subscription.d.mts +14 -15
  95. package/dist/internal/subscription.mjs +69 -57
  96. package/dist/internal/value/compare.d.mts +17 -9
  97. package/dist/internal/value/compare.mjs +7 -7
  98. package/dist/internal/value/equal.d.mts +34 -15
  99. package/dist/internal/value/equal.mjs +28 -13
  100. package/dist/internal/value/get.d.mts +3 -4
  101. package/dist/internal/value/handlers.d.mts +19 -9
  102. package/dist/internal/value/handlers.mjs +50 -50
  103. package/dist/internal/value/has.d.mts +6 -7
  104. package/dist/internal/value/misc.d.mts +6 -7
  105. package/dist/internal/value/partial.d.mts +3 -4
  106. package/dist/internal/value/set.d.mts +4 -5
  107. package/dist/is.d.mts +13 -13
  108. package/dist/logger.d.mts +5 -4
  109. package/dist/logger.mjs +61 -54
  110. package/dist/math.d.mts +20 -20
  111. package/dist/models.d.mts +58 -46
  112. package/dist/promise/constants.d.mts +14 -15
  113. package/dist/promise/delay.d.mts +3 -4
  114. package/dist/promise/delay.mjs +4 -4
  115. package/dist/promise/helpers.d.mts +7 -8
  116. package/dist/promise/index.d.mts +13 -14
  117. package/dist/promise/misc.d.mts +6 -6
  118. package/dist/promise/models.d.mts +16 -17
  119. package/dist/promise/timed.d.mts +4 -5
  120. package/dist/promise/timed.mjs +5 -5
  121. package/dist/query.d.mts +3 -4
  122. package/dist/queue.d.mts +14 -15
  123. package/dist/queue.mjs +185 -129
  124. package/dist/random.d.mts +8 -8
  125. package/dist/result/index.d.mts +8 -9
  126. package/dist/result/match.d.mts +6 -7
  127. package/dist/result/misc.d.mts +3 -3
  128. package/dist/result/work/flow.d.mts +28 -29
  129. package/dist/result/work/pipe.d.mts +24 -25
  130. package/dist/sized/set.d.mts +2 -3
  131. package/dist/string/fuzzy.d.mts +21 -12
  132. package/dist/string/fuzzy.mjs +77 -49
  133. package/dist/string/index.d.mts +8 -8
  134. package/dist/string/match.d.mts +4 -5
  135. package/dist/string/normalize.d.mts +8 -9
  136. package/dist/string/normalize.mjs +9 -4
  137. package/dist/string/template.d.mts +9 -9
  138. package/dist/string/template.mjs +11 -4
  139. package/dist/value/clone.d.mts +21 -13
  140. package/dist/value/clone.mjs +22 -20
  141. package/dist/value/collection.d.mts +4 -5
  142. package/dist/value/diff.d.mts +5 -6
  143. package/dist/value/freeze.d.mts +18 -19
  144. package/dist/value/freeze.mjs +1 -1
  145. package/dist/value/merge.d.mts +13 -14
  146. package/dist/value/merge.mjs +21 -5
  147. package/dist/value/omit.d.mts +2 -3
  148. package/dist/value/pick.d.mts +2 -3
  149. package/dist/value/shake.d.mts +3 -4
  150. package/dist/value/smush.d.mts +3 -4
  151. package/dist/value/transform.d.mts +15 -10
  152. package/dist/value/transform.mjs +12 -7
  153. package/dist/value/unsmush.d.mts +3 -4
  154. package/package.json +1 -1
  155. package/dist/internal/function/timer.d.mts +0 -10
  156. package/dist/internal/function/timer.mjs +0 -87
@@ -5,55 +5,54 @@
5
5
  * @param value String to convert
6
6
  * @returns Camel-cased string
7
7
  */
8
- declare function camelCase(value: string): string;
8
+ export declare function camelCase(value: string): string;
9
9
  /**
10
10
  * Capitalize the first letter of a string _(and lowercase the rest)_
11
11
  *
12
12
  * @param value String to capitalize
13
13
  * @returns Capitalized string
14
14
  */
15
- declare function capitalize(value: string): string;
15
+ export declare function capitalize(value: string): string;
16
16
  /**
17
17
  * Convert a string to kebab case _(this-is-kebab-case)_
18
18
  *
19
19
  * @param value String to convert
20
20
  * @returns Kebab-cased string
21
21
  */
22
- declare function kebabCase(value: string): string;
22
+ export declare function kebabCase(value: string): string;
23
23
  /**
24
24
  * Convert a string to lower case
25
25
  *
26
26
  * @param value String to convert
27
27
  * @returns Lower-cased string
28
28
  */
29
- declare function lowerCase(value: string): string;
29
+ export declare function lowerCase(value: string): string;
30
30
  /**
31
31
  * Convert a string to pascal case _(ThisIsPascalCase)_
32
32
  *
33
33
  * @param value String to convert
34
34
  * @returns Pascal-cased string
35
35
  */
36
- declare function pascalCase(value: string): string;
36
+ export declare function pascalCase(value: string): string;
37
37
  /**
38
38
  * Convert a string to snake case _(this_is_snake_case)_
39
39
  *
40
40
  * @param value String to convert
41
41
  * @returns Snake-cased string
42
42
  */
43
- declare function snakeCase(value: string): string;
43
+ export declare function snakeCase(value: string): string;
44
44
  /**
45
45
  * Convert a string to title case _(Capitalizing Every Word)_
46
46
  *
47
47
  * @param value String to convert
48
48
  * @returns Title-cased string
49
49
  */
50
- declare function titleCase(value: string): string;
50
+ export declare function titleCase(value: string): string;
51
51
  /**
52
52
  * Convert a string to upper case
53
53
  *
54
54
  * @param value String to convert
55
55
  * @returns Upper-cased string
56
56
  */
57
- declare function upperCase(value: string): string;
58
- //#endregion
59
- export { camelCase, capitalize, kebabCase, lowerCase, pascalCase, snakeCase, titleCase, upperCase };
57
+ export declare function upperCase(value: string): string;
58
+ //#endregion
@@ -16,9 +16,9 @@
16
16
  * getString(() => 123) // => '123'
17
17
  * ```
18
18
  */
19
- declare function getString(value: unknown): string;
20
- declare function ignoreKey(key: string): boolean;
21
- declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string;
19
+ export declare function getString(value: unknown): string;
20
+ export declare function ignoreKey(key: string): boolean;
21
+ export declare function interpolate(strings: TemplateStringsArray, values: unknown[]): string;
22
22
  /**
23
23
  * Join an array of values into a string _(while ignoring empty values)_
24
24
  *
@@ -28,15 +28,14 @@ declare function interpolate(strings: TemplateStringsArray, values: unknown[]):
28
28
  * @param delimiter Delimiter to use between values
29
29
  * @returns Joined string
30
30
  */
31
- declare function join(array: unknown[], delimiter?: string): string;
32
- declare function tryDecode(value: string): string;
33
- declare function tryEncode(value: boolean | number | string): unknown;
31
+ export declare function join(array: unknown[], delimiter?: string): string;
32
+ export declare function tryDecode(value: string): string;
33
+ export declare function tryEncode(value: boolean | number | string): unknown;
34
34
  /**
35
35
  * Split a string into words _(and other readable parts)_
36
36
  *
37
37
  * @param value Original string
38
38
  * @returns Array of words found in the string
39
39
  */
40
- declare function words(value: string): string[];
41
- //#endregion
42
- export { getString, ignoreKey, interpolate, join, tryDecode, tryEncode, words };
40
+ export declare function words(value: string): string[];
41
+ //#endregion
@@ -1,6 +1,7 @@
1
1
  import { Key } from "../models.mjs";
2
2
  //#region src/internal/subscription.d.ts
3
- type Subscription = {
3
+ export declare const SUBSCRIPTION_NAME = "subscription";
4
+ export type Subscription = {
4
5
  /**
5
6
  * Is the subscription active?
6
7
  */
@@ -13,7 +14,7 @@ type Subscription = {
13
14
  /**
14
15
  * Parameters for creating a subscription
15
16
  */
16
- type SubscriptionParameters = {
17
+ export type SubscriptionParameters = {
17
18
  /**
18
19
  * Is the owner of the subscription alive? _(defaults to `true`)_
19
20
  */
@@ -34,7 +35,7 @@ type SubscriptionParameters = {
34
35
  /**
35
36
  * Property information for subscription identification
36
37
  */
37
- type SubscriptionProperty = {
38
+ export type SubscriptionProperty = {
38
39
  /**
39
40
  * Name of the property used to identify a subscription
40
41
  */
@@ -44,7 +45,7 @@ type SubscriptionProperty = {
44
45
  */
45
46
  value: unknown;
46
47
  };
47
- type Subscriptions = {
48
+ export type Subscriptions<Value = unknown> = {
48
49
  /**
49
50
  * Items of the subscriptions store
50
51
  *
@@ -60,7 +61,7 @@ type Subscriptions = {
60
61
  * - `to.any` - Map of subscriptions to values _(for unkeyed subscriptions)_
61
62
  * - `to.keyed` - Map of keys to maps of subscriptions to values _(for keyed subscriptions)_
62
63
  */
63
- readonly values: Readonly<SubscriptionsValues>;
64
+ readonly values: Readonly<SubscriptionsValues<Value>>;
64
65
  /**
65
66
  * Clear all subscriptions
66
67
  */
@@ -76,7 +77,7 @@ type Subscriptions = {
76
77
  /**
77
78
  * Parameters for creating a subscription store
78
79
  */
79
- type SubscriptionsParameters = {
80
+ export type SubscriptionsParameters = {
80
81
  /**
81
82
  * Allow any or specific keys for subscriptions? _(defaults to `false`, which prevents keyed subscriptions)_
82
83
  */
@@ -90,9 +91,9 @@ type SubscriptionsItems = {
90
91
  any: Set<Subscription>;
91
92
  keyed?: Map<Key, Set<Subscription>>;
92
93
  };
93
- type SubscriptionsValues = {
94
- from: SubscriptionsValuesItem<unknown, Subscription>;
95
- to: SubscriptionsValuesItem<Subscription, unknown>;
94
+ type SubscriptionsValues<Value = unknown> = {
95
+ from: SubscriptionsValuesItem<Value, Subscription>;
96
+ to: SubscriptionsValuesItem<Subscription, Value>;
96
97
  };
97
98
  type SubscriptionsValuesItem<MapKey, MapValue> = {
98
99
  any: Map<MapKey, MapValue>;
@@ -104,21 +105,19 @@ type SubscriptionsValuesItem<MapKey, MapValue> = {
104
105
  * @param value Value to check
105
106
  * @returns `true` if the value is a subscription, otherwise `false`
106
107
  */
107
- declare function isSubscription(value: unknown): value is Subscription;
108
+ export declare function isSubscription(value: unknown): value is Subscription;
108
109
  /**
109
110
  * Is the value a subscriptions store?
110
111
  *
111
112
  * @param value Value to check
112
113
  * @returns `true` if the value is a subscriptions store, otherwise `false`
113
114
  */
114
- declare function isSubscriptions(value: unknown): value is Subscriptions;
115
+ export declare function isSubscriptions(value: unknown): value is Subscriptions;
115
116
  /**
116
117
  * Create a subscription store
117
118
  *
118
119
  * @param parameters Store parameters
119
120
  * @returns Subscription store
120
121
  */
121
- declare function subscriptions(parameters?: SubscriptionsParameters): Subscriptions;
122
- declare const SUBSCRIPTION_NAME = "subscription";
123
- //#endregion
124
- export { SUBSCRIPTION_NAME, Subscription, SubscriptionParameters, SubscriptionProperty, Subscriptions, SubscriptionsParameters, isSubscription, isSubscriptions, subscriptions };
122
+ export declare function subscriptions<Value = unknown>(parameters?: SubscriptionsParameters): Subscriptions<Value>;
123
+ //#endregion
@@ -1,13 +1,54 @@
1
1
  import { isKey, isPlainObject } from "./is.mjs";
2
2
  import { createAborter } from "./abort.mjs";
3
3
  //#region src/internal/subscription.ts
4
- function addSubscription(subscriptions, subscription, state) {
5
- const { items, values } = subscriptions;
4
+ const SUBSCRIPTION_NAME = "subscription";
5
+ const SUBSCRIPTION_PROPERTY = "$subscription";
6
+ const SUBSCRIPTION_STORE = "subscriptions";
7
+ function Subscription(state, property, parameters) {
8
+ Object.defineProperty(this, SUBSCRIPTION_SYMBOL, { value: state });
9
+ state.aborter = createAborter(parameters.signal, () => this.unsubscribe(subscriptions, this, state));
10
+ Object.defineProperties(this, {
11
+ [property.key]: { value: property.value },
12
+ active: {
13
+ enumerable: true,
14
+ get: () => (state.parameters?.isActive?.() ?? true) && state.active
15
+ }
16
+ });
17
+ addSubscription(this);
18
+ }
19
+ Object.defineProperties(Subscription.prototype, {
20
+ [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
21
+ unsubscribe: { value: removeSubscription }
22
+ });
23
+ function Subscriptions(parameters) {
24
+ const { keys, property } = createSubscriptionsParameters(parameters);
25
+ Object.defineProperty(this, SUBSCRIPTION_SYMBOL, { value: createSubscriptionsState(property, keys) });
26
+ }
27
+ Object.defineProperties(Subscriptions.prototype, {
28
+ [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
29
+ clear: { value: clearSubscriptions },
30
+ create: { value: createSubscription },
31
+ items: {
32
+ enumerable: true,
33
+ get() {
34
+ return this[SUBSCRIPTION_SYMBOL].items;
35
+ }
36
+ },
37
+ values: {
38
+ enumerable: true,
39
+ get() {
40
+ return this[SUBSCRIPTION_SYMBOL].values;
41
+ }
42
+ }
43
+ });
44
+ function addSubscription(instance) {
45
+ const state = instance[SUBSCRIPTION_SYMBOL];
6
46
  const { key, value } = state.parameters;
47
+ const { items, values } = state.subscriptions;
7
48
  if (!isKey(key)) {
8
- items.any.add(subscription);
9
- values.from.any.set(value, subscription);
10
- values.to.any.set(subscription, value);
49
+ items.any.add(instance);
50
+ values.from.any.set(value, instance);
51
+ values.to.any.set(instance, value);
11
52
  return;
12
53
  }
13
54
  /* istanbul ignore if */
@@ -19,29 +60,32 @@ function addSubscription(subscriptions, subscription, state) {
19
60
  keyedItems = /* @__PURE__ */ new Set();
20
61
  items.keyed.set(key, keyedItems);
21
62
  }
22
- keyedItems.add(subscription);
63
+ keyedItems.add(instance);
23
64
  let keyedFrom = values.from.keyed.get(key);
24
65
  if (keyedFrom == null) {
25
66
  keyedFrom = /* @__PURE__ */ new Map();
26
67
  values.from.keyed.set(key, keyedFrom);
27
68
  }
28
- keyedFrom.set(value, subscription);
69
+ keyedFrom.set(value, instance);
29
70
  let keyedTo = values.to.keyed.get(key);
30
71
  if (keyedTo == null) {
31
72
  keyedTo = /* @__PURE__ */ new Map();
32
73
  values.to.keyed.set(key, keyedTo);
33
74
  }
34
- keyedTo.set(subscription, value);
75
+ keyedTo.set(instance, value);
35
76
  }
36
- function clearSubscriptions(store) {
37
- for (const susbcription of store.values.to.any.keys()) susbcription.unsubscribe();
38
- if (store.values.to.keyed != null) for (const values of store.values.to.keyed.values()) for (const susbcription of values.keys()) susbcription.unsubscribe();
77
+ function clearSubscriptions() {
78
+ const state = this[SUBSCRIPTION_SYMBOL];
79
+ for (const susbcription of state.values.to.any.keys()) susbcription.unsubscribe();
80
+ if (state.values.to.keyed != null && state.values.to.keyed.size > 0) for (const values of state.values.to.keyed.values()) for (const susbcription of values.keys()) susbcription.unsubscribe();
39
81
  }
40
- function createSubscription(subscriptions, property, params) {
82
+ function createSubscription(params) {
41
83
  const parameters = createSubscriptionParameters(params);
42
84
  if (parameters.signal?.aborted ?? false) throw new Error(parameters.signal?.reason);
85
+ const subscriptions = this[SUBSCRIPTION_SYMBOL];
43
86
  const state = {
44
87
  parameters,
88
+ subscriptions,
45
89
  active: true
46
90
  };
47
91
  const existing = getExistingSubscription(subscriptions, state);
@@ -50,18 +94,7 @@ function createSubscription(subscriptions, property, params) {
50
94
  if (subscriptions.keys === false) throw new Error(SUBSCRIPTION_DISALLOWED_KEY);
51
95
  else if (subscriptions.keys !== true && !subscriptions.keys.has(parameters.key)) throw new Error(SUBSCRIPTION_INVALID_KEY);
52
96
  }
53
- state.aborter = createAborter(parameters.signal, () => unsubscribe(subscriptions, instance, state));
54
- const instance = { unsubscribe: () => unsubscribe(subscriptions, instance, state) };
55
- Object.defineProperties(instance, {
56
- [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
57
- [property.key]: { value: property.value },
58
- active: {
59
- enumerable: true,
60
- get: () => (parameters.isActive?.() ?? true) && state.active
61
- }
62
- });
63
- addSubscription(subscriptions, instance, state);
64
- return [Object.freeze(instance), false];
97
+ return [new Subscription(state, subscriptions.property, parameters), false];
65
98
  }
66
99
  function getExistingSubscription(subscriptions, state) {
67
100
  const { values } = subscriptions;
@@ -95,9 +128,10 @@ function createSubscriptionsProperty(input) {
95
128
  value: values.value == null ? SUBSCRIPTION_NAME : values.value
96
129
  };
97
130
  }
98
- function createSubscriptionsState(keys) {
131
+ function createSubscriptionsState(property, keys) {
99
132
  return {
100
133
  keys,
134
+ property,
101
135
  items: {
102
136
  any: /* @__PURE__ */ new Set(),
103
137
  keyed: keys === false ? void 0 : /* @__PURE__ */ new Map()
@@ -124,7 +158,7 @@ function isSubscription(value) {
124
158
  return isSubscriptionInstance(value, SUBSCRIPTION_NAME);
125
159
  }
126
160
  function isSubscriptionInstance(value, name) {
127
- return isPlainObject(value) && SUBSCRIPTION_PROPERTY in value && value[SUBSCRIPTION_PROPERTY] === name;
161
+ return typeof value === "object" && value !== null && SUBSCRIPTION_PROPERTY in value && value[SUBSCRIPTION_PROPERTY] === name;
128
162
  }
129
163
  /**
130
164
  * Is the value a subscriptions store?
@@ -145,16 +179,17 @@ function removeFromStore(items, values, subscription, value, key) {
145
179
  values.to.keyed?.get(key)?.delete(subscription);
146
180
  }
147
181
  }
148
- function removeSubscription(subscriptionsState, subscription, state) {
182
+ function removeSubscription() {
183
+ const state = this[SUBSCRIPTION_SYMBOL];
149
184
  if (!state.active) return;
150
185
  state.aborter = void 0;
151
186
  state.active = false;
152
- state.parameters.isActive = void 0;
153
- state.parameters.signal = void 0;
154
- const { items, values } = subscriptionsState;
187
+ const { items, values } = state.subscriptions;
155
188
  const { key, value } = state.parameters;
189
+ state.parameters = void 0;
190
+ state.subscriptions = void 0;
156
191
  if (!isKey(key)) {
157
- removeFromStore(items.any, values, subscription, value);
192
+ removeFromStore(items.any, values, this, value);
158
193
  return;
159
194
  }
160
195
  const keyed = items.keyed?.get(key);
@@ -162,7 +197,7 @@ function removeSubscription(subscriptionsState, subscription, state) {
162
197
  if (items.keyed == null || keyed == null)
163
198
  // istanbul ignore next
164
199
  return;
165
- removeFromStore(keyed, values, subscription, value, key);
200
+ removeFromStore(keyed, values, this, value, key);
166
201
  if (keyed.size === 0) items.keyed.delete(key);
167
202
  }
168
203
  /**
@@ -172,34 +207,11 @@ function removeSubscription(subscriptionsState, subscription, state) {
172
207
  * @returns Subscription store
173
208
  */
174
209
  function subscriptions(parameters) {
175
- const { keys, property } = createSubscriptionsParameters(parameters);
176
- const state = createSubscriptionsState(keys);
177
- const instance = {
178
- clear: () => clearSubscriptions(state),
179
- create: (parameters) => createSubscription(state, property, parameters)
180
- };
181
- Object.defineProperties(instance, {
182
- [SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
183
- items: {
184
- enumerable: true,
185
- value: state.items
186
- },
187
- values: {
188
- enumerable: true,
189
- value: state.values
190
- }
191
- });
192
- return Object.freeze(instance);
193
- }
194
- function unsubscribe(subscriptionsState, subscription, state) {
195
- state.aborter?.cancel();
196
- removeSubscription(subscriptionsState, subscription, state);
210
+ return new Subscriptions(parameters);
197
211
  }
198
212
  const SUBSCRIPTION_DISALLOWED_KEY = "Disallowed key for subscription";
199
213
  const SUBSCRIPTION_INVALID_KEY = "Invalid key for subscription";
200
214
  const SUBSCRIPTION_INVALID_VALUE = "A subscription requires a non-null value to identify it";
201
- const SUBSCRIPTION_NAME = "subscription";
202
- const SUBSCRIPTION_PROPERTY = "$subscriptions";
203
- const SUBSCRIPTION_STORE = "subscriptions";
215
+ const SUBSCRIPTION_SYMBOL = Symbol(SUBSCRIPTION_PROPERTY);
204
216
  //#endregion
205
217
  export { SUBSCRIPTION_NAME, isSubscription, isSubscriptions, subscriptions };
@@ -8,13 +8,22 @@ type Comparator<Value = any> = (first: Value, second: Value) => number;
8
8
  * @param second Second value
9
9
  * @returns `0` if equal; `-1` first comes before second; `1` first comes after second
10
10
  */
11
- declare function compare(first: unknown, second: unknown): number;
12
- declare namespace compare {
11
+ export declare function compare(first: unknown, second: unknown): number;
12
+ export declare namespace compare {
13
13
  var deregister: typeof deregisterComparator;
14
- var handlers: {
15
- deregister(constructor: Constructor): void;
14
+ var handler: {
15
+ base: {
16
+ handlers: WeakMap<Constructor, string | GenericCallback>;
17
+ options: {
18
+ callback: GenericCallback;
19
+ method?: string;
20
+ };
21
+ owner: GenericCallback;
22
+ deregister: (constructor: Constructor) => void;
23
+ get: (first: unknown, second: unknown) => string | GenericCallback | undefined;
24
+ register: (constructor: Constructor, handler?: string | GenericCallback) => void;
25
+ };
16
26
  handle(first: unknown, second: unknown, ...parameters: unknown[]): number;
17
- register(constructor: Constructor, handler?: string | GenericCallback): void;
18
27
  };
19
28
  var register: typeof registerComparator;
20
29
  }
@@ -25,7 +34,7 @@ declare namespace compare {
25
34
  *
26
35
  * @param constructor Class constructor
27
36
  */
28
- declare function deregisterComparator<Instance>(constructor: Constructor<Instance>): void;
37
+ export declare function deregisterComparator<Instance>(constructor: Constructor<Instance>): void;
29
38
  /**
30
39
  * Register a custom comparison handler for a class
31
40
  *
@@ -34,6 +43,5 @@ declare function deregisterComparator<Instance>(constructor: Constructor<Instanc
34
43
  * @param constructor Class constructor
35
44
  * @param handler Method name or comparison function _(defaults to `compare`)_
36
45
  */
37
- declare function registerComparator<Instance>(constructor: Constructor<Instance>, handler?: string | Comparator<Instance>): void;
38
- //#endregion
39
- export { compare, deregisterComparator, registerComparator };
46
+ export declare function registerComparator<Instance>(constructor: Constructor<Instance>, handler?: string | Comparator<Instance>): void;
47
+ //#endregion
@@ -1,6 +1,6 @@
1
1
  import { max } from "../math/aggregate.mjs";
2
2
  import { getString, words } from "../string/misc.mjs";
3
- import { createCompareHandlers } from "./handlers.mjs";
3
+ import { createCompareHandler } from "./handlers.mjs";
4
4
  //#region src/internal/value/compare.ts
5
5
  const COMPARE_NAME = "compare";
6
6
  /**
@@ -45,7 +45,7 @@ function compareValue(first, second, compareStrings) {
45
45
  const firstType = typeof first;
46
46
  if (firstType === typeof second && firstType in comparators) return comparators[firstType](first, second);
47
47
  if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
48
- return compare.handlers.handle(first, second, compareStrings);
48
+ return compare.handler.handle(first, second, compareStrings);
49
49
  }
50
50
  /**
51
51
  * Deregister a custom comparison handler for a class
@@ -55,7 +55,7 @@ function compareValue(first, second, compareStrings) {
55
55
  * @param constructor Class constructor
56
56
  */
57
57
  function deregisterComparator(constructor) {
58
- compare.handlers.deregister(constructor);
58
+ compare.handler.base.deregister(constructor);
59
59
  }
60
60
  function getComparisonParts(value) {
61
61
  if (Array.isArray(value)) return value;
@@ -70,7 +70,7 @@ function getComparisonParts(value) {
70
70
  * @param handler Method name or comparison function _(defaults to `compare`)_
71
71
  */
72
72
  function registerComparator(constructor, handler) {
73
- compare.handlers.register(constructor, handler);
73
+ compare.handler.base.register(constructor, handler);
74
74
  }
75
75
  const comparators = {
76
76
  bigint: compareNumbers,
@@ -78,16 +78,16 @@ const comparators = {
78
78
  number: compareNumbers,
79
79
  symbol: compareSymbols
80
80
  };
81
- const compareHandlers = createCompareHandlers(compare, {
81
+ const compareHandler = createCompareHandler(compare, {
82
82
  callback: (first, second, compareStrings) => compareStrings ? getString(first).localeCompare(getString(second)) : void 0,
83
83
  method: COMPARE_NAME
84
84
  });
85
85
  compare.deregister = deregisterComparator;
86
- compare.handlers = compareHandlers;
86
+ compare.handler = compareHandler;
87
87
  compare.register = registerComparator;
88
88
  Object.defineProperties(compare, {
89
89
  deregister: { value: deregisterComparator },
90
- handlers: { value: compareHandlers },
90
+ handler: { value: compareHandler },
91
91
  register: { value: registerComparator }
92
92
  });
93
93
  //#endregion
@@ -3,7 +3,7 @@ import { Constructor, GenericCallback } from "../../models.mjs";
3
3
  /**
4
4
  * Options for value equality comparison
5
5
  */
6
- type EqualOptions = {
6
+ export type EqualOptions = {
7
7
  /**
8
8
  * When `true`, strings are compared case-insensitively
9
9
  */
@@ -31,7 +31,7 @@ type Equalizer = {
31
31
  * @param ignoreCase If `true`, comparison will be case-insensitive
32
32
  * @returns `true` if the strings are equal, otherwise `false`
33
33
  */
34
- (first: string, second: string, ignoreCase?: boolean): boolean;
34
+ compare(first: string, second: string, ignoreCase?: boolean): boolean;
35
35
  /**
36
36
  * Are two values equal?
37
37
  *
@@ -39,7 +39,7 @@ type Equalizer = {
39
39
  * @param second Second value
40
40
  * @returns `true` if the values are equal, otherwise `false`
41
41
  */
42
- (first: unknown, second: unknown): boolean;
42
+ compare(first: unknown, second: unknown): boolean;
43
43
  /**
44
44
  * Deregister a equality comparison handler for a specific class
45
45
  *
@@ -54,6 +54,17 @@ type Equalizer = {
54
54
  */
55
55
  register: <Instance>(constructor: Constructor<Instance>, handler: (first: Instance, second: Instance) => boolean) => void;
56
56
  };
57
+ type Options = {
58
+ ignoreCase: boolean;
59
+ ignoreExpressions: OptionsKeys<RegExp[]>;
60
+ ignoreKeys: OptionsKeys<Set<string>>;
61
+ relaxedNullish: boolean;
62
+ };
63
+ type OptionsKeys<Values> = {
64
+ enabled: boolean;
65
+ values: Values;
66
+ };
67
+ declare function Equalizer(this: any, options: Options): void;
57
68
  /**
58
69
  * Deregister a equality comparison handler for a specific class
59
70
  *
@@ -61,7 +72,7 @@ type Equalizer = {
61
72
  *
62
73
  * @param constructor Class constructor
63
74
  */
64
- declare function deregisterEqualizer<Instance>(constructor: Constructor<Instance>): void;
75
+ export declare function deregisterEqualizer<Instance>(constructor: Constructor<Instance>): void;
65
76
  /**
66
77
  * Are two strings equal?
67
78
  *
@@ -70,7 +81,7 @@ declare function deregisterEqualizer<Instance>(constructor: Constructor<Instance
70
81
  * @param ignoreCase If `true`, comparison will be case-insensitive
71
82
  * @returns `true` if the strings are equal, otherwise `false`
72
83
  */
73
- declare function equal(first: string, second: string, ignoreCase?: boolean): boolean;
84
+ export declare function equal(first: string, second: string, ignoreCase?: boolean): boolean;
74
85
  /**
75
86
  * Are two values equal?
76
87
  *
@@ -79,14 +90,23 @@ declare function equal(first: string, second: string, ignoreCase?: boolean): boo
79
90
  * @param options Comparison options
80
91
  * @returns `true` if the values are equal, otherwise `false`
81
92
  */
82
- declare function equal(first: unknown, second: unknown, options?: EqualOptions): boolean;
83
- declare namespace equal {
84
- var handlers: {
85
- deregister(constructor: Constructor): void;
93
+ export declare function equal(first: unknown, second: unknown, options?: EqualOptions): boolean;
94
+ export declare namespace equal {
95
+ var deregister: typeof deregisterEqualizer;
96
+ var handler: {
97
+ base: {
98
+ handlers: WeakMap<Constructor, string | GenericCallback>;
99
+ options: {
100
+ callback: GenericCallback;
101
+ method?: string;
102
+ };
103
+ owner: GenericCallback;
104
+ deregister: (constructor: Constructor) => void;
105
+ get: (first: unknown, second: unknown) => string | GenericCallback | undefined;
106
+ register: (constructor: Constructor, handler?: string | GenericCallback) => void;
107
+ };
86
108
  handle(first: unknown, second: unknown, ...parameters: unknown[]): boolean;
87
- register(constructor: Constructor, handler?: string | GenericCallback): void;
88
109
  };
89
- var deregister: typeof deregisterEqualizer;
90
110
  var initialize: typeof initializeEqualizer;
91
111
  var register: typeof registerEqualizer;
92
112
  }
@@ -98,7 +118,7 @@ declare namespace equal {
98
118
  * @param options Comparison options
99
119
  * @returns Equalizer function
100
120
  */
101
- declare function initializeEqualizer(options?: EqualOptions): Equalizer;
121
+ export declare function initializeEqualizer(options?: EqualOptions): Equalizer;
102
122
  /**
103
123
  * Register a equality comparison function for a specific class
104
124
  *
@@ -107,6 +127,5 @@ declare function initializeEqualizer(options?: EqualOptions): Equalizer;
107
127
  * @param constructor Class constructor
108
128
  * @param handler Comparison function
109
129
  */
110
- declare function registerEqualizer<Instance>(constructor: Constructor<Instance>, handler: (first: Instance, second: Instance) => boolean): void;
111
- //#endregion
112
- export { EqualOptions, deregisterEqualizer, equal, initializeEqualizer, registerEqualizer };
130
+ export declare function registerEqualizer<Instance>(constructor: Constructor<Instance>, handler: (first: Instance, second: Instance) => boolean): void;
131
+ //#endregion