@oscarpalmer/atoms 0.192.0 → 0.193.1

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 (130) hide show
  1. package/dist/index.d.mts +25 -23
  2. package/dist/index.mjs +30 -31
  3. package/dist/queue.d.mts +25 -23
  4. package/dist/queue.mjs +27 -28
  5. package/package.json +3 -4
  6. package/src/array/difference.ts +0 -73
  7. package/src/array/exists.ts +0 -93
  8. package/src/array/filter.ts +0 -182
  9. package/src/array/find.ts +0 -183
  10. package/src/array/first.ts +0 -196
  11. package/src/array/flatten.ts +0 -20
  12. package/src/array/from.ts +0 -129
  13. package/src/array/get.ts +0 -131
  14. package/src/array/group-by.ts +0 -369
  15. package/src/array/index.ts +0 -26
  16. package/src/array/insert.ts +0 -52
  17. package/src/array/intersection.ts +0 -72
  18. package/src/array/last.ts +0 -194
  19. package/src/array/match.ts +0 -436
  20. package/src/array/move.ts +0 -315
  21. package/src/array/partition.ts +0 -91
  22. package/src/array/push.ts +0 -23
  23. package/src/array/reverse.ts +0 -33
  24. package/src/array/select.ts +0 -260
  25. package/src/array/single.ts +0 -93
  26. package/src/array/slice.ts +0 -335
  27. package/src/array/sort.ts +0 -607
  28. package/src/array/splice.ts +0 -106
  29. package/src/array/swap.ts +0 -322
  30. package/src/array/to-map.ts +0 -371
  31. package/src/array/to-record.ts +0 -351
  32. package/src/array/to-set.ts +0 -80
  33. package/src/array/toggle.ts +0 -79
  34. package/src/array/union.ts +0 -72
  35. package/src/array/unique.ts +0 -67
  36. package/src/array/update.ts +0 -75
  37. package/src/beacon.ts +0 -378
  38. package/src/color/constants.ts +0 -137
  39. package/src/color/index.ts +0 -83
  40. package/src/color/instance.ts +0 -162
  41. package/src/color/misc/alpha.ts +0 -56
  42. package/src/color/misc/format.ts +0 -29
  43. package/src/color/misc/get.ts +0 -210
  44. package/src/color/misc/is.ts +0 -221
  45. package/src/color/misc/state.ts +0 -243
  46. package/src/color/models.ts +0 -389
  47. package/src/color/space/hex.ts +0 -184
  48. package/src/color/space/hsl.ts +0 -174
  49. package/src/color/space/hwb.ts +0 -153
  50. package/src/color/space/rgb.ts +0 -240
  51. package/src/function/assert.ts +0 -174
  52. package/src/function/index.ts +0 -2
  53. package/src/function/limit.ts +0 -83
  54. package/src/function/memoize.ts +0 -202
  55. package/src/function/once.ts +0 -200
  56. package/src/function/retry.ts +0 -175
  57. package/src/function/work.ts +0 -1007
  58. package/src/herald.ts +0 -216
  59. package/src/index.ts +0 -68
  60. package/src/internal/array/callbacks.ts +0 -46
  61. package/src/internal/array/chunk.ts +0 -51
  62. package/src/internal/array/compact.ts +0 -56
  63. package/src/internal/array/find.ts +0 -200
  64. package/src/internal/array/group.ts +0 -42
  65. package/src/internal/array/index-of.ts +0 -182
  66. package/src/internal/array/insert.ts +0 -80
  67. package/src/internal/array/overlap.ts +0 -35
  68. package/src/internal/array/sets.ts +0 -74
  69. package/src/internal/array/shuffle.ts +0 -33
  70. package/src/internal/array/update.ts +0 -52
  71. package/src/internal/function/misc.ts +0 -8
  72. package/src/internal/function/timer.ts +0 -168
  73. package/src/internal/is.ts +0 -244
  74. package/src/internal/math/aggregate.ts +0 -164
  75. package/src/internal/math/misc.ts +0 -28
  76. package/src/internal/number.ts +0 -129
  77. package/src/internal/random.ts +0 -49
  78. package/src/internal/result.ts +0 -92
  79. package/src/internal/sized.ts +0 -25
  80. package/src/internal/string.ts +0 -128
  81. package/src/internal/subscription.ts +0 -264
  82. package/src/internal/value/compare.ts +0 -170
  83. package/src/internal/value/equal.ts +0 -465
  84. package/src/internal/value/get.ts +0 -57
  85. package/src/internal/value/handlers.ts +0 -95
  86. package/src/internal/value/has.ts +0 -118
  87. package/src/internal/value/misc.ts +0 -125
  88. package/src/internal/value/partial.ts +0 -46
  89. package/src/internal/value/set.ts +0 -132
  90. package/src/is.ts +0 -182
  91. package/src/logger.ts +0 -230
  92. package/src/math.ts +0 -281
  93. package/src/models.ts +0 -286
  94. package/src/number.ts +0 -1
  95. package/src/promise/delay.ts +0 -62
  96. package/src/promise/helpers.ts +0 -96
  97. package/src/promise/index.ts +0 -300
  98. package/src/promise/misc.ts +0 -96
  99. package/src/promise/models.ts +0 -195
  100. package/src/promise/timed.ts +0 -91
  101. package/src/query.ts +0 -147
  102. package/src/queue.ts +0 -814
  103. package/src/random.ts +0 -125
  104. package/src/result/index.ts +0 -105
  105. package/src/result/match.ts +0 -124
  106. package/src/result/misc.ts +0 -129
  107. package/src/result/models.ts +0 -83
  108. package/src/result/work/flow.ts +0 -488
  109. package/src/result/work/pipe.ts +0 -496
  110. package/src/sized/map.ts +0 -110
  111. package/src/sized/set.ts +0 -107
  112. package/src/string/case.ts +0 -236
  113. package/src/string/fuzzy.ts +0 -444
  114. package/src/string/index.ts +0 -199
  115. package/src/string/match.ts +0 -80
  116. package/src/string/normalize.ts +0 -205
  117. package/src/string/template.ts +0 -161
  118. package/src/value/clone.ts +0 -319
  119. package/src/value/collection.ts +0 -63
  120. package/src/value/diff.ts +0 -232
  121. package/src/value/freeze.ts +0 -322
  122. package/src/value/handle.ts +0 -3
  123. package/src/value/index.ts +0 -5
  124. package/src/value/merge.ts +0 -278
  125. package/src/value/omit.ts +0 -20
  126. package/src/value/pick.ts +0 -20
  127. package/src/value/shake.ts +0 -45
  128. package/src/value/smush.ts +0 -89
  129. package/src/value/transform.ts +0 -153
  130. 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
- }