@oscarpalmer/atoms 0.196.1 → 0.197.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/filter.mjs +1 -0
- package/dist/array/find.mjs +2 -1
- package/dist/array/first.mjs +2 -1
- package/dist/array/group-by.mjs +2 -1
- package/dist/array/last.mjs +2 -1
- package/dist/array/move.mjs +6 -2
- package/dist/array/sort.mjs +8 -3
- package/dist/array/swap.mjs +2 -1
- package/dist/array/to-map.mjs +2 -1
- package/dist/array/to-record.mjs +2 -1
- package/dist/index.d.mts +21 -6
- package/dist/index.mjs +185 -100
- package/dist/internal/array/callbacks.mjs +1 -0
- package/dist/internal/array/index-of.mjs +2 -1
- package/dist/internal/function/assert.mjs +12 -5
- package/dist/internal/math/aggregate.d.mts +2 -2
- package/dist/internal/sized/map.mjs +3 -2
- package/dist/internal/value/compare.d.mts +1 -1
- package/dist/internal/value/compare.mjs +12 -8
- package/dist/internal/value/handlers.d.mts +1 -1
- package/dist/internal/value/has.mjs +2 -1
- package/dist/promise/index.mjs +2 -1
- package/dist/queue.mjs +2 -1
- package/dist/sized/set.mjs +5 -6
- package/dist/string/fuzzy.mjs +2 -1
- package/dist/string/normalize.mjs +2 -1
- package/dist/string/template.mjs +2 -1
- package/dist/value/clone.d.mts +18 -3
- package/dist/value/clone.mjs +94 -54
- package/dist/value/collection.mjs +3 -1
- package/dist/value/freeze.mjs +6 -2
- package/dist/value/merge.mjs +4 -2
- package/dist/value/transform.mjs +2 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ function getArrayCallback(value) {
|
|
|
4
4
|
case "function": return value;
|
|
5
5
|
case "number":
|
|
6
6
|
case "string": return typeof value === "string" && value.includes(".") ? void 0 : (obj) => obj[value];
|
|
7
|
+
default: return;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
function getArrayCallbacks(bool, key, value) {
|
|
@@ -101,15 +102,17 @@ function filter(array, ...parameters) {
|
|
|
101
102
|
return findValues("all", array, parameters).matched;
|
|
102
103
|
}
|
|
103
104
|
filter.remove = exclude;
|
|
105
|
+
Object.defineProperty(filter, "remove", { value: exclude });
|
|
104
106
|
//#endregion
|
|
105
107
|
//#region src/array/first.ts
|
|
106
108
|
function first(array, ...parameters) {
|
|
107
109
|
return findAbsoluteValueOrDefault(array, parameters, void 0, false, false);
|
|
108
110
|
}
|
|
109
|
-
first.default = firstOrDefault;
|
|
110
111
|
function firstOrDefault(array, defaultValue, ...parameters) {
|
|
111
112
|
return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, false);
|
|
112
113
|
}
|
|
114
|
+
first.default = firstOrDefault;
|
|
115
|
+
Object.defineProperty(first, "default", { value: firstOrDefault });
|
|
113
116
|
//#endregion
|
|
114
117
|
//#region src/internal/array/group.ts
|
|
115
118
|
function groupValues(array, key, value, arrays) {
|
|
@@ -134,10 +137,11 @@ function groupValues(array, key, value, arrays) {
|
|
|
134
137
|
function groupBy(array, first, second) {
|
|
135
138
|
return groupValues(array, first, second, false);
|
|
136
139
|
}
|
|
137
|
-
groupBy.arrays = groupArraysBy;
|
|
138
140
|
function groupArraysBy(array, first, second) {
|
|
139
141
|
return groupValues(array, first, second, true);
|
|
140
142
|
}
|
|
143
|
+
groupBy.arrays = groupArraysBy;
|
|
144
|
+
Object.defineProperty(groupBy, "arrays", { value: groupArraysBy });
|
|
141
145
|
//#endregion
|
|
142
146
|
//#region src/internal/array/chunk.ts
|
|
143
147
|
/**
|
|
@@ -378,10 +382,11 @@ function getArray(value, indiced) {
|
|
|
378
382
|
function indexOf(array, ...parameters) {
|
|
379
383
|
return findValue(FIND_VALUE_INDEX, array, parameters, false);
|
|
380
384
|
}
|
|
381
|
-
indexOf.last = lastIndexOf;
|
|
382
385
|
function lastIndexOf(array, ...parameters) {
|
|
383
386
|
return findValue(FIND_VALUE_INDEX, array, parameters, true);
|
|
384
387
|
}
|
|
388
|
+
indexOf.last = lastIndexOf;
|
|
389
|
+
Object.defineProperty(indexOf, "last", { value: lastIndexOf });
|
|
385
390
|
//#endregion
|
|
386
391
|
//#region src/internal/array/match.ts
|
|
387
392
|
function endsWithArray(haystack, needle, key) {
|
|
@@ -532,10 +537,11 @@ function exists(array, ...parameters) {
|
|
|
532
537
|
function find(array, ...parameters) {
|
|
533
538
|
return findValue(FIND_VALUE_ITEM, array, parameters, false);
|
|
534
539
|
}
|
|
535
|
-
find.last = findLast;
|
|
536
540
|
function findLast(array, ...parameters) {
|
|
537
541
|
return findValue(FIND_VALUE_ITEM, array, parameters, true);
|
|
538
542
|
}
|
|
543
|
+
find.last = findLast;
|
|
544
|
+
Object.defineProperty(find, "last", { value: findLast });
|
|
539
545
|
//#endregion
|
|
540
546
|
//#region src/array/flatten.ts
|
|
541
547
|
/**
|
|
@@ -782,10 +788,11 @@ function update(array, values, key) {
|
|
|
782
788
|
function last(array, ...parameters) {
|
|
783
789
|
return findAbsoluteValueOrDefault(array, parameters, void 0, false, true);
|
|
784
790
|
}
|
|
785
|
-
last.default = lastOrDefault;
|
|
786
791
|
function lastOrDefault(array, defaultValue, ...parameters) {
|
|
787
792
|
return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, true);
|
|
788
793
|
}
|
|
794
|
+
last.default = lastOrDefault;
|
|
795
|
+
Object.defineProperty(last, "default", { value: lastOrDefault });
|
|
789
796
|
//#endregion
|
|
790
797
|
//#region src/internal/array/overlap.ts
|
|
791
798
|
function arraysOverlap(first, second) {
|
|
@@ -830,8 +837,6 @@ function move(array, from, to, key) {
|
|
|
830
837
|
else array.splice(next, 0, ...firstArray);
|
|
831
838
|
return array;
|
|
832
839
|
}
|
|
833
|
-
move.indices = moveIndices;
|
|
834
|
-
move.toIndex = moveToIndex;
|
|
835
840
|
/**
|
|
836
841
|
* Move an item from one index to another within an array
|
|
837
842
|
*
|
|
@@ -879,6 +884,12 @@ function moveToIndex(array, value, index, key) {
|
|
|
879
884
|
else array.splice(next, 0, ...values);
|
|
880
885
|
return array;
|
|
881
886
|
}
|
|
887
|
+
move.indices = moveIndices;
|
|
888
|
+
move.toIndex = moveToIndex;
|
|
889
|
+
Object.defineProperties(move, {
|
|
890
|
+
indices: { value: moveIndices },
|
|
891
|
+
toIndex: { value: moveToIndex }
|
|
892
|
+
});
|
|
882
893
|
//#endregion
|
|
883
894
|
//#region src/internal/math/aggregate.ts
|
|
884
895
|
function aggregate(type, array, key, first) {
|
|
@@ -1117,14 +1128,6 @@ function compare(first, second) {
|
|
|
1117
1128
|
}
|
|
1118
1129
|
return 0;
|
|
1119
1130
|
}
|
|
1120
|
-
compare.handlers = getCompareHandlers(compare, {
|
|
1121
|
-
callback: (first, second, compareStrings) => {
|
|
1122
|
-
if (compareStrings) return getString(first).localeCompare(getString(second));
|
|
1123
|
-
},
|
|
1124
|
-
method: COMPARE_NAME
|
|
1125
|
-
});
|
|
1126
|
-
compare.deregister = deregisterComparator;
|
|
1127
|
-
compare.register = registerComparator;
|
|
1128
1131
|
function compareNumbers(first, second) {
|
|
1129
1132
|
if (Object.is(first, second)) return 0;
|
|
1130
1133
|
if (Number.isNaN(first)) return -1;
|
|
@@ -1171,6 +1174,18 @@ const comparators = {
|
|
|
1171
1174
|
number: compareNumbers,
|
|
1172
1175
|
symbol: compareSymbols
|
|
1173
1176
|
};
|
|
1177
|
+
const compareHandlers = getCompareHandlers(compare, {
|
|
1178
|
+
callback: (first, second, compareStrings) => compareStrings ? getString(first).localeCompare(getString(second)) : void 0,
|
|
1179
|
+
method: COMPARE_NAME
|
|
1180
|
+
});
|
|
1181
|
+
compare.deregister = deregisterComparator;
|
|
1182
|
+
compare.handlers = compareHandlers;
|
|
1183
|
+
compare.register = registerComparator;
|
|
1184
|
+
Object.defineProperties(compare, {
|
|
1185
|
+
deregister: { value: deregisterComparator },
|
|
1186
|
+
handlers: { value: compareHandlers },
|
|
1187
|
+
register: { value: registerComparator }
|
|
1188
|
+
});
|
|
1174
1189
|
//#endregion
|
|
1175
1190
|
//#region src/array/sort.ts
|
|
1176
1191
|
function getComparisonSorter(callback, modifier) {
|
|
@@ -1298,9 +1313,6 @@ function sortArray(array, sorters) {
|
|
|
1298
1313
|
const { length } = sorters;
|
|
1299
1314
|
return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
|
|
1300
1315
|
}
|
|
1301
|
-
sort.getIndex = getSortedIndex;
|
|
1302
|
-
sort.initialize = initializeSorter;
|
|
1303
|
-
sort.is = isSorted;
|
|
1304
1316
|
const SORT_PEEK_PERCENTAGE = 10;
|
|
1305
1317
|
const SORT_THRESHOLD = 100;
|
|
1306
1318
|
const SORT_DIRECTION_ASCENDING = "ascending";
|
|
@@ -1309,6 +1321,14 @@ const modifiers = {
|
|
|
1309
1321
|
[SORT_DIRECTION_ASCENDING]: 1,
|
|
1310
1322
|
[SORT_DIRECTION_DESCENDING]: -1
|
|
1311
1323
|
};
|
|
1324
|
+
sort.getIndex = getSortedIndex;
|
|
1325
|
+
sort.initialize = initializeSorter;
|
|
1326
|
+
sort.is = isSorted;
|
|
1327
|
+
Object.defineProperties(sort, {
|
|
1328
|
+
getIndex: { value: getSortedIndex },
|
|
1329
|
+
initialize: { value: initializeSorter },
|
|
1330
|
+
is: { value: isSorted }
|
|
1331
|
+
});
|
|
1312
1332
|
//#endregion
|
|
1313
1333
|
//#region src/array/swap.ts
|
|
1314
1334
|
function swap(array, first, second, third) {
|
|
@@ -1317,7 +1337,6 @@ function swap(array, first, second, third) {
|
|
|
1317
1337
|
if (Array.isArray(first) && Array.isArray(second)) return swapArrays(array, first, second, third);
|
|
1318
1338
|
return swapValues(array, first, second, third);
|
|
1319
1339
|
}
|
|
1320
|
-
swap.indices = swapIndices;
|
|
1321
1340
|
function swapArrays(array, from, to, key) {
|
|
1322
1341
|
if (from.length === 0 || to.length === 0) return array;
|
|
1323
1342
|
if (from.length === 1 && to.length === 1) return swapValues(array, from[0], to[0], key);
|
|
@@ -1366,6 +1385,8 @@ function swapValues(array, from, to, key) {
|
|
|
1366
1385
|
if (first === second || first === -1 || second === -1) return array;
|
|
1367
1386
|
return swapIndices(array, first, second);
|
|
1368
1387
|
}
|
|
1388
|
+
swap.indices = swapIndices;
|
|
1389
|
+
Object.defineProperty(swap, "indices", { value: swapIndices });
|
|
1369
1390
|
//#endregion
|
|
1370
1391
|
//#region src/array/to-map.ts
|
|
1371
1392
|
function getMapValues(array, first, second, arrays) {
|
|
@@ -1388,19 +1409,21 @@ function getMapValues(array, first, second, arrays) {
|
|
|
1388
1409
|
function toMap(array, first, second) {
|
|
1389
1410
|
return getMapValues(array, first, second, false);
|
|
1390
1411
|
}
|
|
1391
|
-
toMap.arrays = toMapArrays;
|
|
1392
1412
|
function toMapArrays(array, first, second) {
|
|
1393
1413
|
return getMapValues(array, first, second, true);
|
|
1394
1414
|
}
|
|
1415
|
+
toMap.arrays = toMapArrays;
|
|
1416
|
+
Object.defineProperty(toMap, "arrays", { value: toMapArrays });
|
|
1395
1417
|
//#endregion
|
|
1396
1418
|
//#region src/array/to-record.ts
|
|
1397
1419
|
function toRecord(array, first, second) {
|
|
1398
1420
|
return groupValues(array, first, second, false);
|
|
1399
1421
|
}
|
|
1400
|
-
toRecord.arrays = toRecordArrays;
|
|
1401
1422
|
function toRecordArrays(array, first, second) {
|
|
1402
1423
|
return groupValues(array, first, second, true);
|
|
1403
1424
|
}
|
|
1425
|
+
toRecord.arrays = toRecordArrays;
|
|
1426
|
+
Object.defineProperty(toRecord, "arrays", { value: toRecordArrays });
|
|
1404
1427
|
//#endregion
|
|
1405
1428
|
//#region src/internal/function/misc.ts
|
|
1406
1429
|
/**
|
|
@@ -1651,10 +1674,11 @@ const MISC_NESTED_MESSAGE_UNSAFE = "Access to this property is not allowed";
|
|
|
1651
1674
|
function hasValue(data, path, ignoreCase) {
|
|
1652
1675
|
return getNestedValue(data, path, ignoreCase === true).ok;
|
|
1653
1676
|
}
|
|
1654
|
-
hasValue.get = hasValueResult;
|
|
1655
1677
|
function hasValueResult(data, path, ignoreCase) {
|
|
1656
1678
|
return getNestedValue(data, path, ignoreCase === true);
|
|
1657
1679
|
}
|
|
1680
|
+
hasValue.get = hasValueResult;
|
|
1681
|
+
Object.defineProperty(hasValue, "get", { value: hasValueResult });
|
|
1658
1682
|
//#endregion
|
|
1659
1683
|
//#region src/internal/function/assert.ts
|
|
1660
1684
|
/**
|
|
@@ -1667,11 +1691,6 @@ function hasValueResult(data, path, ignoreCase) {
|
|
|
1667
1691
|
function assert(condition, message, error) {
|
|
1668
1692
|
if (!condition()) throw new (error ?? Error)(message);
|
|
1669
1693
|
}
|
|
1670
|
-
assert.condition = assertCondition;
|
|
1671
|
-
assert.defined = assertDefined;
|
|
1672
|
-
assert.instanceOf = assertInstanceOf;
|
|
1673
|
-
assert.is = assertIs;
|
|
1674
|
-
assert.property = assertProperty;
|
|
1675
1694
|
/**
|
|
1676
1695
|
* Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not
|
|
1677
1696
|
*
|
|
@@ -1749,6 +1768,18 @@ function assertProperty(path, condition, message, error) {
|
|
|
1749
1768
|
};
|
|
1750
1769
|
}
|
|
1751
1770
|
const ASSERT_MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
1771
|
+
assert.condition = assertCondition;
|
|
1772
|
+
assert.defined = assertDefined;
|
|
1773
|
+
assert.instanceOf = assertInstanceOf;
|
|
1774
|
+
assert.is = assertIs;
|
|
1775
|
+
assert.property = assertProperty;
|
|
1776
|
+
Object.defineProperties(assert, {
|
|
1777
|
+
condition: { value: assertCondition },
|
|
1778
|
+
defined: { value: assertDefined },
|
|
1779
|
+
instanceOf: { value: assertInstanceOf },
|
|
1780
|
+
is: { value: assertIs },
|
|
1781
|
+
property: { value: assertProperty }
|
|
1782
|
+
});
|
|
1752
1783
|
//#endregion
|
|
1753
1784
|
//#region src/function/once.ts
|
|
1754
1785
|
/**
|
|
@@ -2130,11 +2161,12 @@ var SizedMap = class extends Map {
|
|
|
2130
2161
|
* @inheritdoc
|
|
2131
2162
|
*/
|
|
2132
2163
|
get(key) {
|
|
2164
|
+
let value;
|
|
2133
2165
|
if (super.has(key)) {
|
|
2134
|
-
|
|
2166
|
+
value = super.get(key);
|
|
2135
2167
|
this.#setValue(key, value, true);
|
|
2136
|
-
return value;
|
|
2137
2168
|
}
|
|
2169
|
+
return value;
|
|
2138
2170
|
}
|
|
2139
2171
|
/**
|
|
2140
2172
|
* @inheritdoc
|
|
@@ -2825,10 +2857,11 @@ async function promises(items, options) {
|
|
|
2825
2857
|
}));
|
|
2826
2858
|
});
|
|
2827
2859
|
}
|
|
2828
|
-
promises.result = resultPromises;
|
|
2829
2860
|
async function resultPromises(items, signal) {
|
|
2830
2861
|
return promises(items, signal).then(getResultsFromPromises);
|
|
2831
2862
|
}
|
|
2863
|
+
promises.result = resultPromises;
|
|
2864
|
+
Object.defineProperty(promises, "result", { value: resultPromises });
|
|
2832
2865
|
//#endregion
|
|
2833
2866
|
//#region src/result/index.ts
|
|
2834
2867
|
async function asyncAttempt(value, err) {
|
|
@@ -3021,7 +3054,6 @@ function fuzzy(items, configuration) {
|
|
|
3021
3054
|
});
|
|
3022
3055
|
return Object.freeze(instance);
|
|
3023
3056
|
}
|
|
3024
|
-
fuzzy.match = fuzzyMatch;
|
|
3025
3057
|
/**
|
|
3026
3058
|
* Does the needle match the haystack in a fuzzy way?
|
|
3027
3059
|
*
|
|
@@ -3128,6 +3160,8 @@ const FUZZY_LENGTH_DIVISOR = 3;
|
|
|
3128
3160
|
const FUZZY_MESSAGE_ARRAY = "Fuzzy requires an array of items";
|
|
3129
3161
|
const FUZZY_MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
|
|
3130
3162
|
const FUZZY_PROXIMITY_THRESHOLD = 5;
|
|
3163
|
+
fuzzy.match = fuzzyMatch;
|
|
3164
|
+
Object.defineProperty(fuzzy, "match", { value: fuzzyMatch });
|
|
3131
3165
|
//#endregion
|
|
3132
3166
|
//#region src/string/index.ts
|
|
3133
3167
|
function dedent(value, ...values) {
|
|
@@ -3273,7 +3307,6 @@ function initializeNormalizer(options) {
|
|
|
3273
3307
|
function normalize(value, options) {
|
|
3274
3308
|
return normalizeString(value, getNormalizeOptions(options));
|
|
3275
3309
|
}
|
|
3276
|
-
normalize.initialize = initializeNormalizer;
|
|
3277
3310
|
function normalizeString(value, options) {
|
|
3278
3311
|
if (typeof value !== "string") return "";
|
|
3279
3312
|
let result = value;
|
|
@@ -3325,6 +3358,8 @@ const NORMALIZE_SPECIAL_REPLACEMENT = "";
|
|
|
3325
3358
|
const NORMALIZE_WHITESPACE_PATTERN = /\s+/g;
|
|
3326
3359
|
const NORMALIZE_WHITESPACE_REPLACEMENT = " ";
|
|
3327
3360
|
let deburrMemoizer;
|
|
3361
|
+
normalize.initialize = initializeNormalizer;
|
|
3362
|
+
Object.defineProperty(normalize, "initialize", { value: initializeNormalizer });
|
|
3328
3363
|
//#endregion
|
|
3329
3364
|
//#region src/string/template.ts
|
|
3330
3365
|
function getRenderer(strings, values) {
|
|
@@ -3370,13 +3405,23 @@ function template(value, ...parameters) {
|
|
|
3370
3405
|
const { ignoreCase, pattern } = getTemplateOptions(parameters[1]);
|
|
3371
3406
|
return handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
3372
3407
|
}
|
|
3373
|
-
template.initialize = initializeTemplater;
|
|
3374
3408
|
const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
3409
|
+
template.initialize = initializeTemplater;
|
|
3410
|
+
Object.defineProperty(template, "initialize", { value: initializeTemplater });
|
|
3375
3411
|
//#endregion
|
|
3376
3412
|
//#region src/value/clone.ts
|
|
3377
3413
|
const CLONE_NAME = "clone";
|
|
3378
|
-
function clone(value,
|
|
3379
|
-
|
|
3414
|
+
function clone(value, options) {
|
|
3415
|
+
switch (true) {
|
|
3416
|
+
case value === null:
|
|
3417
|
+
case value === void 0:
|
|
3418
|
+
case typeof value === "bigint":
|
|
3419
|
+
case typeof value === "boolean":
|
|
3420
|
+
case typeof value === "number":
|
|
3421
|
+
case typeof value === "string": return value;
|
|
3422
|
+
case value instanceof Date: return new Date(value.getTime());
|
|
3423
|
+
default: return cloneAny(value, getCloneParameters(options), 0);
|
|
3424
|
+
}
|
|
3380
3425
|
}
|
|
3381
3426
|
clone.handlers = getSelfHandlers(clone, {
|
|
3382
3427
|
callback: tryStructuredClone,
|
|
@@ -3384,90 +3429,92 @@ clone.handlers = getSelfHandlers(clone, {
|
|
|
3384
3429
|
});
|
|
3385
3430
|
clone.deregister = deregisterCloner;
|
|
3386
3431
|
clone.register = registerCloner;
|
|
3387
|
-
function
|
|
3388
|
-
|
|
3432
|
+
function cloneAny(value, parameters, depth) {
|
|
3433
|
+
switch (true) {
|
|
3434
|
+
case value == null:
|
|
3435
|
+
case typeof value === "bigint":
|
|
3436
|
+
case typeof value === "boolean":
|
|
3437
|
+
case typeof value === "number":
|
|
3438
|
+
case typeof value === "string": return value;
|
|
3439
|
+
case value instanceof Date: return new Date(value.getTime());
|
|
3440
|
+
case typeof value === "function": return parameters.options?.copyFunctions ? value : void 0;
|
|
3441
|
+
case typeof value === "symbol": return parameters.options?.copySymbols ? value : Symbol(value.description);
|
|
3442
|
+
case parameters.references.has(value): return parameters.references.get(value);
|
|
3443
|
+
case value instanceof ArrayBuffer: return cloneArrayBuffer(value, parameters, depth);
|
|
3444
|
+
case value instanceof DataView: return cloneDataView(value, parameters, depth);
|
|
3445
|
+
case value instanceof RegExp: return cloneRegularExpression(value, parameters, depth);
|
|
3446
|
+
case value instanceof Map: return cloneMap(value, parameters, depth);
|
|
3447
|
+
case typeof Node !== "undefined" && value instanceof Node: return cloneNode(value, parameters, depth);
|
|
3448
|
+
case value instanceof Set: return cloneSet(value, parameters, depth);
|
|
3449
|
+
case isArrayOrPlainObject(value): return cloneObject(value, parameters, depth);
|
|
3450
|
+
case isTypedArray(value): return cloneTypedArray(value, parameters, depth);
|
|
3451
|
+
default: return clone.handlers.handle(value, parameters, depth);
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
function cloneArrayBuffer(value, parameters, depth) {
|
|
3455
|
+
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
3389
3456
|
const cloned = new ArrayBuffer(value.byteLength);
|
|
3390
3457
|
new Uint8Array(cloned).set(new Uint8Array(value));
|
|
3391
|
-
references
|
|
3458
|
+
parameters.references.set(value, cloned);
|
|
3392
3459
|
return cloned;
|
|
3393
3460
|
}
|
|
3394
|
-
function cloneDataView(value,
|
|
3461
|
+
function cloneDataView(value, parameters, depth) {
|
|
3395
3462
|
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
3396
|
-
const buffer = cloneArrayBuffer(value.buffer);
|
|
3463
|
+
const buffer = cloneArrayBuffer(value.buffer, parameters, depth);
|
|
3397
3464
|
const cloned = new DataView(buffer, value.byteOffset, value.byteLength);
|
|
3398
|
-
references.set(value, cloned);
|
|
3465
|
+
parameters.references.set(value, cloned);
|
|
3399
3466
|
return cloned;
|
|
3400
3467
|
}
|
|
3401
|
-
function cloneMap(map,
|
|
3468
|
+
function cloneMap(map, parameters, depth) {
|
|
3402
3469
|
if (depth >= CLONE_MAX_DEPTH) return map;
|
|
3470
|
+
const flat = parameters.options?.flat;
|
|
3403
3471
|
const cloned = /* @__PURE__ */ new Map();
|
|
3404
3472
|
const entries = map.entries();
|
|
3405
|
-
for (const entry of entries) cloned.set(flat ? entry[0] :
|
|
3406
|
-
references.set(map, cloned);
|
|
3473
|
+
for (const entry of entries) cloned.set(flat ? entry[0] : cloneAny(entry[0], parameters, depth + 1), flat ? entry[1] : cloneAny(entry[1], parameters, depth + 1));
|
|
3474
|
+
parameters.references.set(map, cloned);
|
|
3407
3475
|
return cloned;
|
|
3408
3476
|
}
|
|
3409
|
-
function cloneNode(node,
|
|
3477
|
+
function cloneNode(node, parameters, depth) {
|
|
3410
3478
|
if (depth >= CLONE_MAX_DEPTH) return node;
|
|
3411
3479
|
const cloned = node.cloneNode(true);
|
|
3412
|
-
references.set(node, cloned);
|
|
3480
|
+
parameters.references.set(node, cloned);
|
|
3413
3481
|
return cloned;
|
|
3414
3482
|
}
|
|
3415
|
-
function cloneObject(value,
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
const
|
|
3419
|
-
const
|
|
3483
|
+
function cloneObject(value, parameters, depth) {
|
|
3484
|
+
const isArray = Array.isArray(value);
|
|
3485
|
+
if (parameters.options?.flat || depth >= CLONE_MAX_DEPTH) return isArray ? value.slice() : { ...value };
|
|
3486
|
+
const cloned = isArray ? [] : {};
|
|
3487
|
+
const keys = isArray ? void 0 : Object.keys(value);
|
|
3488
|
+
const { length } = keys ?? value;
|
|
3420
3489
|
for (let index = 0; index < length; index += 1) {
|
|
3421
|
-
const key = keys[index];
|
|
3422
|
-
cloned[key] =
|
|
3490
|
+
const key = keys?.[index] ?? index;
|
|
3491
|
+
cloned[key] = cloneAny(value[key], parameters, depth + 1);
|
|
3423
3492
|
}
|
|
3424
|
-
references.set(value, cloned);
|
|
3493
|
+
parameters.references.set(value, cloned);
|
|
3425
3494
|
return cloned;
|
|
3426
3495
|
}
|
|
3427
|
-
function cloneRegularExpression(value,
|
|
3496
|
+
function cloneRegularExpression(value, parameters, depth) {
|
|
3428
3497
|
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
3429
3498
|
const cloned = new RegExp(value.source, value.flags);
|
|
3430
3499
|
cloned.lastIndex = value.lastIndex;
|
|
3431
|
-
references.set(value, cloned);
|
|
3500
|
+
parameters.references.set(value, cloned);
|
|
3432
3501
|
return cloned;
|
|
3433
3502
|
}
|
|
3434
|
-
function cloneSet(set,
|
|
3503
|
+
function cloneSet(set, parameters, depth) {
|
|
3435
3504
|
if (depth >= CLONE_MAX_DEPTH) return set;
|
|
3436
3505
|
const cloned = /* @__PURE__ */ new Set();
|
|
3437
3506
|
const values = [...set.values()];
|
|
3438
3507
|
const { length } = values;
|
|
3439
|
-
for (let index = 0; index < length; index += 1) cloned.add(flat ? values[index] :
|
|
3440
|
-
references.set(set, cloned);
|
|
3508
|
+
for (let index = 0; index < length; index += 1) cloned.add(parameters.options?.flat ? values[index] : cloneAny(values[index], parameters, depth + 1));
|
|
3509
|
+
parameters.references.set(set, cloned);
|
|
3441
3510
|
return cloned;
|
|
3442
3511
|
}
|
|
3443
|
-
function cloneTypedArray(value,
|
|
3512
|
+
function cloneTypedArray(value, parameters, depth) {
|
|
3444
3513
|
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
3445
3514
|
const cloned = new value.constructor(value);
|
|
3446
|
-
references.set(value, cloned);
|
|
3515
|
+
parameters.references.set(value, cloned);
|
|
3447
3516
|
return cloned;
|
|
3448
3517
|
}
|
|
3449
|
-
function cloneValue(value, depth, references, flat) {
|
|
3450
|
-
switch (true) {
|
|
3451
|
-
case value == null:
|
|
3452
|
-
case typeof value === "bigint":
|
|
3453
|
-
case typeof value === "boolean":
|
|
3454
|
-
case typeof value === "number":
|
|
3455
|
-
case typeof value === "string": return value;
|
|
3456
|
-
case typeof value === "function": return;
|
|
3457
|
-
case typeof value === "symbol": return Symbol(value.description);
|
|
3458
|
-
case references.has(value): return references.get(value);
|
|
3459
|
-
case value instanceof ArrayBuffer: return cloneArrayBuffer(value, depth, references);
|
|
3460
|
-
case value instanceof DataView: return cloneDataView(value, depth, references);
|
|
3461
|
-
case value instanceof Date: return new Date(value.getTime());
|
|
3462
|
-
case value instanceof RegExp: return cloneRegularExpression(value, depth, references);
|
|
3463
|
-
case value instanceof Map: return cloneMap(value, depth, references, flat);
|
|
3464
|
-
case typeof Node !== "undefined" && value instanceof Node: return cloneNode(value, depth, references);
|
|
3465
|
-
case value instanceof Set: return cloneSet(value, depth, references, flat);
|
|
3466
|
-
case isArrayOrPlainObject(value): return cloneObject(value, depth, references, flat);
|
|
3467
|
-
case isTypedArray(value): return cloneTypedArray(value, depth, references);
|
|
3468
|
-
default: return clone.handlers.handle(value, depth, references);
|
|
3469
|
-
}
|
|
3470
|
-
}
|
|
3471
3518
|
/**
|
|
3472
3519
|
* Copy any kind of value
|
|
3473
3520
|
*
|
|
@@ -3478,7 +3525,7 @@ function cloneValue(value, depth, references, flat) {
|
|
|
3478
3525
|
* @returns Copied value
|
|
3479
3526
|
*/
|
|
3480
3527
|
function copy(value) {
|
|
3481
|
-
return
|
|
3528
|
+
return clone(value, CLONE_COPY_OPTIONS);
|
|
3482
3529
|
}
|
|
3483
3530
|
/**
|
|
3484
3531
|
* Deregister a clone handler for a specific class
|
|
@@ -3490,6 +3537,25 @@ function copy(value) {
|
|
|
3490
3537
|
function deregisterCloner(constructor) {
|
|
3491
3538
|
clone.handlers.deregister(constructor);
|
|
3492
3539
|
}
|
|
3540
|
+
function getCloneOptions(input) {
|
|
3541
|
+
if (typeof input === "boolean") return {
|
|
3542
|
+
copyFunctions: false,
|
|
3543
|
+
copySymbols: false,
|
|
3544
|
+
flat: input === true
|
|
3545
|
+
};
|
|
3546
|
+
if (typeof input !== "object" || input === null) return CLONE_DEFAULT_OPTIONS;
|
|
3547
|
+
return {
|
|
3548
|
+
copyFunctions: input.copyFunctions === true,
|
|
3549
|
+
copySymbols: input.copySymbols === true,
|
|
3550
|
+
flat: input.flat === true
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
function getCloneParameters(input) {
|
|
3554
|
+
return {
|
|
3555
|
+
options: getCloneOptions(input),
|
|
3556
|
+
references: /* @__PURE__ */ new WeakMap()
|
|
3557
|
+
};
|
|
3558
|
+
}
|
|
3493
3559
|
/**
|
|
3494
3560
|
* Register a clone handler for a specific class
|
|
3495
3561
|
*
|
|
@@ -3501,17 +3567,27 @@ function deregisterCloner(constructor) {
|
|
|
3501
3567
|
function registerCloner(constructor, handler) {
|
|
3502
3568
|
clone.handlers.register(constructor, handler);
|
|
3503
3569
|
}
|
|
3504
|
-
function tryStructuredClone(value,
|
|
3570
|
+
function tryStructuredClone(value, parameters, depth) {
|
|
3505
3571
|
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
3506
3572
|
try {
|
|
3507
3573
|
const cloned = structuredClone(value);
|
|
3508
|
-
references
|
|
3574
|
+
parameters.references?.set(value, cloned);
|
|
3509
3575
|
return cloned;
|
|
3510
3576
|
} catch {
|
|
3511
|
-
references
|
|
3577
|
+
parameters.references?.set(value, value);
|
|
3512
3578
|
return value;
|
|
3513
3579
|
}
|
|
3514
3580
|
}
|
|
3581
|
+
const CLONE_COPY_OPTIONS = {
|
|
3582
|
+
copyFunctions: true,
|
|
3583
|
+
copySymbols: true,
|
|
3584
|
+
flat: true
|
|
3585
|
+
};
|
|
3586
|
+
const CLONE_DEFAULT_OPTIONS = {
|
|
3587
|
+
copyFunctions: false,
|
|
3588
|
+
copySymbols: false,
|
|
3589
|
+
flat: false
|
|
3590
|
+
};
|
|
3515
3591
|
const CLONE_MAX_DEPTH = 100;
|
|
3516
3592
|
//#endregion
|
|
3517
3593
|
//#region src/value/collection.ts
|
|
@@ -3519,7 +3595,9 @@ function inMap(map, value, key) {
|
|
|
3519
3595
|
const getKey = key === true;
|
|
3520
3596
|
if (!(map instanceof Map)) return getKey ? void 0 : false;
|
|
3521
3597
|
if (!getKey) return inSet(new Set(map.values()), value);
|
|
3522
|
-
|
|
3598
|
+
let found;
|
|
3599
|
+
for (const [key, item] of map) if (equal(item, value)) found = key;
|
|
3600
|
+
return found;
|
|
3523
3601
|
}
|
|
3524
3602
|
/**
|
|
3525
3603
|
* Does the value exist in a _Set_?
|
|
@@ -3648,8 +3726,6 @@ function flatFreeze(value) {
|
|
|
3648
3726
|
function freeze(value, flat) {
|
|
3649
3727
|
return freezeValue(value, /* @__PURE__ */ new WeakSet(), flat === true);
|
|
3650
3728
|
}
|
|
3651
|
-
freeze.flat = flatFreeze;
|
|
3652
|
-
freeze.is = isFrozen;
|
|
3653
3729
|
function freezeArray(array, references, flat) {
|
|
3654
3730
|
if (flat) return Object.freeze(array);
|
|
3655
3731
|
references.add(array);
|
|
@@ -3714,6 +3790,12 @@ function isFrozen(value) {
|
|
|
3714
3790
|
return typeof value === "object" && value !== null && Object.isFrozen(value);
|
|
3715
3791
|
}
|
|
3716
3792
|
const frozenValues = /* @__PURE__ */ new WeakSet();
|
|
3793
|
+
freeze.flat = flatFreeze;
|
|
3794
|
+
freeze.is = isFrozen;
|
|
3795
|
+
Object.defineProperties(freeze, {
|
|
3796
|
+
flat: { value: flatFreeze },
|
|
3797
|
+
is: { value: isFrozen }
|
|
3798
|
+
});
|
|
3717
3799
|
//#endregion
|
|
3718
3800
|
//#region src/internal/value/partial.ts
|
|
3719
3801
|
function partial(value, providedKeys, omit) {
|
|
@@ -3859,7 +3941,6 @@ function assign(to, from, options) {
|
|
|
3859
3941
|
actual.assignValues = true;
|
|
3860
3942
|
return mergeValues([to, ...from], actual);
|
|
3861
3943
|
}
|
|
3862
|
-
assign.initialize = initializeAssigner;
|
|
3863
3944
|
function getMergeOptions(options) {
|
|
3864
3945
|
const actual = {
|
|
3865
3946
|
assignValues: false,
|
|
@@ -3913,7 +3994,6 @@ function initializeMerger(options) {
|
|
|
3913
3994
|
function merge(values, options) {
|
|
3914
3995
|
return mergeValues(values, getMergeOptions(options));
|
|
3915
3996
|
}
|
|
3916
|
-
merge.initialize = initializeMerger;
|
|
3917
3997
|
function mergeObjects(values, options, destination, prefix) {
|
|
3918
3998
|
const { length } = values;
|
|
3919
3999
|
const isArray = Array.isArray(destination ?? values[0]);
|
|
@@ -3943,6 +4023,10 @@ function mergeValues(values, options, prefix) {
|
|
|
3943
4023
|
if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
|
|
3944
4024
|
return options.assignValues ? actual[0] : Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
|
|
3945
4025
|
}
|
|
4026
|
+
assign.initialize = initializeAssigner;
|
|
4027
|
+
merge.initialize = initializeMerger;
|
|
4028
|
+
Object.defineProperty(assign, "initialize", { value: initializeAssigner });
|
|
4029
|
+
Object.defineProperty(merge, "initialize", { value: initializeMerger });
|
|
3946
4030
|
//#endregion
|
|
3947
4031
|
//#region src/value/transform.ts
|
|
3948
4032
|
function getTransformer(input) {
|
|
@@ -3965,7 +4049,6 @@ function initializeTransformer(transform) {
|
|
|
3965
4049
|
function transform(value, transform) {
|
|
3966
4050
|
return transformValue(value, getTransformer(transform));
|
|
3967
4051
|
}
|
|
3968
|
-
transform.initialize = initializeTransformer;
|
|
3969
4052
|
function transformValue(value, transformer) {
|
|
3970
4053
|
if (isNonPlainObject(value)) return {};
|
|
3971
4054
|
if (transformer == null) return value;
|
|
@@ -3979,6 +4062,8 @@ function transformValue(value, transformer) {
|
|
|
3979
4062
|
}
|
|
3980
4063
|
return value;
|
|
3981
4064
|
}
|
|
4065
|
+
transform.initialize = initializeTransformer;
|
|
4066
|
+
Object.defineProperty(transform, "initialize", { value: initializeTransformer });
|
|
3982
4067
|
//#endregion
|
|
3983
4068
|
//#region src/internal/subscription.ts
|
|
3984
4069
|
function addSubscription(subscriptions, subscription, state) {
|
|
@@ -6104,7 +6189,6 @@ function keyedQueue(callback, options) {
|
|
|
6104
6189
|
function queue(callback, options) {
|
|
6105
6190
|
return createQueue(callback, options);
|
|
6106
6191
|
}
|
|
6107
|
-
queue.keyed = keyedQueue;
|
|
6108
6192
|
function removeQueue(state, key, id) {
|
|
6109
6193
|
if (key == null) {
|
|
6110
6194
|
handleQueues(state, QUEUE_HANDLE_CLEAR);
|
|
@@ -6180,6 +6264,8 @@ const QUEUE_STATUS_ACTIVE = "active";
|
|
|
6180
6264
|
const QUEUE_STATUS_EMPTY = "empty";
|
|
6181
6265
|
const QUEUE_STATUS_FULL = "full";
|
|
6182
6266
|
const QUEUE_STATUS_PAUSED = "paused";
|
|
6267
|
+
queue.keyed = keyedQueue;
|
|
6268
|
+
Object.defineProperty(queue, "keyed", { value: keyedQueue });
|
|
6183
6269
|
//#endregion
|
|
6184
6270
|
//#region src/random.ts
|
|
6185
6271
|
/**
|
|
@@ -6288,13 +6374,12 @@ var SizedSet = class extends Set {
|
|
|
6288
6374
|
* @returns Found value if it exists, otherwise `undefined`
|
|
6289
6375
|
*/
|
|
6290
6376
|
get(value, update) {
|
|
6291
|
-
if (super.has(value))
|
|
6292
|
-
|
|
6293
|
-
|
|
6294
|
-
|
|
6295
|
-
}
|
|
6296
|
-
return value;
|
|
6377
|
+
if (!super.has(value)) return;
|
|
6378
|
+
if (update ?? false) {
|
|
6379
|
+
super.delete(value);
|
|
6380
|
+
this.add(value);
|
|
6297
6381
|
}
|
|
6382
|
+
return value;
|
|
6298
6383
|
}
|
|
6299
6384
|
};
|
|
6300
6385
|
//#endregion
|
|
@@ -3,9 +3,10 @@ import { FIND_VALUE_INDEX, findValue } from "./find.mjs";
|
|
|
3
3
|
function indexOf(array, ...parameters) {
|
|
4
4
|
return findValue(FIND_VALUE_INDEX, array, parameters, false);
|
|
5
5
|
}
|
|
6
|
-
indexOf.last = lastIndexOf;
|
|
7
6
|
function lastIndexOf(array, ...parameters) {
|
|
8
7
|
return findValue(FIND_VALUE_INDEX, array, parameters, true);
|
|
9
8
|
}
|
|
9
|
+
indexOf.last = lastIndexOf;
|
|
10
|
+
Object.defineProperty(indexOf, "last", { value: lastIndexOf });
|
|
10
11
|
//#endregion
|
|
11
12
|
export { indexOf, lastIndexOf };
|
|
@@ -10,11 +10,6 @@ import { hasValueResult } from "../value/has.mjs";
|
|
|
10
10
|
function assert(condition, message, error) {
|
|
11
11
|
if (!condition()) throw new (error ?? Error)(message);
|
|
12
12
|
}
|
|
13
|
-
assert.condition = assertCondition;
|
|
14
|
-
assert.defined = assertDefined;
|
|
15
|
-
assert.instanceOf = assertInstanceOf;
|
|
16
|
-
assert.is = assertIs;
|
|
17
|
-
assert.property = assertProperty;
|
|
18
13
|
/**
|
|
19
14
|
* Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not
|
|
20
15
|
*
|
|
@@ -92,5 +87,17 @@ function assertProperty(path, condition, message, error) {
|
|
|
92
87
|
};
|
|
93
88
|
}
|
|
94
89
|
const ASSERT_MESSAGE_VALUE_DEFINED = "Expected value to be defined";
|
|
90
|
+
assert.condition = assertCondition;
|
|
91
|
+
assert.defined = assertDefined;
|
|
92
|
+
assert.instanceOf = assertInstanceOf;
|
|
93
|
+
assert.is = assertIs;
|
|
94
|
+
assert.property = assertProperty;
|
|
95
|
+
Object.defineProperties(assert, {
|
|
96
|
+
condition: { value: assertCondition },
|
|
97
|
+
defined: { value: assertDefined },
|
|
98
|
+
instanceOf: { value: assertInstanceOf },
|
|
99
|
+
is: { value: assertIs },
|
|
100
|
+
property: { value: assertProperty }
|
|
101
|
+
});
|
|
95
102
|
//#endregion
|
|
96
103
|
export { assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty };
|