@oscarpalmer/atoms 0.193.0 → 0.194.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/dist/array/difference.mjs +2 -2
  2. package/dist/array/intersection.mjs +2 -2
  3. package/dist/array/match.mjs +13 -13
  4. package/dist/array/slice.mjs +5 -5
  5. package/dist/array/sort.d.mts +5 -1
  6. package/dist/array/sort.mjs +4 -2
  7. package/dist/array/union.mjs +2 -2
  8. package/dist/beacon.d.mts +8 -1
  9. package/dist/beacon.mjs +52 -60
  10. package/dist/color/constants.d.mts +1 -1
  11. package/dist/color/constants.mjs +3 -5
  12. package/dist/color/instance.mjs +34 -41
  13. package/dist/color/misc/format.d.mts +3 -2
  14. package/dist/color/misc/format.mjs +4 -1
  15. package/dist/color/misc/is.d.mts +9 -1
  16. package/dist/color/misc/is.mjs +11 -1
  17. package/dist/color/misc/state.d.mts +6 -6
  18. package/dist/color/misc/state.mjs +11 -14
  19. package/dist/color/models.d.mts +23 -68
  20. package/dist/function/assert.mjs +2 -2
  21. package/dist/function/limit.d.mts +0 -6
  22. package/dist/function/limit.mjs +2 -2
  23. package/dist/function/memoize.mjs +19 -32
  24. package/dist/function/once.d.mts +0 -3
  25. package/dist/function/once.mjs +16 -13
  26. package/dist/function/retry.d.mts +1 -24
  27. package/dist/function/retry.mjs +1 -1
  28. package/dist/function/work.mjs +13 -11
  29. package/dist/herald.d.mts +30 -31
  30. package/dist/herald.mjs +74 -56
  31. package/dist/index.d.mts +100 -185
  32. package/dist/index.mjs +680 -702
  33. package/dist/internal/abort.d.mts +10 -0
  34. package/dist/internal/abort.mjs +14 -0
  35. package/dist/internal/array/chunk.mjs +2 -2
  36. package/dist/internal/array/find.mjs +2 -2
  37. package/dist/internal/array/sets.d.mts +4 -4
  38. package/dist/internal/array/sets.mjs +7 -7
  39. package/dist/internal/function/timer.mjs +19 -15
  40. package/dist/internal/number.mjs +7 -7
  41. package/dist/internal/result.mjs +3 -3
  42. package/dist/internal/sized.mjs +4 -4
  43. package/dist/internal/string.mjs +4 -4
  44. package/dist/internal/subscription.d.mts +24 -8
  45. package/dist/internal/subscription.mjs +49 -36
  46. package/dist/internal/value/equal.mjs +6 -6
  47. package/dist/internal/value/misc.mjs +14 -14
  48. package/dist/internal/value/set.mjs +2 -2
  49. package/dist/logger.mjs +15 -39
  50. package/dist/promise/constants.d.mts +17 -0
  51. package/dist/promise/constants.mjs +14 -0
  52. package/dist/promise/delay.mjs +7 -10
  53. package/dist/promise/helpers.mjs +1 -1
  54. package/dist/promise/index.mjs +14 -17
  55. package/dist/promise/misc.d.mts +2 -1
  56. package/dist/promise/misc.mjs +8 -7
  57. package/dist/promise/models.d.mts +4 -16
  58. package/dist/promise/models.mjs +4 -13
  59. package/dist/promise/timed.mjs +9 -10
  60. package/dist/query.mjs +15 -15
  61. package/dist/queue.mjs +103 -116
  62. package/dist/random.mjs +7 -7
  63. package/dist/result/index.d.mts +0 -3
  64. package/dist/result/index.mjs +1 -1
  65. package/dist/result/match.d.mts +0 -3
  66. package/dist/result/match.mjs +4 -4
  67. package/dist/result/misc.mjs +2 -2
  68. package/dist/result/work/flow.d.mts +0 -3
  69. package/dist/result/work/flow.mjs +5 -5
  70. package/dist/result/work/pipe.d.mts +0 -3
  71. package/dist/result/work/pipe.mjs +3 -3
  72. package/dist/string/case.mjs +20 -20
  73. package/dist/string/fuzzy.mjs +23 -18
  74. package/dist/string/index.mjs +7 -7
  75. package/dist/string/normalize.mjs +14 -14
  76. package/dist/string/template.mjs +2 -2
  77. package/dist/value/clone.mjs +10 -10
  78. package/dist/value/smush.mjs +2 -2
  79. package/package.json +13 -5
  80. package/src/array/difference.ts +0 -73
  81. package/src/array/exists.ts +0 -93
  82. package/src/array/filter.ts +0 -182
  83. package/src/array/find.ts +0 -183
  84. package/src/array/first.ts +0 -196
  85. package/src/array/flatten.ts +0 -20
  86. package/src/array/from.ts +0 -129
  87. package/src/array/get.ts +0 -131
  88. package/src/array/group-by.ts +0 -369
  89. package/src/array/index.ts +0 -26
  90. package/src/array/insert.ts +0 -52
  91. package/src/array/intersection.ts +0 -72
  92. package/src/array/last.ts +0 -194
  93. package/src/array/match.ts +0 -436
  94. package/src/array/move.ts +0 -315
  95. package/src/array/partition.ts +0 -91
  96. package/src/array/push.ts +0 -23
  97. package/src/array/reverse.ts +0 -33
  98. package/src/array/select.ts +0 -260
  99. package/src/array/single.ts +0 -93
  100. package/src/array/slice.ts +0 -335
  101. package/src/array/sort.ts +0 -607
  102. package/src/array/splice.ts +0 -106
  103. package/src/array/swap.ts +0 -322
  104. package/src/array/to-map.ts +0 -371
  105. package/src/array/to-record.ts +0 -351
  106. package/src/array/to-set.ts +0 -80
  107. package/src/array/toggle.ts +0 -79
  108. package/src/array/union.ts +0 -72
  109. package/src/array/unique.ts +0 -67
  110. package/src/array/update.ts +0 -75
  111. package/src/beacon.ts +0 -378
  112. package/src/color/constants.ts +0 -137
  113. package/src/color/index.ts +0 -83
  114. package/src/color/instance.ts +0 -162
  115. package/src/color/misc/alpha.ts +0 -56
  116. package/src/color/misc/format.ts +0 -29
  117. package/src/color/misc/get.ts +0 -210
  118. package/src/color/misc/is.ts +0 -221
  119. package/src/color/misc/state.ts +0 -243
  120. package/src/color/models.ts +0 -389
  121. package/src/color/space/hex.ts +0 -184
  122. package/src/color/space/hsl.ts +0 -174
  123. package/src/color/space/hwb.ts +0 -153
  124. package/src/color/space/rgb.ts +0 -240
  125. package/src/function/assert.ts +0 -174
  126. package/src/function/index.ts +0 -2
  127. package/src/function/limit.ts +0 -83
  128. package/src/function/memoize.ts +0 -202
  129. package/src/function/once.ts +0 -200
  130. package/src/function/retry.ts +0 -175
  131. package/src/function/work.ts +0 -1007
  132. package/src/herald.ts +0 -216
  133. package/src/index.ts +0 -68
  134. package/src/internal/array/callbacks.ts +0 -46
  135. package/src/internal/array/chunk.ts +0 -51
  136. package/src/internal/array/compact.ts +0 -56
  137. package/src/internal/array/find.ts +0 -200
  138. package/src/internal/array/group.ts +0 -42
  139. package/src/internal/array/index-of.ts +0 -182
  140. package/src/internal/array/insert.ts +0 -80
  141. package/src/internal/array/overlap.ts +0 -35
  142. package/src/internal/array/sets.ts +0 -74
  143. package/src/internal/array/shuffle.ts +0 -33
  144. package/src/internal/array/update.ts +0 -52
  145. package/src/internal/function/misc.ts +0 -8
  146. package/src/internal/function/timer.ts +0 -168
  147. package/src/internal/is.ts +0 -244
  148. package/src/internal/math/aggregate.ts +0 -164
  149. package/src/internal/math/misc.ts +0 -28
  150. package/src/internal/number.ts +0 -129
  151. package/src/internal/random.ts +0 -49
  152. package/src/internal/result.ts +0 -92
  153. package/src/internal/sized.ts +0 -25
  154. package/src/internal/string.ts +0 -128
  155. package/src/internal/subscription.ts +0 -264
  156. package/src/internal/value/compare.ts +0 -170
  157. package/src/internal/value/equal.ts +0 -465
  158. package/src/internal/value/get.ts +0 -57
  159. package/src/internal/value/handlers.ts +0 -95
  160. package/src/internal/value/has.ts +0 -118
  161. package/src/internal/value/misc.ts +0 -125
  162. package/src/internal/value/partial.ts +0 -46
  163. package/src/internal/value/set.ts +0 -132
  164. package/src/is.ts +0 -182
  165. package/src/logger.ts +0 -230
  166. package/src/math.ts +0 -281
  167. package/src/models.ts +0 -286
  168. package/src/number.ts +0 -1
  169. package/src/promise/delay.ts +0 -62
  170. package/src/promise/helpers.ts +0 -96
  171. package/src/promise/index.ts +0 -300
  172. package/src/promise/misc.ts +0 -96
  173. package/src/promise/models.ts +0 -195
  174. package/src/promise/timed.ts +0 -91
  175. package/src/query.ts +0 -147
  176. package/src/queue.ts +0 -814
  177. package/src/random.ts +0 -125
  178. package/src/result/index.ts +0 -105
  179. package/src/result/match.ts +0 -124
  180. package/src/result/misc.ts +0 -129
  181. package/src/result/models.ts +0 -83
  182. package/src/result/work/flow.ts +0 -488
  183. package/src/result/work/pipe.ts +0 -496
  184. package/src/sized/map.ts +0 -110
  185. package/src/sized/set.ts +0 -107
  186. package/src/string/case.ts +0 -236
  187. package/src/string/fuzzy.ts +0 -444
  188. package/src/string/index.ts +0 -199
  189. package/src/string/match.ts +0 -80
  190. package/src/string/normalize.ts +0 -205
  191. package/src/string/template.ts +0 -161
  192. package/src/value/clone.ts +0 -319
  193. package/src/value/collection.ts +0 -63
  194. package/src/value/diff.ts +0 -232
  195. package/src/value/freeze.ts +0 -322
  196. package/src/value/handle.ts +0 -3
  197. package/src/value/index.ts +0 -5
  198. package/src/value/merge.ts +0 -278
  199. package/src/value/omit.ts +0 -20
  200. package/src/value/pick.ts +0 -20
  201. package/src/value/shake.ts +0 -45
  202. package/src/value/smush.ts +0 -89
  203. package/src/value/transform.ts +0 -153
  204. package/src/value/unsmush.ts +0 -84
