@oscarpalmer/atoms 0.140.0 → 0.141.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.
- package/dist/array/group-by.js +2 -1
- package/dist/array/to-map.js +2 -1
- package/dist/array/to-record.js +2 -1
- package/dist/atoms.full.js +38 -23
- package/dist/index.js +9 -9
- package/dist/internal/value/compare.js +12 -10
- package/dist/internal/value/equal.js +13 -7
- package/dist/string/template.js +2 -1
- package/dist/value/clone.js +10 -8
- package/dist/value/merge.js +2 -1
- package/dist/value/misc.js +1 -2
- package/package.json +5 -1
- package/src/array/group-by.ts +9 -7
- package/src/array/to-map.ts +9 -7
- package/src/array/to-record.ts +9 -7
- package/src/internal/value/compare.ts +18 -14
- package/src/internal/value/equal.ts +43 -14
- package/src/string/template.ts +3 -1
- package/src/value/clone.ts +14 -10
- package/src/value/merge.ts +3 -1
- package/src/value/misc.ts +0 -1
- package/types/array/group-by.d.ts +10 -6
- package/types/array/to-map.d.ts +10 -6
- package/types/array/to-record.d.ts +10 -6
- package/types/internal/value/compare.d.ts +12 -2
- package/types/internal/value/equal.d.ts +28 -5
- package/types/string/template.d.ts +4 -1
- package/types/value/clone.d.ts +12 -2
- package/types/value/merge.d.ts +5 -1
- package/types/value/misc.d.ts +0 -1
package/dist/array/group-by.js
CHANGED
|
@@ -2,7 +2,8 @@ import { groupValues } from "../internal/array/group.js";
|
|
|
2
2
|
function groupBy(array, first, second) {
|
|
3
3
|
return groupValues(array, first, second, false);
|
|
4
4
|
}
|
|
5
|
+
groupBy.arrays = groupArraysBy;
|
|
5
6
|
function groupArraysBy(array, first, second) {
|
|
6
7
|
return groupValues(array, first, second, true);
|
|
7
8
|
}
|
|
8
|
-
export {
|
|
9
|
+
export { groupBy };
|
package/dist/array/to-map.js
CHANGED
|
@@ -19,7 +19,8 @@ function getMapValues(array, first, second, arrays) {
|
|
|
19
19
|
function toMap(array, first, second) {
|
|
20
20
|
return getMapValues(array, first, second, false);
|
|
21
21
|
}
|
|
22
|
+
toMap.arrays = toMapArrays;
|
|
22
23
|
function toMapArrays(array, first, second) {
|
|
23
24
|
return getMapValues(array, first, second, true);
|
|
24
25
|
}
|
|
25
|
-
export { toMap
|
|
26
|
+
export { toMap };
|
package/dist/array/to-record.js
CHANGED
|
@@ -2,7 +2,8 @@ import { groupValues } from "../internal/array/group.js";
|
|
|
2
2
|
function toRecord(array, first, second) {
|
|
3
3
|
return groupValues(array, first, second, false);
|
|
4
4
|
}
|
|
5
|
+
toRecord.arrays = toRecordArrays;
|
|
5
6
|
function toRecordArrays(array, first, second) {
|
|
6
7
|
return groupValues(array, first, second, true);
|
|
7
8
|
}
|
|
8
|
-
export { toRecord
|
|
9
|
+
export { toRecord };
|
package/dist/atoms.full.js
CHANGED
|
@@ -205,6 +205,7 @@ function groupValues(array, key, value, arrays) {
|
|
|
205
205
|
function groupBy(array, first, second) {
|
|
206
206
|
return groupValues(array, first, second, false);
|
|
207
207
|
}
|
|
208
|
+
groupBy.arrays = groupArraysBy;
|
|
208
209
|
function groupArraysBy(array, first, second) {
|
|
209
210
|
return groupValues(array, first, second, true);
|
|
210
211
|
}
|
|
@@ -438,20 +439,28 @@ function compare(first, second) {
|
|
|
438
439
|
}
|
|
439
440
|
return 0;
|
|
440
441
|
}
|
|
442
|
+
compare.handlers = getCompareHandlers(compare, {
|
|
443
|
+
callback: (first, second, compareStrings) => {
|
|
444
|
+
if (compareStrings) return getString(first).localeCompare(getString(second));
|
|
445
|
+
},
|
|
446
|
+
method: "compare"
|
|
447
|
+
});
|
|
448
|
+
compare.register = registerComparator;
|
|
449
|
+
compare.unregister = unregisterComparator;
|
|
441
450
|
/**
|
|
442
451
|
* Register a custom comparison handler for a class
|
|
443
452
|
* @param constructor Class constructor
|
|
444
453
|
* @param handler Method name or comparison function _(defaults to `compare`)_
|
|
445
454
|
*/
|
|
446
455
|
function registerComparator(constructor, handler) {
|
|
447
|
-
|
|
456
|
+
compare.handlers.register(constructor, handler);
|
|
448
457
|
}
|
|
449
458
|
/**
|
|
450
459
|
* Unregister a custom comparison handler for a class
|
|
451
460
|
* @param constructor Class constructor
|
|
452
461
|
*/
|
|
453
462
|
function unregisterComparator(constructor) {
|
|
454
|
-
|
|
463
|
+
compare.handlers.unregister(constructor);
|
|
455
464
|
}
|
|
456
465
|
function compareNumbers(first, second) {
|
|
457
466
|
const firstNumber = Number(first);
|
|
@@ -466,7 +475,7 @@ function compareValue(first, second, compareStrings) {
|
|
|
466
475
|
const firstType = typeof first;
|
|
467
476
|
if (firstType === typeof second && firstType in comparators) return comparators[firstType](first, second);
|
|
468
477
|
if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
|
|
469
|
-
return
|
|
478
|
+
return compare.handlers.handle(first, second, compareStrings);
|
|
470
479
|
}
|
|
471
480
|
function getComparisonParts(value) {
|
|
472
481
|
if (Array.isArray(value)) return value;
|
|
@@ -478,12 +487,6 @@ const comparators = {
|
|
|
478
487
|
number: compareNumbers,
|
|
479
488
|
symbol: compareSymbols
|
|
480
489
|
};
|
|
481
|
-
const compareHandlers = getCompareHandlers(compare, {
|
|
482
|
-
callback: (first, second, compareStrings) => {
|
|
483
|
-
if (compareStrings) return getString(first).localeCompare(getString(second));
|
|
484
|
-
},
|
|
485
|
-
method: "compare"
|
|
486
|
-
});
|
|
487
490
|
function getCallback(value, key, forObject) {
|
|
488
491
|
if (key != null) return;
|
|
489
492
|
if (forObject && typeof value.value === "function") return value.value;
|
|
@@ -564,12 +567,14 @@ function getMapValues(array, first, second, arrays) {
|
|
|
564
567
|
function toMap(array, first, second) {
|
|
565
568
|
return getMapValues(array, first, second, false);
|
|
566
569
|
}
|
|
570
|
+
toMap.arrays = toMapArrays;
|
|
567
571
|
function toMapArrays(array, first, second) {
|
|
568
572
|
return getMapValues(array, first, second, true);
|
|
569
573
|
}
|
|
570
574
|
function toRecord(array, first, second) {
|
|
571
575
|
return groupValues(array, first, second, false);
|
|
572
576
|
}
|
|
577
|
+
toRecord.arrays = toRecordArrays;
|
|
573
578
|
function toRecordArrays(array, first, second) {
|
|
574
579
|
return groupValues(array, first, second, true);
|
|
575
580
|
}
|
|
@@ -887,6 +892,10 @@ function noop() {}
|
|
|
887
892
|
function equal(first, second, options) {
|
|
888
893
|
return equalValue(first, second, getEqualOptions(options));
|
|
889
894
|
}
|
|
895
|
+
equal.handlers = getCompareHandlers(equal, { callback: Object.is });
|
|
896
|
+
equal.initialize = initializeEqualizer;
|
|
897
|
+
equal.register = registerEqualizer;
|
|
898
|
+
equal.unregister = unregisterEqualizer;
|
|
890
899
|
function equalArray(first, second, options) {
|
|
891
900
|
const { length } = first;
|
|
892
901
|
if (length !== second.length) return false;
|
|
@@ -983,7 +992,7 @@ function equalValue(first, second, options) {
|
|
|
983
992
|
case Array.isArray(first) && Array.isArray(second): return equalArray(first, second, options);
|
|
984
993
|
case isPlainObject(first) && isPlainObject(second): return equalPlainObject(first, second, options);
|
|
985
994
|
case isTypedArray(first) && isTypedArray(second): return equalTypedArray(first, second);
|
|
986
|
-
default: return
|
|
995
|
+
default: return equal.handlers.handle(first, second, options);
|
|
987
996
|
}
|
|
988
997
|
}
|
|
989
998
|
/**
|
|
@@ -993,22 +1002,25 @@ function equalValue(first, second, options) {
|
|
|
993
1002
|
*/
|
|
994
1003
|
function initializeEqualizer(options) {
|
|
995
1004
|
const actual = getEqualOptions(options);
|
|
996
|
-
|
|
1005
|
+
const equalizer = (first, second) => equalValue(first, second, actual);
|
|
1006
|
+
equalizer.register = registerEqualizer;
|
|
1007
|
+
equalizer.unregister = unregisterEqualizer;
|
|
1008
|
+
return equalizer;
|
|
997
1009
|
}
|
|
998
1010
|
/**
|
|
999
1011
|
* Register a equality comparison function for a specific class
|
|
1000
1012
|
* @param constructor Class constructor
|
|
1001
1013
|
* @param fn Comparison function
|
|
1002
1014
|
*/
|
|
1003
|
-
function registerEqualizer(constructor,
|
|
1004
|
-
|
|
1015
|
+
function registerEqualizer(constructor, handler) {
|
|
1016
|
+
equal.handlers.register(constructor, handler);
|
|
1005
1017
|
}
|
|
1006
1018
|
/**
|
|
1007
1019
|
* Unregister a equality comparison handler for a specific class
|
|
1008
1020
|
* @param constructor Class constructor
|
|
1009
1021
|
*/
|
|
1010
1022
|
function unregisterEqualizer(constructor) {
|
|
1011
|
-
|
|
1023
|
+
equal.handlers.unregister(constructor);
|
|
1012
1024
|
}
|
|
1013
1025
|
function filterKey(key, options) {
|
|
1014
1026
|
if (typeof key !== "string") return true;
|
|
@@ -1042,7 +1054,6 @@ function getEqualOptions(input) {
|
|
|
1042
1054
|
options.relaxedNullish = input.relaxedNullish === true;
|
|
1043
1055
|
return options;
|
|
1044
1056
|
}
|
|
1045
|
-
const equalHandlers = getCompareHandlers(equal, { callback: Object.is });
|
|
1046
1057
|
const ARRAY_PEEK_PERCENTAGE = 10;
|
|
1047
1058
|
const ARRAY_THRESHOLD = 100;
|
|
1048
1059
|
function findKey(needle, haystack) {
|
|
@@ -1351,24 +1362,31 @@ function template(value, variables, options) {
|
|
|
1351
1362
|
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
1352
1363
|
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
1353
1364
|
}
|
|
1365
|
+
template.initialize = initializeTemplater;
|
|
1354
1366
|
const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
1355
1367
|
function clone(value) {
|
|
1356
1368
|
return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
|
|
1357
1369
|
}
|
|
1370
|
+
clone.handlers = getSelfHandlers(clone, {
|
|
1371
|
+
callback: tryStructuredClone,
|
|
1372
|
+
method: "clone"
|
|
1373
|
+
});
|
|
1374
|
+
clone.register = registerCloner;
|
|
1375
|
+
clone.unregister = unregisterCloner;
|
|
1358
1376
|
/**
|
|
1359
1377
|
* Register a clone handler for a specific class
|
|
1360
1378
|
* @param constructor Class constructor
|
|
1361
1379
|
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
1362
1380
|
*/
|
|
1363
1381
|
function registerCloner(constructor, handler) {
|
|
1364
|
-
|
|
1382
|
+
clone.handlers.register(constructor, handler);
|
|
1365
1383
|
}
|
|
1366
1384
|
/**
|
|
1367
1385
|
* Unregister a clone handler for a specific class
|
|
1368
1386
|
* @param constructor Class constructor
|
|
1369
1387
|
*/
|
|
1370
1388
|
function unregisterCloner(constructor) {
|
|
1371
|
-
|
|
1389
|
+
clone.handlers.unregister(constructor);
|
|
1372
1390
|
}
|
|
1373
1391
|
function cloneArrayBuffer(value, depth, references) {
|
|
1374
1392
|
if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
|
|
@@ -1448,7 +1466,7 @@ function cloneValue(value, depth, references) {
|
|
|
1448
1466
|
case value instanceof Node: return cloneNode(value, depth, references);
|
|
1449
1467
|
case isArrayOrPlainObject(value): return clonePlainObject(value, depth, references);
|
|
1450
1468
|
case isTypedArray(value): return cloneTypedArray(value, depth, references);
|
|
1451
|
-
default: return
|
|
1469
|
+
default: return clone.handlers.handle(value, depth, references);
|
|
1452
1470
|
}
|
|
1453
1471
|
}
|
|
1454
1472
|
function tryStructuredClone(value, depth, references) {
|
|
@@ -1462,10 +1480,6 @@ function tryStructuredClone(value, depth, references) {
|
|
|
1462
1480
|
return value;
|
|
1463
1481
|
}
|
|
1464
1482
|
}
|
|
1465
|
-
const cloneHandlers = getSelfHandlers(clone, {
|
|
1466
|
-
callback: tryStructuredClone,
|
|
1467
|
-
method: "clone"
|
|
1468
|
-
});
|
|
1469
1483
|
const MAX_CLONE_DEPTH = 100;
|
|
1470
1484
|
/**
|
|
1471
1485
|
* Find the differences between two values
|
|
@@ -1589,6 +1603,7 @@ function handleMerge(values, options) {
|
|
|
1589
1603
|
function merge(values, options) {
|
|
1590
1604
|
return handleMerge(values, getMergeOptions(options));
|
|
1591
1605
|
}
|
|
1606
|
+
merge.initialize = initializeMerger;
|
|
1592
1607
|
/**
|
|
1593
1608
|
* Create a merger with predefined options
|
|
1594
1609
|
* @param options Merging options
|
|
@@ -3326,4 +3341,4 @@ var SizedSet = class extends Set {
|
|
|
3326
3341
|
}
|
|
3327
3342
|
}
|
|
3328
3343
|
};
|
|
3329
|
-
export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, asyncResult, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue,
|
|
3344
|
+
export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, asyncResult, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, upperCase, words };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { find } from "./array/find.js";
|
|
|
4
4
|
import { flatten } from "./array/flatten.js";
|
|
5
5
|
import { isArrayOrPlainObject, isConstructor, isKey, isNumber, isPlainObject, isTypedArray } from "./internal/is.js";
|
|
6
6
|
import { getArray } from "./array/get.js";
|
|
7
|
-
import {
|
|
7
|
+
import { groupBy } from "./array/group-by.js";
|
|
8
8
|
import { indexOf } from "./array/index-of.js";
|
|
9
9
|
import { chunk } from "./internal/array/chunk.js";
|
|
10
10
|
import { insert } from "./array/insert.js";
|
|
@@ -12,11 +12,11 @@ import { push } from "./array/push.js";
|
|
|
12
12
|
import { max } from "./internal/math/aggregate.js";
|
|
13
13
|
import { compact } from "./internal/array/compact.js";
|
|
14
14
|
import { getString, ignoreKey, join, tryDecode, tryEncode, words } from "./internal/string.js";
|
|
15
|
-
import { compare
|
|
15
|
+
import { compare } from "./internal/value/compare.js";
|
|
16
16
|
import { sort } from "./array/sort.js";
|
|
17
17
|
import { splice } from "./array/splice.js";
|
|
18
|
-
import { toMap
|
|
19
|
-
import { toRecord
|
|
18
|
+
import { toMap } from "./array/to-map.js";
|
|
19
|
+
import { toRecord } from "./array/to-record.js";
|
|
20
20
|
import { toSet } from "./array/to-set.js";
|
|
21
21
|
import { unique } from "./array/unique.js";
|
|
22
22
|
import { noop } from "./internal/function/misc.js";
|
|
@@ -35,16 +35,16 @@ import { memoize } from "./function/memoize.js";
|
|
|
35
35
|
import { throttle } from "./function/throttle.js";
|
|
36
36
|
import { getRandomFloat, getRandomInteger } from "./internal/random.js";
|
|
37
37
|
import { shuffle } from "./internal/array/shuffle.js";
|
|
38
|
-
import { equal
|
|
38
|
+
import { equal } from "./internal/value/equal.js";
|
|
39
39
|
import { getValue } from "./internal/value/get.js";
|
|
40
40
|
import { setValue } from "./internal/value/set.js";
|
|
41
41
|
import { camelCase, capitalize, kebabCase, lowerCase, pascalCase, snakeCase, titleCase, upperCase } from "./string/case.js";
|
|
42
42
|
import { endsWith, includes, startsWith } from "./string/match.js";
|
|
43
43
|
import { getUuid, parse, trim, truncate } from "./string/misc.js";
|
|
44
|
-
import {
|
|
45
|
-
import { clone
|
|
44
|
+
import { template } from "./string/template.js";
|
|
45
|
+
import { clone } from "./value/clone.js";
|
|
46
46
|
import { diff } from "./value/diff.js";
|
|
47
|
-
import {
|
|
47
|
+
import { merge } from "./value/merge.js";
|
|
48
48
|
import { partial } from "./value/partial.js";
|
|
49
49
|
import { smush } from "./value/smush.js";
|
|
50
50
|
import { unsmush } from "./value/unsmush.js";
|
|
@@ -57,4 +57,4 @@ import { QueueError, queue } from "./queue.js";
|
|
|
57
57
|
import { getRandomBoolean, getRandomCharacters, getRandomColor, getRandomHex, getRandomItem, getRandomItems } from "./random.js";
|
|
58
58
|
import { asyncResult, error, isError, isOk, isResult, ok, result, unwrap } from "./result.js";
|
|
59
59
|
import { SizedSet } from "./sized/set.js";
|
|
60
|
-
export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, asyncResult, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue,
|
|
60
|
+
export { frame_rate_default as FRAME_RATE_MS, PromiseTimeoutError, QueueError, SizedMap, SizedSet, asyncResult, average, beacon, between, camelCase, capitalize, chunk, clamp, clone, compact, compare, count, debounce, delay, diff, endsWith, equal, error, exists, filter, find, flatten, fromQuery, getArray, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getString, getUuid, getValue, groupBy, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, includes, indexOf, insert, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isKey, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isTypedArray, join, kebabCase, logger, lowerCase, max, memoize, merge, min, noop, ok, parse, partial, pascalCase, promises, push, queue, result, rgbToHex, rgbToHsl, rgbToHsla, round, setValue, shuffle, smush, snakeCase, sort, splice, startsWith, sum, template, throttle, timed, titleCase, toMap, toQuery, toRecord, toSet, trim, truncate, tryDecode, tryEncode, unique, unsmush, unwrap, upperCase, words };
|
|
@@ -29,20 +29,28 @@ function compare(first, second) {
|
|
|
29
29
|
}
|
|
30
30
|
return 0;
|
|
31
31
|
}
|
|
32
|
+
compare.handlers = getCompareHandlers(compare, {
|
|
33
|
+
callback: (first, second, compareStrings) => {
|
|
34
|
+
if (compareStrings) return getString(first).localeCompare(getString(second));
|
|
35
|
+
},
|
|
36
|
+
method: "compare"
|
|
37
|
+
});
|
|
38
|
+
compare.register = registerComparator;
|
|
39
|
+
compare.unregister = unregisterComparator;
|
|
32
40
|
/**
|
|
33
41
|
* Register a custom comparison handler for a class
|
|
34
42
|
* @param constructor Class constructor
|
|
35
43
|
* @param handler Method name or comparison function _(defaults to `compare`)_
|
|
36
44
|
*/
|
|
37
45
|
function registerComparator(constructor, handler) {
|
|
38
|
-
|
|
46
|
+
compare.handlers.register(constructor, handler);
|
|
39
47
|
}
|
|
40
48
|
/**
|
|
41
49
|
* Unregister a custom comparison handler for a class
|
|
42
50
|
* @param constructor Class constructor
|
|
43
51
|
*/
|
|
44
52
|
function unregisterComparator(constructor) {
|
|
45
|
-
|
|
53
|
+
compare.handlers.unregister(constructor);
|
|
46
54
|
}
|
|
47
55
|
function compareNumbers(first, second) {
|
|
48
56
|
const firstNumber = Number(first);
|
|
@@ -57,7 +65,7 @@ function compareValue(first, second, compareStrings) {
|
|
|
57
65
|
const firstType = typeof first;
|
|
58
66
|
if (firstType === typeof second && firstType in comparators) return comparators[firstType](first, second);
|
|
59
67
|
if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
|
|
60
|
-
return
|
|
68
|
+
return compare.handlers.handle(first, second, compareStrings);
|
|
61
69
|
}
|
|
62
70
|
function getComparisonParts(value) {
|
|
63
71
|
if (Array.isArray(value)) return value;
|
|
@@ -69,10 +77,4 @@ var comparators = {
|
|
|
69
77
|
number: compareNumbers,
|
|
70
78
|
symbol: compareSymbols
|
|
71
79
|
};
|
|
72
|
-
|
|
73
|
-
callback: (first, second, compareStrings) => {
|
|
74
|
-
if (compareStrings) return getString(first).localeCompare(getString(second));
|
|
75
|
-
},
|
|
76
|
-
method: "compare"
|
|
77
|
-
});
|
|
78
|
-
export { compare, registerComparator, unregisterComparator };
|
|
80
|
+
export { compare };
|
|
@@ -4,6 +4,10 @@ import { getCompareHandlers } from "./handlers.js";
|
|
|
4
4
|
function equal(first, second, options) {
|
|
5
5
|
return equalValue(first, second, getEqualOptions(options));
|
|
6
6
|
}
|
|
7
|
+
equal.handlers = getCompareHandlers(equal, { callback: Object.is });
|
|
8
|
+
equal.initialize = initializeEqualizer;
|
|
9
|
+
equal.register = registerEqualizer;
|
|
10
|
+
equal.unregister = unregisterEqualizer;
|
|
7
11
|
function equalArray(first, second, options) {
|
|
8
12
|
const { length } = first;
|
|
9
13
|
if (length !== second.length) return false;
|
|
@@ -100,7 +104,7 @@ function equalValue(first, second, options) {
|
|
|
100
104
|
case Array.isArray(first) && Array.isArray(second): return equalArray(first, second, options);
|
|
101
105
|
case isPlainObject(first) && isPlainObject(second): return equalPlainObject(first, second, options);
|
|
102
106
|
case isTypedArray(first) && isTypedArray(second): return equalTypedArray(first, second);
|
|
103
|
-
default: return
|
|
107
|
+
default: return equal.handlers.handle(first, second, options);
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
/**
|
|
@@ -110,22 +114,25 @@ function equalValue(first, second, options) {
|
|
|
110
114
|
*/
|
|
111
115
|
function initializeEqualizer(options) {
|
|
112
116
|
const actual = getEqualOptions(options);
|
|
113
|
-
|
|
117
|
+
const equalizer = (first, second) => equalValue(first, second, actual);
|
|
118
|
+
equalizer.register = registerEqualizer;
|
|
119
|
+
equalizer.unregister = unregisterEqualizer;
|
|
120
|
+
return equalizer;
|
|
114
121
|
}
|
|
115
122
|
/**
|
|
116
123
|
* Register a equality comparison function for a specific class
|
|
117
124
|
* @param constructor Class constructor
|
|
118
125
|
* @param fn Comparison function
|
|
119
126
|
*/
|
|
120
|
-
function registerEqualizer(constructor,
|
|
121
|
-
|
|
127
|
+
function registerEqualizer(constructor, handler) {
|
|
128
|
+
equal.handlers.register(constructor, handler);
|
|
122
129
|
}
|
|
123
130
|
/**
|
|
124
131
|
* Unregister a equality comparison handler for a specific class
|
|
125
132
|
* @param constructor Class constructor
|
|
126
133
|
*/
|
|
127
134
|
function unregisterEqualizer(constructor) {
|
|
128
|
-
|
|
135
|
+
equal.handlers.unregister(constructor);
|
|
129
136
|
}
|
|
130
137
|
function filterKey(key, options) {
|
|
131
138
|
if (typeof key !== "string") return true;
|
|
@@ -159,7 +166,6 @@ function getEqualOptions(input) {
|
|
|
159
166
|
options.relaxedNullish = input.relaxedNullish === true;
|
|
160
167
|
return options;
|
|
161
168
|
}
|
|
162
|
-
var equalHandlers = getCompareHandlers(equal, { callback: Object.is });
|
|
163
169
|
var ARRAY_PEEK_PERCENTAGE = 10;
|
|
164
170
|
var ARRAY_THRESHOLD = 100;
|
|
165
|
-
export { equal
|
|
171
|
+
export { equal };
|
package/dist/string/template.js
CHANGED
|
@@ -42,5 +42,6 @@ function template(value, variables, options) {
|
|
|
42
42
|
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
43
43
|
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
44
44
|
}
|
|
45
|
+
template.initialize = initializeTemplater;
|
|
45
46
|
var EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
46
|
-
export {
|
|
47
|
+
export { template };
|
package/dist/value/clone.js
CHANGED
|
@@ -3,20 +3,26 @@ import { getSelfHandlers } from "../internal/value/handlers.js";
|
|
|
3
3
|
function clone(value) {
|
|
4
4
|
return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
|
|
5
5
|
}
|
|
6
|
+
clone.handlers = getSelfHandlers(clone, {
|
|
7
|
+
callback: tryStructuredClone,
|
|
8
|
+
method: "clone"
|
|
9
|
+
});
|
|
10
|
+
clone.register = registerCloner;
|
|
11
|
+
clone.unregister = unregisterCloner;
|
|
6
12
|
/**
|
|
7
13
|
* Register a clone handler for a specific class
|
|
8
14
|
* @param constructor Class constructor
|
|
9
15
|
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
10
16
|
*/
|
|
11
17
|
function registerCloner(constructor, handler) {
|
|
12
|
-
|
|
18
|
+
clone.handlers.register(constructor, handler);
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* Unregister a clone handler for a specific class
|
|
16
22
|
* @param constructor Class constructor
|
|
17
23
|
*/
|
|
18
24
|
function unregisterCloner(constructor) {
|
|
19
|
-
|
|
25
|
+
clone.handlers.unregister(constructor);
|
|
20
26
|
}
|
|
21
27
|
function cloneArrayBuffer(value, depth, references) {
|
|
22
28
|
if (typeof depth === "number" && depth >= MAX_CLONE_DEPTH) return value;
|
|
@@ -96,7 +102,7 @@ function cloneValue(value, depth, references) {
|
|
|
96
102
|
case value instanceof Node: return cloneNode(value, depth, references);
|
|
97
103
|
case isArrayOrPlainObject(value): return clonePlainObject(value, depth, references);
|
|
98
104
|
case isTypedArray(value): return cloneTypedArray(value, depth, references);
|
|
99
|
-
default: return
|
|
105
|
+
default: return clone.handlers.handle(value, depth, references);
|
|
100
106
|
}
|
|
101
107
|
}
|
|
102
108
|
function tryStructuredClone(value, depth, references) {
|
|
@@ -110,9 +116,5 @@ function tryStructuredClone(value, depth, references) {
|
|
|
110
116
|
return value;
|
|
111
117
|
}
|
|
112
118
|
}
|
|
113
|
-
var cloneHandlers = getSelfHandlers(clone, {
|
|
114
|
-
callback: tryStructuredClone,
|
|
115
|
-
method: "clone"
|
|
116
|
-
});
|
|
117
119
|
var MAX_CLONE_DEPTH = 100;
|
|
118
|
-
export { clone
|
|
120
|
+
export { clone };
|
package/dist/value/merge.js
CHANGED
|
@@ -26,6 +26,7 @@ function handleMerge(values, options) {
|
|
|
26
26
|
function merge(values, options) {
|
|
27
27
|
return handleMerge(values, getMergeOptions(options));
|
|
28
28
|
}
|
|
29
|
+
merge.initialize = initializeMerger;
|
|
29
30
|
/**
|
|
30
31
|
* Create a merger with predefined options
|
|
31
32
|
* @param options Merging options
|
|
@@ -59,4 +60,4 @@ function mergeValues(values, options, validate, prefix) {
|
|
|
59
60
|
const actual = validate ? values.filter(isArrayOrPlainObject) : values;
|
|
60
61
|
return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
|
|
61
62
|
}
|
|
62
|
-
export {
|
|
63
|
+
export { merge };
|
package/dist/value/misc.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { initializeMerger, merge } from "./merge.js";
|
|
2
1
|
import { partial } from "./partial.js";
|
|
3
2
|
import { smush } from "./smush.js";
|
|
4
3
|
import { unsmush } from "./unsmush.js";
|
|
5
|
-
export {
|
|
4
|
+
export { partial, smush, unsmush };
|
package/package.json
CHANGED
|
@@ -201,6 +201,10 @@
|
|
|
201
201
|
"types": "./types/value/get-set.d.ts",
|
|
202
202
|
"default": "./dist/value/get-set.js"
|
|
203
203
|
},
|
|
204
|
+
"./value/merge": {
|
|
205
|
+
"types": "./types/value/merge.d.ts",
|
|
206
|
+
"default": "./dist/value/merge.js"
|
|
207
|
+
},
|
|
204
208
|
"./value/misc": {
|
|
205
209
|
"types": "./types/value/misc.d.ts",
|
|
206
210
|
"default": "./dist/value/misc.js"
|
|
@@ -232,5 +236,5 @@
|
|
|
232
236
|
},
|
|
233
237
|
"type": "module",
|
|
234
238
|
"types": "./types/index.d.ts",
|
|
235
|
-
"version": "0.
|
|
239
|
+
"version": "0.141.0"
|
|
236
240
|
}
|
package/src/array/group-by.ts
CHANGED
|
@@ -116,6 +116,8 @@ export function groupBy(array: unknown[], first?: unknown, second?: unknown): un
|
|
|
116
116
|
return groupValues(array, first, second, false);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
groupBy.arrays = groupArraysBy;
|
|
120
|
+
|
|
119
121
|
/**
|
|
120
122
|
* Create a record from an array of items using a specific key and value, grouping values into arrays
|
|
121
123
|
* @param array Array to group
|
|
@@ -123,7 +125,7 @@ export function groupBy(array: unknown[], first?: unknown, second?: unknown): un
|
|
|
123
125
|
* @param value Callback to get an item's value
|
|
124
126
|
* @returns Record of keyed values
|
|
125
127
|
*/
|
|
126
|
-
|
|
128
|
+
function groupArraysBy<
|
|
127
129
|
Item,
|
|
128
130
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
129
131
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -140,7 +142,7 @@ export function groupArraysBy<
|
|
|
140
142
|
* @param value Key to use for value
|
|
141
143
|
* @returns Record of keyed values
|
|
142
144
|
*/
|
|
143
|
-
|
|
145
|
+
function groupArraysBy<
|
|
144
146
|
Item extends PlainObject,
|
|
145
147
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
146
148
|
ItemValue extends keyof Item,
|
|
@@ -157,7 +159,7 @@ export function groupArraysBy<
|
|
|
157
159
|
* @param value Callback to get an item's value
|
|
158
160
|
* @returns Record of keyed values
|
|
159
161
|
*/
|
|
160
|
-
|
|
162
|
+
function groupArraysBy<
|
|
161
163
|
Item extends PlainObject,
|
|
162
164
|
ItemKey extends keyof Item,
|
|
163
165
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -174,7 +176,7 @@ export function groupArraysBy<
|
|
|
174
176
|
* @param value Key to use for value
|
|
175
177
|
* @returns Record of keyed values
|
|
176
178
|
*/
|
|
177
|
-
|
|
179
|
+
function groupArraysBy<
|
|
178
180
|
Item extends PlainObject,
|
|
179
181
|
ItemKey extends keyof Item,
|
|
180
182
|
ItemValue extends keyof Item,
|
|
@@ -190,7 +192,7 @@ export function groupArraysBy<
|
|
|
190
192
|
* @param callback Callback to get an item's grouping key
|
|
191
193
|
* @returns Record of keyed items
|
|
192
194
|
*/
|
|
193
|
-
|
|
195
|
+
function groupArraysBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
194
196
|
array: Item[],
|
|
195
197
|
callback: Callback,
|
|
196
198
|
): Record<ReturnType<Callback>, Item[]>;
|
|
@@ -201,12 +203,12 @@ export function groupArraysBy<Item, Callback extends (item: Item, index: number,
|
|
|
201
203
|
* @param key Key to use for grouping
|
|
202
204
|
* @returns Record of keyed items
|
|
203
205
|
*/
|
|
204
|
-
|
|
206
|
+
function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
205
207
|
array: Item[],
|
|
206
208
|
key: ItemKey,
|
|
207
209
|
): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
|
|
208
210
|
|
|
209
|
-
|
|
211
|
+
function groupArraysBy(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
210
212
|
return groupValues(array, first, second, true);
|
|
211
213
|
}
|
|
212
214
|
|
package/src/array/to-map.ts
CHANGED
|
@@ -140,6 +140,8 @@ export function toMap(array: unknown[], first?: unknown, second?: unknown): unkn
|
|
|
140
140
|
return getMapValues(array, first, second, false);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
toMap.arrays = toMapArrays;
|
|
144
|
+
|
|
143
145
|
/**
|
|
144
146
|
* Create a Map from an array of items using callbacks, grouping values into arrays
|
|
145
147
|
* @param array Array to convert
|
|
@@ -147,7 +149,7 @@ export function toMap(array: unknown[], first?: unknown, second?: unknown): unkn
|
|
|
147
149
|
* @param value Callback to get an item's value
|
|
148
150
|
* @returns Map of keyed arrays of values
|
|
149
151
|
*/
|
|
150
|
-
|
|
152
|
+
function toMapArrays<
|
|
151
153
|
Item,
|
|
152
154
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
153
155
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -164,7 +166,7 @@ export function toMapArrays<
|
|
|
164
166
|
* @param value Key to use for value
|
|
165
167
|
* @returns Map of keyed arrays of values
|
|
166
168
|
*/
|
|
167
|
-
|
|
169
|
+
function toMapArrays<
|
|
168
170
|
Item extends PlainObject,
|
|
169
171
|
KeyCallback extends (item: Item, index: number, array: Item[]) => Key,
|
|
170
172
|
ItemValue extends keyof Item,
|
|
@@ -181,7 +183,7 @@ export function toMapArrays<
|
|
|
181
183
|
* @param value Callback to get an item's value
|
|
182
184
|
* @returns Map of keyed arrays of values
|
|
183
185
|
*/
|
|
184
|
-
|
|
186
|
+
function toMapArrays<
|
|
185
187
|
Item extends PlainObject,
|
|
186
188
|
ItemKey extends keyof Item,
|
|
187
189
|
ValueCallback extends (item: Item, index: number, array: Item[]) => unknown,
|
|
@@ -198,7 +200,7 @@ export function toMapArrays<
|
|
|
198
200
|
* @param value Key to use for value
|
|
199
201
|
* @returns Map of keyed arrays of values
|
|
200
202
|
*/
|
|
201
|
-
|
|
203
|
+
function toMapArrays<
|
|
202
204
|
Item extends PlainObject,
|
|
203
205
|
ItemKey extends keyof Item,
|
|
204
206
|
ItemValue extends keyof Item,
|
|
@@ -210,7 +212,7 @@ export function toMapArrays<
|
|
|
210
212
|
* @param callback Callback to get an item's grouping key
|
|
211
213
|
* @returns Map of keyed arrays of items
|
|
212
214
|
*/
|
|
213
|
-
|
|
215
|
+
function toMapArrays<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(
|
|
214
216
|
array: Item[],
|
|
215
217
|
callback: Callback,
|
|
216
218
|
): Map<ReturnType<Callback>, Item[]>;
|
|
@@ -221,12 +223,12 @@ export function toMapArrays<Item, Callback extends (item: Item, index: number, a
|
|
|
221
223
|
* @param key Key to use for grouping
|
|
222
224
|
* @returns Map of keyed arrays of items
|
|
223
225
|
*/
|
|
224
|
-
|
|
226
|
+
function toMapArrays<Item extends PlainObject, ItemKey extends keyof Item>(
|
|
225
227
|
array: Item[],
|
|
226
228
|
key: ItemKey,
|
|
227
229
|
): Map<Item[ItemKey], Item[]>;
|
|
228
230
|
|
|
229
|
-
|
|
231
|
+
function toMapArrays(array: unknown[], first?: unknown, second?: unknown): unknown {
|
|
230
232
|
return getMapValues(array, first, second, true);
|
|
231
233
|
}
|
|
232
234
|
|