@@ -1,465 +0,0 @@
1
- import type {ArrayOrPlainObject, Constructor, PlainObject, TypedArray} from '../../models';
2
- import {isNonPlainObject, isPlainObject, isPrimitive, isTypedArray} from '../is';
3
- import {getCompareHandlers} from './handlers';
4
-
5
- // #region Types
6
-
7
- /**
8
- * Options for value equality comparison
9
- */
10
- export type EqualOptions = {
11
- /**
12
- * When `true`, strings are compared case-insensitively
13
- */
14
- ignoreCase?: boolean;
15
- /**
16
- * Keys _(or key expressions)_ to ignore when comparing objects
17
- */
18
- ignoreKeys?: string | RegExp | Array<string | RegExp>;
19
- /**
20
- * Should `null` and `undefined` be considered equal?
21
- */
22
- relaxedNullish?: boolean;
23
- };
24
-
25
- /**
26
- * An equalizer function for comparing values for equality, with predefined options
27
- *
28
- * Can be used to compare values, and register or deregister equality comparison handlers for specific classes
29
- */
30
- type Equalizer = {
31
- /**
32
- * Are two strings equal?
33
- *
34
- * @param first First string
35
- * @param second Second string
36
- * @param ignoreCase If `true`, comparison will be case-insensitive
37
- * @returns `true` if the strings are equal, otherwise `false`
38
- */
39
- (first: string, second: string, ignoreCase?: boolean): boolean;
40
-
41
- /**
42
- * Are two values equal?
43
- *
44
- * @param first First value
45
- * @param second Second value
46
- * @returns `true` if the values are equal, otherwise `false`
47
- */
48
- (first: unknown, second: unknown): boolean;
49
-
50
- /**
51
- * Deregister a equality comparison handler for a specific class
52
- *
53
- * @param constructor Class constructor
54
- */
55
- deregister: <Instance>(constructor: Constructor<Instance>) => void;
56
-
57
- /**
58
- * Register a equality comparison function for a specific class
59
- *
60
- * @param constructor Class constructor
61
- * @param handler Comparison function
62
- */
63
- register: <Instance>(
64
- constructor: Constructor<Instance>,
65
- handler: (first: Instance, second: Instance) => boolean,
66
- ) => void;
67
- };
68
-
69
- type Options = {
70
- ignoreCase: boolean;
71
- ignoreExpressions: OptionsKeys<RegExp[]>;
72
- ignoreKeys: OptionsKeys<Set<string>>;
73
- relaxedNullish: boolean;
74
- };
75
-
76
- type OptionsKeys<Values> = {
77
- enabled: boolean;
78
- values: Values;
79
- };
80
-
81
- // #endregion
82
-
83
- // #region Functions
84
-
85
- /**
86
- * Deregister a equality comparison handler for a specific class
87
- *
88
- * _Available as `deregisterEqualizer` and `equal.deregister`_
89
- *
90
- * @param constructor Class constructor
91
- */
92
- export function deregisterEqualizer<Instance>(constructor: Constructor<Instance>): void {
93
- equal.handlers.deregister(constructor);
94
- }
95
-
96
- function filterKey(key: string | symbol, options: Options): boolean {
97
- if (typeof key !== 'string') {
98
- return true;
99
- }
100
-
101
- if (
102
- options.ignoreExpressions.enabled &&
103
- options.ignoreExpressions.values.some(expression => expression.test(key))
104
- ) {
105
- return false;
106
- }
107
-
108
- if (options.ignoreKeys.enabled && options.ignoreKeys.values.has(key)) {
109
- return false;
110
- }
111
-
112
- return true;
113
- }
114
-
115
- /**
116
- * Are two strings equal?
117
- *
118
- * @param first First string
119
- * @param second Second string
120
- * @param ignoreCase If `true`, comparison will be case-insensitive
121
- * @returns `true` if the strings are equal, otherwise `false`
122
- */
123
- export function equal(first: string, second: string, ignoreCase?: boolean): boolean;
124
-
125
- /**
126
- * Are two values equal?
127
- *
128
- * @param first First value
129
- * @param second Second value
130
- * @param options Comparison options
131
- * @returns `true` if the values are equal, otherwise `false`
132
- */
133
- export function equal(first: unknown, second: unknown, options?: EqualOptions): boolean;
134
-
135
- export function equal(first: unknown, second: unknown, options?: boolean | EqualOptions): boolean {
136
- return equalValue(first, second, getEqualOptions(options));
137
- }
138
-
139
- equal.handlers = getCompareHandlers<boolean>(equal, {
140
- callback: Object.is,
141
- });
142
-
143
- equal.deregister = deregisterEqualizer;
144
- equal.initialize = initializeEqualizer;
145
- equal.register = registerEqualizer;
146
-
147
- function equalArray(first: unknown[], second: unknown[], options: Options): boolean {
148
- const {length} = first;
149
-
150
- if (length !== second.length) {
151
- return false;
152
- }
153
-
154
- let offset = 0;
155
-
156
- if (length >= EQUAL_ARRAY_THRESHOLD) {
157
- offset = Math.round(length / EQUAL_ARRAY_PEEK_PERCENTAGE);
158
- offset = offset > EQUAL_ARRAY_THRESHOLD ? EQUAL_ARRAY_THRESHOLD : offset;
159
-
160
- for (let index = 0; index < offset; index += 1) {
161
- if (
162
- !(
163
- equalValue(first[index], second[index], options) &&
164
- equalValue(first[length - index - 1], second[length - index - 1], options)
165
- )
166
- ) {
167
- return false;
168
- }
169
- }
170
- }
171
-
172
- const end = length - offset;
173
-
174
- for (let index = offset; index < end; index += 1) {
175
- if (!equalValue(first[index], second[index], options)) {
176
- return false;
177
- }
178
- }
179
-
180
- return true;
181
- }
182
-
183
- function equalArrayBuffer(first: ArrayBuffer, second: ArrayBuffer, options: Options): boolean {
184
- return first.byteLength === second.byteLength
185
- ? equalArray(new Uint8Array(first) as never, new Uint8Array(second) as never, options)
186
- : false;
187
- }
188
-
189
- function equalDataView(first: DataView, second: DataView, options: Options): boolean {
190
- return first.byteOffset === second.byteOffset
191
- ? equalArrayBuffer(first.buffer as ArrayBuffer, second.buffer as ArrayBuffer, options)
192
- : false;
193
- }
194
-
195
- function equalMap(
196
- first: Map<unknown, unknown>,
197
- second: Map<unknown, unknown>,
198
- options: Options,
199
- ): boolean {
200
- const {size} = first;
201
-
202
- if (size !== second.size) {
203
- return false;
204
- }
205
-
206
- const firstKeys = [...first.keys()];
207
-
208
- for (let index = 0; index < size; index += 1) {
209
- const key = firstKeys[index];
210
-
211
- if (!second.has(key) || !equalValue(first.get(key), second.get(key), options)) {
212
- return false;
213
- }
214
- }
215
-
216
- return true;
217
- }
218
-
219
- function equalPlainObject(
220
- first: ArrayOrPlainObject,
221
- second: ArrayOrPlainObject,
222
- options: Options,
223
- ): boolean {
224
- let firstKeys = [...Object.keys(first), ...Object.getOwnPropertySymbols(first)];
225
- let secondKeys = [...Object.keys(second), ...Object.getOwnPropertySymbols(second)];
226
-
227
- if (options.ignoreKeys.enabled || options.ignoreExpressions.enabled) {
228
- firstKeys = firstKeys.filter(key => filterKey(key, options));
229
- secondKeys = secondKeys.filter(key => filterKey(key, options));
230
- }
231
-
232
- const useSet = secondKeys.length >= MINIMUM_LENGTH_FOR_SET;
233
- const secondSet = useSet ? new Set(secondKeys) : undefined;
234
-
235
- const {length} = firstKeys;
236
-
237
- if (length !== secondKeys.length) {
238
- return false;
239
- }
240
-
241
- for (let index = 0; index < length; index += 1) {
242
- const key = firstKeys[index];
243
-
244
- if (
245
- !(secondSet?.has(key) ?? secondKeys.includes(key)) ||
246
- !equalValue(first[key as never], second[key as never], options)
247
- ) {
248
- return false;
249
- }
250
- }
251
-
252
- return true;
253
- }
254
-
255
- function equalProperties(
256
- first: object,
257
- second: object,
258
- properties: string[],
259
- options: Options,
260
- ): boolean {
261
- const {length} = properties;
262
-
263
- for (let index = 0; index < length; index += 1) {
264
- const property = properties[index];
265
-
266
- if (!equalValue((first as PlainObject)[property], (second as PlainObject)[property], options)) {
267
- return false;
268
- }
269
- }
270
-
271
- return true;
272
- }
273
-
274
- function equalSet(first: Set<unknown>, second: Set<unknown>, options: Options): boolean {
275
- const {size} = first;
276
-
277
- if (size !== second.size) {
278
- return false;
279
- }
280
-
281
- const firstValues = [...first];
282
- const secondValues = [...second];
283
-
284
- for (let index = 0; index < size; index += 1) {
285
- const firstValue = firstValues[index];
286
-
287
- if (
288
- isPrimitive(firstValue)
289
- ? !second.has(firstValue)
290
- : !secondValues.some(secondValue => equalValue(firstValue, secondValue, options))
291
- ) {
292
- return false;
293
- }
294
- }
295
-
296
- return true;
297
- }
298
-
299
- function equalTypedArray(first: TypedArray, second: TypedArray): boolean {
300
- if (first.constructor !== second.constructor) {
301
- return false;
302
- }
303
-
304
- if (first.byteLength !== second.byteLength) {
305
- return false;
306
- }
307
-
308
- const {length} = first;
309
-
310
- for (let index = 0; index < length; index += 1) {
311
- if (first[index] !== second[index]) {
312
- return false;
313
- }
314
- }
315
-
316
- return true;
317
- }
318
-
319
- function equalValue(first: unknown, second: unknown, options: Options): boolean {
320
- if (options.relaxedNullish && first == null && second == null) {
321
- return true;
322
- }
323
-
324
- switch (true) {
325
- case Object.is(first, second):
326
- return true;
327
-
328
- case first == null || second == null:
329
- return first === second;
330
-
331
- case typeof first !== typeof second:
332
- return false;
333
-
334
- case typeof first === 'string' && options.ignoreCase === true:
335
- return Object.is(first.toLocaleLowerCase(), (second as string).toLocaleLowerCase());
336
-
337
- case first instanceof ArrayBuffer && second instanceof ArrayBuffer:
338
- return equalArrayBuffer(first, second, options);
339
-
340
- case first instanceof Date && second instanceof Date:
341
- return Object.is(first.getTime(), (second as Date).getTime());
342
-
343
- case first instanceof DataView && second instanceof DataView:
344
- return equalDataView(first, second, options);
345
-
346
- case first instanceof Error && second instanceof Error:
347
- return equalProperties(first, second, ERROR_PROPERTIES, options);
348
-
349
- case first instanceof Map && second instanceof Map:
350
- return equalMap(first, second, options);
351
-
352
- case first instanceof RegExp && second instanceof RegExp:
353
- return equalProperties(first, second, EXPRESSION_PROPERTIES, options);
354
-
355
- case first instanceof Set && second instanceof Set:
356
- return equalSet(first, second, options);
357
-
358
- case Array.isArray(first) && Array.isArray(second):
359
- return equalArray(first, second, options);
360
-
361
- case isPlainObject(first) && isPlainObject(second):
362
- return equalPlainObject(first, second, options);
363
-
364
- case isTypedArray(first) && isTypedArray(second):
365
- return equalTypedArray(first as TypedArray, second as TypedArray);
366
-
367
- default:
368
- return equal.handlers.handle(first, second, options);
369
- }
370
- }
371
-
372
- function getEqualOptions(input?: boolean | EqualOptions): Options {
373
- const options: Options = {
374
- ignoreCase: false,
375
- ignoreExpressions: {
376
- enabled: false,
377
- values: [],
378
- },
379
- ignoreKeys: {
380
- enabled: false,
381
- values: new Set(),
382
- },
383
- relaxedNullish: false,
384
- };
385
-
386
- if (typeof input === 'boolean') {
387
- options.ignoreCase = input;
388
-
389
- return options;
390
- }
391
-
392
- if (isNonPlainObject(input)) {
393
- return options;
394
- }
395
-
396
- options.ignoreCase = typeof input.ignoreCase === 'boolean' ? input.ignoreCase : false;
397
-
398
- options.ignoreExpressions.values = (
399
- Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]
400
- ).filter(key => key instanceof RegExp);
401
-
402
- options.ignoreKeys.values = new Set(
403
- (Array.isArray(input.ignoreKeys) ? input.ignoreKeys : [input.ignoreKeys]).filter(
404
- key => typeof key === 'string',
405
- ),
406
- );
407
-
408
- options.ignoreExpressions.enabled = options.ignoreExpressions.values.length > 0;
409
-
410
- options.ignoreKeys.enabled = options.ignoreKeys.values.size > 0;
411
-
412
- options.relaxedNullish = input.relaxedNullish === true;
413
-
414
- return options;
415
- }
416
-
417
- /**
418
- * Create an equalizer with predefined options
419
- *
420
- * _Available as `initializeEqualizer` and `equal.initialize`_
421
- *
422
- * @param options Comparison options
423
- * @returns Equalizer function
424
- */
425
- export function initializeEqualizer(options?: EqualOptions): Equalizer {
426
- const actual = getEqualOptions(options);
427
-
428
- const equalizer = (first: unknown, second: unknown): boolean => equalValue(first, second, actual);
429
-
430
- equalizer.deregister = deregisterEqualizer;
431
- equalizer.register = registerEqualizer;
432
-
433
- return equalizer;
434
- }
435
-
436
- /**
437
- * Register a equality comparison function for a specific class
438
- *
439
- * _Available as `registerEqualizer` and `equal.register`_
440
- *
441
- * @param constructor Class constructor
442
- * @param handler Comparison function
443
- */
444
- export function registerEqualizer<Instance>(
445
- constructor: Constructor<Instance>,
446
- handler: (first: Instance, second: Instance) => boolean,
447
- ): void {
448
- equal.handlers.register(constructor, handler);
449
- }
450
-
451
- // #endregion
452
-
453
- // #region Variables
454
-
455
- const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
456
-
457
- const EQUAL_ARRAY_THRESHOLD = 100;
458
-
459
- const ERROR_PROPERTIES: string[] = ['name', 'message'];
460
-
461
- const EXPRESSION_PROPERTIES: string[] = ['source', 'flags'];
462
-
463
- const MINIMUM_LENGTH_FOR_SET = 16;
464
-
465
- // #endregion
@@ -1,57 +0,0 @@
1
- import type {NestedKeys, NestedValue, PlainObject} from '../../models';
2
- import type {Ok} from '../../result/models';
3
- import {getNestedValue} from './misc';
4
-
5
- // #region Functions
6
-
7
- /**
8
- * Get the value from an object using a known path
9
- *
10
- * @param data Object to get value from
11
- * @param path Path for value
12
- * @returns Found value, or `undefined`
13
- *
14
- * @example
15
- * ```typescript
16
- * const data = {foo: {bar: {baz: 42}}};
17
- *
18
- * getValue(data, 'foo'); // => {bar: {baz: 42}}
19
- * getValue(data, 'foo.bar'); // => {baz: 42}
20
- * getValue(data, 'foo.bar.baz'); // => 42
21
- * getValue(data, 'foo.nope'); // => undefined
22
- * ```
23
- */
24
- export function getValue<Data extends PlainObject, Path extends NestedKeys<Data>>(
25
- data: Data,
26
- path: Path,
27
- ): NestedValue<Data, Path>;
28
-
29
- /**
30
- * Get the value from an object using an unknown path
31
- *
32
- * @param data Object to get value from
33
- * @param path Path for value
34
- * @param ignoreCase If `true`, path matching is case-insensitive
35
- * @returns Found value, or `undefined`
36
- *
37
- * @example
38
- * ```typescript
39
- * const data = {foo: {bar: {baz: 42}}};
40
- *
41
- * getValue(data, 'foo'); // => {bar: {baz: 42}}
42
- * getValue(data, 'foo.bar'); // => {baz: 42}
43
- * getValue(data, 'Foo.Bar.Baz', true); // => 42
44
- * getValue(data, 'foo.nope'); // => undefined
45
- * ```
46
- */
47
- export function getValue<Data extends PlainObject>(
48
- data: Data,
49
- path: string,
50
- ignoreCase?: boolean,
51
- ): unknown;
52
-
53
- export function getValue(data: PlainObject, path: string, ignoreCase?: boolean): unknown {
54
- return (getNestedValue(data, path, ignoreCase === true) as Ok<unknown>).value;
55
- }
56
-
57
- // #endregion
@@ -1,95 +0,0 @@
1
- import type {Constructor, GenericCallback} from '../../models';
2
- import {isNonConstructor} from '../is';
3
-
4
- type Options = {
5
- callback: GenericCallback;
6
- method?: string;
7
- };
8
-
9
- export function getCompareHandlers<Value>(owner: GenericCallback, options: Options) {
10
- const handlers = getHandlers(owner, options);
11
-
12
- return {
13
- deregister(constructor: Constructor) {
14
- handlers.deregister(constructor);
15
- },
16
- handle(first: unknown, second: unknown, ...parameters: unknown[]): Value {
17
- const handler = handlers.get(first, second);
18
-
19
- if (handler == null) {
20
- return options.callback(first, second, ...parameters);
21
- }
22
-
23
- return typeof handler === 'function'
24
- ? handler(first, second)
25
- : (first as any)[handler](second);
26
- },
27
- register(constructor: Constructor, handler?: string | GenericCallback) {
28
- handlers.register(constructor, handler);
29
- },
30
- };
31
- }
32
-
33
- function getHandlers(owner: GenericCallback, options: Options) {
34
- const handlers = new WeakMap<Constructor, string | GenericCallback>();
35
-
36
- return {
37
- deregister(constructor: Constructor) {
38
- handlers.delete(constructor);
39
- },
40
- get(first: unknown, second: unknown): string | GenericCallback | undefined {
41
- if (
42
- isConstructable(first) &&
43
- isConstructable(second) &&
44
- (first as object).constructor === (second as object).constructor
45
- ) {
46
- return handlers.get((first as object).constructor as Constructor);
47
- }
48
- },
49
- register(constructor: Constructor, handler?: string | GenericCallback) {
50
- if (isNonConstructor(constructor) || handler === owner) {
51
- return;
52
- }
53
-
54
- let actual: string | GenericCallback | undefined = handler ?? options.method;
55
-
56
- if (typeof actual !== 'function' && typeof actual !== 'string') {
57
- return;
58
- }
59
-
60
- if (typeof actual === 'string') {
61
- actual = typeof constructor.prototype[actual] === 'function' ? actual : undefined;
62
- }
63
-
64
- if (actual != null) {
65
- handlers.set(constructor, actual);
66
- }
67
- },
68
- };
69
- }
70
-
71
- export function getSelfHandlers(owner: GenericCallback, options: Options) {
72
- const handlers = getHandlers(owner, options);
73
-
74
- return {
75
- deregister(constructor: Constructor) {
76
- handlers.deregister(constructor);
77
- },
78
- handle(value: unknown, ...parameters: unknown[]) {
79
- const handler = handlers.get(value, value);
80
-
81
- if (handler == null) {
82
- return options.callback(value, ...parameters);
83
- }
84
-
85
- return typeof handler === 'function' ? handler(value) : (value as any)[handler]();
86
- },
87
- register(constructor: Constructor, handler?: string | GenericCallback) {
88
- handlers.register(constructor, handler);
89
- },
90
- };
91
- }
92
-
93
- function isConstructable(value: unknown): boolean {
94
- return typeof value === 'object' && value !== null;
95
- }