@oscarpalmer/atoms 0.202.0 → 0.203.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/difference.d.mts +4 -5
- package/dist/array/exists.d.mts +5 -6
- package/dist/array/filter.d.mts +10 -11
- package/dist/array/find.d.mts +10 -11
- package/dist/array/first.d.mts +10 -11
- package/dist/array/flatten.d.mts +2 -3
- package/dist/array/from.d.mts +7 -8
- package/dist/array/group-by.d.mts +7 -8
- package/dist/array/insert.d.mts +3 -4
- package/dist/array/intersection.d.mts +4 -5
- package/dist/array/last.d.mts +10 -11
- package/dist/array/move.d.mts +9 -10
- package/dist/array/partition.d.mts +5 -6
- package/dist/array/push.d.mts +2 -3
- package/dist/array/reverse.d.mts +2 -3
- package/dist/array/select.d.mts +11 -12
- package/dist/array/single.d.mts +4 -5
- package/dist/array/slice.d.mts +12 -13
- package/dist/array/sort.d.mts +31 -32
- package/dist/array/sort.mjs +41 -33
- package/dist/array/splice.d.mts +5 -6
- package/dist/array/swap.d.mts +8 -9
- package/dist/array/to-map.d.mts +7 -8
- package/dist/array/to-record.d.mts +7 -8
- package/dist/array/to-set.d.mts +4 -5
- package/dist/array/toggle.d.mts +4 -5
- package/dist/array/union.d.mts +4 -5
- package/dist/array/unique.d.mts +4 -5
- package/dist/array/update.d.mts +4 -5
- package/dist/beacon.d.mts +8 -9
- package/dist/beacon.mjs +90 -65
- package/dist/color/constants.d.mts +14 -13
- package/dist/color/constants.mjs +9 -2
- package/dist/color/index.d.mts +2 -2
- package/dist/color/instance.d.mts +3 -3
- package/dist/color/instance.mjs +125 -61
- package/dist/color/misc/alpha.d.mts +4 -5
- package/dist/color/misc/format.d.mts +6 -7
- package/dist/color/misc/format.mjs +15 -12
- package/dist/color/misc/get.d.mts +14 -15
- package/dist/color/misc/is.d.mts +16 -17
- package/dist/color/misc/is.mjs +3 -4
- package/dist/color/misc/state.d.mts +8 -10
- package/dist/color/misc/state.mjs +22 -20
- package/dist/color/models.d.mts +25 -19
- package/dist/color/space/hex.d.mts +9 -10
- package/dist/color/space/hsl.d.mts +8 -9
- package/dist/color/space/hwb.d.mts +9 -10
- package/dist/color/space/rgb.d.mts +11 -12
- package/dist/function/limit.d.mts +9 -8
- package/dist/function/limit.mjs +5 -5
- package/dist/function/once.d.mts +26 -6
- package/dist/function/once.mjs +135 -76
- package/dist/function/retry.d.mts +5 -6
- package/dist/function/retry.mjs +3 -3
- package/dist/index.d.mts +182 -58
- package/dist/index.mjs +1191 -810
- package/dist/internal/abort.d.mts +3 -4
- package/dist/internal/array/callbacks.d.mts +4 -5
- package/dist/internal/array/chunk.d.mts +2 -3
- package/dist/internal/array/compact.d.mts +3 -4
- package/dist/internal/array/find.d.mts +10 -11
- package/dist/internal/array/get.d.mts +7 -8
- package/dist/internal/array/group.d.mts +2 -3
- package/dist/internal/array/index-of.d.mts +10 -11
- package/dist/internal/array/insert.d.mts +5 -6
- package/dist/internal/array/match.d.mts +17 -18
- package/dist/internal/array/overlap.d.mts +2 -3
- package/dist/internal/array/sets.d.mts +5 -6
- package/dist/internal/array/shuffle.d.mts +2 -3
- package/dist/internal/array/update.d.mts +2 -3
- package/dist/internal/defaults.d.mts +3 -4
- package/dist/internal/function/assert.d.mts +10 -11
- package/dist/internal/function/limit.d.mts +41 -0
- package/dist/internal/function/limit.mjs +110 -0
- package/dist/internal/function/memoize.d.mts +4 -5
- package/dist/internal/function/memoize.mjs +53 -31
- package/dist/internal/function/misc.d.mts +2 -3
- package/dist/internal/function/work.d.mts +53 -54
- package/dist/internal/herald.d.mts +8 -9
- package/dist/internal/herald.mjs +38 -26
- package/dist/internal/is.d.mts +19 -20
- package/dist/internal/math/aggregate.d.mts +14 -15
- package/dist/internal/math/misc.d.mts +3 -4
- package/dist/internal/number.d.mts +4 -5
- package/dist/internal/random.d.mts +3 -4
- package/dist/internal/result/misc.d.mts +29 -14
- package/dist/internal/result/misc.mjs +4 -0
- package/dist/internal/result/models.d.mts +9 -10
- package/dist/internal/sized/map.d.mts +2 -3
- package/dist/internal/sized/misc.d.mts +2 -3
- package/dist/internal/string/case.d.mts +9 -10
- package/dist/internal/string/misc.d.mts +8 -9
- package/dist/internal/subscription.d.mts +10 -11
- package/dist/internal/subscription.mjs +69 -57
- package/dist/internal/value/compare.d.mts +17 -9
- package/dist/internal/value/compare.mjs +7 -7
- package/dist/internal/value/equal.d.mts +34 -15
- package/dist/internal/value/equal.mjs +28 -13
- package/dist/internal/value/get.d.mts +3 -4
- package/dist/internal/value/handlers.d.mts +19 -9
- package/dist/internal/value/handlers.mjs +50 -50
- package/dist/internal/value/has.d.mts +6 -7
- package/dist/internal/value/misc.d.mts +6 -7
- package/dist/internal/value/partial.d.mts +3 -4
- package/dist/internal/value/set.d.mts +4 -5
- package/dist/is.d.mts +13 -13
- package/dist/logger.d.mts +5 -4
- package/dist/logger.mjs +61 -54
- package/dist/math.d.mts +20 -20
- package/dist/models.d.mts +45 -49
- package/dist/promise/constants.d.mts +14 -15
- package/dist/promise/delay.d.mts +3 -4
- package/dist/promise/delay.mjs +4 -4
- package/dist/promise/helpers.d.mts +7 -8
- package/dist/promise/index.d.mts +13 -14
- package/dist/promise/misc.d.mts +6 -6
- package/dist/promise/models.d.mts +16 -17
- package/dist/promise/timed.d.mts +4 -5
- package/dist/promise/timed.mjs +5 -5
- package/dist/query.d.mts +3 -4
- package/dist/queue.d.mts +14 -15
- package/dist/queue.mjs +185 -129
- package/dist/random.d.mts +8 -8
- package/dist/result/index.d.mts +8 -9
- package/dist/result/match.d.mts +6 -7
- package/dist/result/misc.d.mts +3 -3
- package/dist/result/work/flow.d.mts +28 -29
- package/dist/result/work/pipe.d.mts +24 -25
- package/dist/sized/set.d.mts +2 -3
- package/dist/string/fuzzy.d.mts +21 -12
- package/dist/string/fuzzy.mjs +77 -49
- package/dist/string/index.d.mts +8 -8
- package/dist/string/match.d.mts +4 -5
- package/dist/string/normalize.d.mts +8 -9
- package/dist/string/normalize.mjs +9 -4
- package/dist/string/template.d.mts +9 -9
- package/dist/string/template.mjs +11 -4
- package/dist/value/clone.d.mts +21 -13
- package/dist/value/clone.mjs +22 -20
- package/dist/value/collection.d.mts +4 -5
- package/dist/value/diff.d.mts +5 -6
- package/dist/value/freeze.d.mts +18 -19
- package/dist/value/freeze.mjs +1 -1
- package/dist/value/merge.d.mts +13 -14
- package/dist/value/merge.mjs +21 -5
- package/dist/value/omit.d.mts +2 -3
- package/dist/value/pick.d.mts +2 -3
- package/dist/value/shake.d.mts +3 -4
- package/dist/value/smush.d.mts +3 -4
- package/dist/value/transform.d.mts +15 -10
- package/dist/value/transform.mjs +12 -7
- package/dist/value/unsmush.d.mts +3 -4
- package/package.json +1 -1
- package/dist/internal/function/timer.d.mts +0 -10
- package/dist/internal/function/timer.mjs +0 -87
package/dist/index.mjs
CHANGED
|
@@ -1069,59 +1069,59 @@ const STRING_EXPRESSION_IGNORED = /(^|\.)(__proto__|constructor|prototype)(\.|$)
|
|
|
1069
1069
|
const STRING_EXPRESSION_WORDS = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
|
|
1070
1070
|
//#endregion
|
|
1071
1071
|
//#region src/internal/value/handlers.ts
|
|
1072
|
-
function
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
handlers.register(constructor, handler);
|
|
1085
|
-
}
|
|
1086
|
-
};
|
|
1072
|
+
function BaseHandler(owner, options) {
|
|
1073
|
+
this.handlers = /* @__PURE__ */ new WeakMap();
|
|
1074
|
+
this.owner = owner;
|
|
1075
|
+
this.options = options;
|
|
1076
|
+
}
|
|
1077
|
+
Object.defineProperties(BaseHandler.prototype, {
|
|
1078
|
+
deregister: { value: deregisterHandler },
|
|
1079
|
+
get: { value: getHandler$1 },
|
|
1080
|
+
register: { value: registerHandler }
|
|
1081
|
+
});
|
|
1082
|
+
function CompareHandler(base) {
|
|
1083
|
+
this.base = base;
|
|
1087
1084
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
deregister(constructor) {
|
|
1092
|
-
handlers.delete(constructor);
|
|
1093
|
-
},
|
|
1094
|
-
get(first, second) {
|
|
1095
|
-
if (isConstructable(first) && isConstructable(second) && first.constructor === second.constructor) return handlers.get(first.constructor);
|
|
1096
|
-
},
|
|
1097
|
-
register(constructor, handler) {
|
|
1098
|
-
if (isNonConstructor(constructor) || handler === owner) return;
|
|
1099
|
-
let actual = handler ?? options.method;
|
|
1100
|
-
if (typeof actual !== "function" && typeof actual !== "string") return;
|
|
1101
|
-
if (typeof actual === "string") actual = typeof constructor.prototype[actual] === "function" ? actual : void 0;
|
|
1102
|
-
if (actual != null) handlers.set(constructor, actual);
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1085
|
+
Object.defineProperties(CompareHandler.prototype, { handle: { value: handleComparison } });
|
|
1086
|
+
function ValueHandler(value) {
|
|
1087
|
+
this.base = value;
|
|
1105
1088
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
return
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1089
|
+
Object.defineProperties(ValueHandler.prototype, { handle: { value: handleValue$1 } });
|
|
1090
|
+
function createBaseHandler(owner, options) {
|
|
1091
|
+
return new BaseHandler(owner, options);
|
|
1092
|
+
}
|
|
1093
|
+
function createCompareHandler(owner, options) {
|
|
1094
|
+
return new CompareHandler(createBaseHandler(owner, options));
|
|
1095
|
+
}
|
|
1096
|
+
function createValueHandler(owner, options) {
|
|
1097
|
+
return new ValueHandler(createBaseHandler(owner, options));
|
|
1098
|
+
}
|
|
1099
|
+
function deregisterHandler(value) {
|
|
1100
|
+
this.handlers.delete(value);
|
|
1101
|
+
}
|
|
1102
|
+
function getHandler$1(first, second) {
|
|
1103
|
+
if (isConstructable(first) && isConstructable(second) && first.constructor === second.constructor) return this.handlers.get(first.constructor);
|
|
1104
|
+
}
|
|
1105
|
+
function handleComparison(first, second, ...parameters) {
|
|
1106
|
+
const handler = this.base.get(first, second);
|
|
1107
|
+
if (handler == null) return this.base.options.callback(first, second, ...parameters);
|
|
1108
|
+
return typeof handler === "function" ? handler(first, second) : first[handler](second);
|
|
1121
1109
|
}
|
|
1122
1110
|
function isConstructable(value) {
|
|
1123
1111
|
return typeof value === "object" && value !== null;
|
|
1124
1112
|
}
|
|
1113
|
+
function registerHandler(constructor, handler) {
|
|
1114
|
+
if (isNonConstructor(constructor) || handler === this.owner) return;
|
|
1115
|
+
let actual = handler ?? this.options.method;
|
|
1116
|
+
if (typeof actual !== "function" && typeof actual !== "string") return;
|
|
1117
|
+
if (typeof actual === "string") actual = typeof constructor.prototype[actual] === "function" ? actual : void 0;
|
|
1118
|
+
if (actual != null) this.handlers.set(constructor, actual);
|
|
1119
|
+
}
|
|
1120
|
+
function handleValue$1(value, ...parameters) {
|
|
1121
|
+
const handler = this.base.get(value, value);
|
|
1122
|
+
if (handler == null) return this.base.options.callback(value, ...parameters);
|
|
1123
|
+
return typeof handler === "function" ? handler(value) : value[handler]();
|
|
1124
|
+
}
|
|
1125
1125
|
//#endregion
|
|
1126
1126
|
//#region src/internal/value/compare.ts
|
|
1127
1127
|
const COMPARE_NAME = "compare";
|
|
@@ -1167,7 +1167,7 @@ function compareValue(first, second, compareStrings) {
|
|
|
1167
1167
|
const firstType = typeof first;
|
|
1168
1168
|
if (firstType === typeof second && firstType in comparators) return comparators[firstType](first, second);
|
|
1169
1169
|
if (first instanceof Date && second instanceof Date) return compareNumbers(first.getTime(), second.getTime());
|
|
1170
|
-
return compare.
|
|
1170
|
+
return compare.handler.handle(first, second, compareStrings);
|
|
1171
1171
|
}
|
|
1172
1172
|
/**
|
|
1173
1173
|
* Deregister a custom comparison handler for a class
|
|
@@ -1177,7 +1177,7 @@ function compareValue(first, second, compareStrings) {
|
|
|
1177
1177
|
* @param constructor Class constructor
|
|
1178
1178
|
*/
|
|
1179
1179
|
function deregisterComparator(constructor) {
|
|
1180
|
-
compare.
|
|
1180
|
+
compare.handler.base.deregister(constructor);
|
|
1181
1181
|
}
|
|
1182
1182
|
function getComparisonParts(value) {
|
|
1183
1183
|
if (Array.isArray(value)) return value;
|
|
@@ -1192,7 +1192,7 @@ function getComparisonParts(value) {
|
|
|
1192
1192
|
* @param handler Method name or comparison function _(defaults to `compare`)_
|
|
1193
1193
|
*/
|
|
1194
1194
|
function registerComparator(constructor, handler) {
|
|
1195
|
-
compare.
|
|
1195
|
+
compare.handler.base.register(constructor, handler);
|
|
1196
1196
|
}
|
|
1197
1197
|
const comparators = {
|
|
1198
1198
|
bigint: compareNumbers,
|
|
@@ -1200,24 +1200,34 @@ const comparators = {
|
|
|
1200
1200
|
number: compareNumbers,
|
|
1201
1201
|
symbol: compareSymbols
|
|
1202
1202
|
};
|
|
1203
|
-
const
|
|
1203
|
+
const compareHandler = createCompareHandler(compare, {
|
|
1204
1204
|
callback: (first, second, compareStrings) => compareStrings ? getString(first).localeCompare(getString(second)) : void 0,
|
|
1205
1205
|
method: COMPARE_NAME
|
|
1206
1206
|
});
|
|
1207
1207
|
compare.deregister = deregisterComparator;
|
|
1208
|
-
compare.
|
|
1208
|
+
compare.handler = compareHandler;
|
|
1209
1209
|
compare.register = registerComparator;
|
|
1210
1210
|
Object.defineProperties(compare, {
|
|
1211
1211
|
deregister: { value: deregisterComparator },
|
|
1212
|
-
|
|
1212
|
+
handler: { value: compareHandler },
|
|
1213
1213
|
register: { value: registerComparator }
|
|
1214
1214
|
});
|
|
1215
1215
|
//#endregion
|
|
1216
1216
|
//#region src/array/sort.ts
|
|
1217
|
+
const SORTER_PROPERTY = "$sorter";
|
|
1218
|
+
function Sorter(sorters) {
|
|
1219
|
+
Object.defineProperty(this, SORTER_SYMBOL, { value: sorters });
|
|
1220
|
+
}
|
|
1221
|
+
Object.defineProperties(Sorter.prototype, {
|
|
1222
|
+
[SORTER_PROPERTY]: { value: true },
|
|
1223
|
+
index: { value: getSortedArrayIndex },
|
|
1224
|
+
is: { value: isSortedArray },
|
|
1225
|
+
sort: { value: sortArray }
|
|
1226
|
+
});
|
|
1217
1227
|
function getComparisonSorter(callback, modifier) {
|
|
1218
1228
|
return {
|
|
1219
1229
|
modifier,
|
|
1220
|
-
|
|
1230
|
+
comparison: { simple: callback },
|
|
1221
1231
|
get: false,
|
|
1222
1232
|
identifier: callback.toString()
|
|
1223
1233
|
};
|
|
@@ -1226,15 +1236,29 @@ function getComparisonValue(first, second, sorters, length) {
|
|
|
1226
1236
|
for (let index = 0; index < length; index += 1) {
|
|
1227
1237
|
const sorter = sorters[index];
|
|
1228
1238
|
const values = [sorter.get ? sorter.value(first) : first, sorter.get ? sorter.value(second) : second];
|
|
1229
|
-
const comparison = (sorter.
|
|
1239
|
+
const comparison = (sorter.comparison?.complex?.(first, values[0], second, values[1]) ?? sorter.comparison?.simple?.(values[0], values[1]) ?? compare(values[0], values[1])) * sorter.modifier;
|
|
1230
1240
|
if (comparison !== 0) return comparison;
|
|
1231
1241
|
}
|
|
1232
1242
|
return 0;
|
|
1233
1243
|
}
|
|
1234
|
-
function
|
|
1244
|
+
function getModifier(first, second) {
|
|
1245
|
+
return modifiers[first === true || second === true ? SORT_DIRECTION_DESCENDING : SORT_DIRECTION_ASCENDING];
|
|
1246
|
+
}
|
|
1247
|
+
function getObjectSorter(obj, modifier) {
|
|
1248
|
+
let sorter;
|
|
1249
|
+
if (typeof obj.comparison === "function") sorter = getComparisonSorter(obj.comparison, modifier);
|
|
1250
|
+
else if (typeof obj.key === "string") {
|
|
1251
|
+
sorter = getValueSortHandlers(obj.key, modifier);
|
|
1252
|
+
if (typeof obj.compare === "function") sorter.comparison = { complex: obj.compare };
|
|
1253
|
+
} else if (typeof obj.value === "function") sorter = getValueSortHandlers(obj.value, modifier);
|
|
1254
|
+
if (sorter != null && typeof obj.direction === "string") sorter.modifier = modifiers[obj.direction] ?? modifier;
|
|
1255
|
+
return sorter;
|
|
1256
|
+
}
|
|
1257
|
+
function getSortedArrayIndex(array, item) {
|
|
1235
1258
|
if (!Array.isArray(array)) return -1;
|
|
1236
1259
|
const { length } = array;
|
|
1237
1260
|
if (length === 0) return 0;
|
|
1261
|
+
const sorters = Array.isArray(this) ? this : this[SORTER_SYMBOL];
|
|
1238
1262
|
const sortersLength = sorters.length;
|
|
1239
1263
|
if (getComparisonValue(item, array[0], sorters, sortersLength) < 0) return 0;
|
|
1240
1264
|
if (getComparisonValue(item, array[length - 1], sorters, sortersLength) >= 0) return length;
|
|
@@ -1247,36 +1271,23 @@ function getIndex(array, item, sorters) {
|
|
|
1247
1271
|
}
|
|
1248
1272
|
return low;
|
|
1249
1273
|
}
|
|
1250
|
-
function getModifier(first, second) {
|
|
1251
|
-
return modifiers[first === true || second === true ? SORT_DIRECTION_DESCENDING : SORT_DIRECTION_ASCENDING];
|
|
1252
|
-
}
|
|
1253
|
-
function getObjectSorter(obj, modifier) {
|
|
1254
|
-
let sorter;
|
|
1255
|
-
if (typeof obj.comparison === "function") sorter = getComparisonSorter(obj.comparison, modifier);
|
|
1256
|
-
else if (typeof obj.key === "string") {
|
|
1257
|
-
sorter = getValueSorter(obj.key, modifier);
|
|
1258
|
-
if (typeof obj.compare === "function") sorter.compare = { complex: obj.compare };
|
|
1259
|
-
} else if (typeof obj.value === "function") sorter = getValueSorter(obj.value, modifier);
|
|
1260
|
-
if (sorter != null && typeof obj.direction === "string") sorter.modifier = modifiers[obj.direction] ?? modifier;
|
|
1261
|
-
return sorter;
|
|
1262
|
-
}
|
|
1263
1274
|
function getSortedIndex(array, item, first, second) {
|
|
1264
|
-
return
|
|
1275
|
+
return getSortedArrayIndex.call(getSortHandlers(first, getModifier(first, second)), array, item);
|
|
1265
1276
|
}
|
|
1266
|
-
function
|
|
1277
|
+
function getSortHandler(value, modifier) {
|
|
1267
1278
|
switch (true) {
|
|
1268
1279
|
case typeof value === "function": return getComparisonSorter(value, modifier);
|
|
1269
|
-
case typeof value === "string": return
|
|
1280
|
+
case typeof value === "string": return getValueSortHandlers(value, modifier);
|
|
1270
1281
|
case isPlainObject(value): return getObjectSorter(value, modifier);
|
|
1271
1282
|
}
|
|
1272
1283
|
}
|
|
1273
|
-
function
|
|
1284
|
+
function getSortHandlers(value, modifier) {
|
|
1274
1285
|
const array = Array.isArray(value) ? value : [value];
|
|
1275
1286
|
const { length } = array;
|
|
1276
1287
|
const sorters = [];
|
|
1277
1288
|
for (let index = 0; index < length; index += 1) {
|
|
1278
1289
|
const item = array[index];
|
|
1279
|
-
const sorter =
|
|
1290
|
+
const sorter = getSortHandler(item, modifier);
|
|
1280
1291
|
if (sorter != null) sorters.push(sorter);
|
|
1281
1292
|
}
|
|
1282
1293
|
if (sorters.length === 0) return [{
|
|
@@ -1286,7 +1297,7 @@ function getSorters(value, modifier) {
|
|
|
1286
1297
|
}];
|
|
1287
1298
|
return sorters.filter((value, index, array) => array.findIndex((next) => next.identifier === value.identifier) === index);
|
|
1288
1299
|
}
|
|
1289
|
-
function
|
|
1300
|
+
function getValueSortHandlers(value, modifier) {
|
|
1290
1301
|
const isFunction = typeof value === "function";
|
|
1291
1302
|
return {
|
|
1292
1303
|
modifier,
|
|
@@ -1296,21 +1307,16 @@ function getValueSorter(value, modifier) {
|
|
|
1296
1307
|
};
|
|
1297
1308
|
}
|
|
1298
1309
|
function initializeSorter(first, second) {
|
|
1299
|
-
|
|
1300
|
-
const sorter = (array) => sortArray(array, sorters);
|
|
1301
|
-
Object.defineProperties(sorter, {
|
|
1302
|
-
index: { value: (array, item) => getIndex(array, item, sorters) },
|
|
1303
|
-
is: { value: (array) => isSortedArray(array, sorters) }
|
|
1304
|
-
});
|
|
1305
|
-
return sorter;
|
|
1310
|
+
return new Sorter(getSortHandlers(first, getModifier(first, second)));
|
|
1306
1311
|
}
|
|
1307
1312
|
function isSorted(array, first, second) {
|
|
1308
|
-
return isSortedArray(
|
|
1313
|
+
return isSortedArray.call(getSortHandlers(first, getModifier(first, second)), array);
|
|
1309
1314
|
}
|
|
1310
|
-
function isSortedArray(array
|
|
1315
|
+
function isSortedArray(array) {
|
|
1311
1316
|
if (!Array.isArray(array)) return false;
|
|
1312
1317
|
const { length } = array;
|
|
1313
1318
|
if (length < 2) return true;
|
|
1319
|
+
const sorters = Array.isArray(this) ? this : this[SORTER_SYMBOL];
|
|
1314
1320
|
const sortersLength = sorters.length;
|
|
1315
1321
|
let offset = 0;
|
|
1316
1322
|
if (length >= SORT_THRESHOLD) {
|
|
@@ -1332,10 +1338,11 @@ function isSortedArray(array, sorters) {
|
|
|
1332
1338
|
return true;
|
|
1333
1339
|
}
|
|
1334
1340
|
function sort(array, first, second) {
|
|
1335
|
-
return sortArray(
|
|
1341
|
+
return sortArray.call(getSortHandlers(first, getModifier(first, second)), array);
|
|
1336
1342
|
}
|
|
1337
|
-
function sortArray(array
|
|
1343
|
+
function sortArray(array) {
|
|
1338
1344
|
if (!Array.isArray(array)) return [];
|
|
1345
|
+
const sorters = Array.isArray(this) ? this : this[SORTER_SYMBOL];
|
|
1339
1346
|
const { length } = sorters;
|
|
1340
1347
|
return array.length > 1 ? array.sort((first, second) => getComparisonValue(first, second, sorters, length)) : array;
|
|
1341
1348
|
}
|
|
@@ -1343,6 +1350,7 @@ const SORT_PEEK_PERCENTAGE = 10;
|
|
|
1343
1350
|
const SORT_THRESHOLD = 100;
|
|
1344
1351
|
const SORT_DIRECTION_ASCENDING = "ascending";
|
|
1345
1352
|
const SORT_DIRECTION_DESCENDING = "descending";
|
|
1353
|
+
const SORTER_SYMBOL = Symbol(SORTER_PROPERTY);
|
|
1346
1354
|
const modifiers = {
|
|
1347
1355
|
[SORT_DIRECTION_ASCENDING]: 1,
|
|
1348
1356
|
[SORT_DIRECTION_DESCENDING]: -1
|
|
@@ -1465,86 +1473,109 @@ function getNumberOrDefault(value, defaultValue, minimum) {
|
|
|
1465
1473
|
return typeof value === "number" && !Number.isNaN(value) && value >= (minimum ?? 0) ? value : defaultValue;
|
|
1466
1474
|
}
|
|
1467
1475
|
//#endregion
|
|
1468
|
-
//#region src/internal/function/
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1476
|
+
//#region src/internal/function/limit.ts
|
|
1477
|
+
const LIMITER_NAME_ASYNC = "asyncLimiter";
|
|
1478
|
+
const LIMITER_NAME_SYNC = "limiter";
|
|
1479
|
+
const LIMITER_PROPERTY = "$limiter";
|
|
1480
|
+
function AsyncLimiter(type, callback, time) {
|
|
1481
|
+
Object.defineProperty(this, LIMITER_SYMBOL, { value: {
|
|
1482
|
+
callback,
|
|
1483
|
+
type,
|
|
1484
|
+
interval: getNumberOrDefault(time, 0),
|
|
1485
|
+
parameters: [],
|
|
1486
|
+
throttle: type === LIMITER_THROTTLE
|
|
1487
|
+
} });
|
|
1488
|
+
}
|
|
1489
|
+
Object.defineProperties(AsyncLimiter.prototype, {
|
|
1490
|
+
[LIMITER_PROPERTY]: { value: LIMITER_NAME_ASYNC },
|
|
1491
|
+
cancel: { value: cancelAsyncLimiter },
|
|
1492
|
+
run: { value: runAsyncLimiter }
|
|
1493
|
+
});
|
|
1494
|
+
function Limiter(type, callback, time) {
|
|
1495
|
+
Object.defineProperty(this, LIMITER_SYMBOL, { value: {
|
|
1496
|
+
callback,
|
|
1497
|
+
type,
|
|
1498
|
+
interval: getNumberOrDefault(time, 0),
|
|
1499
|
+
parameters: [],
|
|
1500
|
+
throttle: type === LIMITER_THROTTLE
|
|
1501
|
+
} });
|
|
1502
|
+
}
|
|
1503
|
+
Object.defineProperties(Limiter.prototype, {
|
|
1504
|
+
[LIMITER_PROPERTY]: { value: LIMITER_NAME_SYNC },
|
|
1505
|
+
cancel: { value: cancelLimiter },
|
|
1506
|
+
run: { value: runLimiter }
|
|
1507
|
+
});
|
|
1508
|
+
function cancelAsyncLimiter() {
|
|
1509
|
+
const state = this[LIMITER_SYMBOL];
|
|
1510
|
+
if (state.timer != null) clearTimer(state.timer);
|
|
1511
|
+
if (state.last != null && !state.last.running) {
|
|
1512
|
+
state.last.reject();
|
|
1513
|
+
state.last = void 0;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
function cancelLimiter() {
|
|
1517
|
+
const { timer } = this[LIMITER_SYMBOL];
|
|
1518
|
+
if (timer != null) clearTimer(timer);
|
|
1519
|
+
}
|
|
1520
|
+
function getAsyncLimiter(type, callback, time) {
|
|
1521
|
+
return new AsyncLimiter(type, callback, time);
|
|
1522
|
+
}
|
|
1523
|
+
function getLimiter(type, callback, time) {
|
|
1524
|
+
return new Limiter(type, callback, time);
|
|
1525
|
+
}
|
|
1526
|
+
async function handleAsyncLimiter(state, item) {
|
|
1527
|
+
const now = performance.now();
|
|
1528
|
+
state.start ??= now;
|
|
1529
|
+
if (state.interval === 0 || now - state.start >= state.interval - LIMITER_OFFSET) {
|
|
1530
|
+
state.start = state.throttle ? now : void 0;
|
|
1531
|
+
item.running = true;
|
|
1532
|
+
try {
|
|
1533
|
+
let result = state.callback(...item.parameters);
|
|
1534
|
+
if (result instanceof Promise) result = await result;
|
|
1535
|
+
item.resolve(result);
|
|
1536
|
+
} catch (error) {
|
|
1537
|
+
item.reject(error);
|
|
1538
|
+
} finally {
|
|
1539
|
+
item.running = false;
|
|
1475
1540
|
}
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
} else id = startTimer(() => run(item));
|
|
1493
|
-
}
|
|
1494
|
-
const interval = getNumberOrDefault(time, 0);
|
|
1495
|
-
const throttle = type === TIMER_THROTTLE;
|
|
1496
|
-
let id;
|
|
1497
|
-
let last;
|
|
1498
|
-
let start;
|
|
1499
|
-
const timer = (...parameters) => {
|
|
1500
|
-
cancel();
|
|
1501
|
-
const next = {
|
|
1502
|
-
parameters,
|
|
1503
|
-
running: false
|
|
1504
|
-
};
|
|
1505
|
-
next.promise = new Promise((resolve, reject) => {
|
|
1506
|
-
next.reject = reject;
|
|
1507
|
-
next.resolve = resolve;
|
|
1508
|
-
});
|
|
1509
|
-
last = next;
|
|
1510
|
-
if (throttle) run(next);
|
|
1511
|
-
else id = startTimer(() => run(next));
|
|
1512
|
-
return next.promise;
|
|
1513
|
-
};
|
|
1514
|
-
Object.defineProperty(timer, TIMER_CANCEL, { value: () => cancel() });
|
|
1515
|
-
return timer;
|
|
1516
|
-
}
|
|
1517
|
-
function getTimer(type, callback, time) {
|
|
1518
|
-
function cancel() {
|
|
1519
|
-
clearTimer(id);
|
|
1520
|
-
}
|
|
1521
|
-
function run() {
|
|
1522
|
-
const now = performance.now();
|
|
1523
|
-
start ??= now;
|
|
1524
|
-
if (interval === 0 || now - start >= interval - TIMER_OFFSET) {
|
|
1525
|
-
start = throttle ? now : void 0;
|
|
1526
|
-
callback(...args);
|
|
1527
|
-
} else id = startTimer(run);
|
|
1528
|
-
}
|
|
1529
|
-
const interval = getNumberOrDefault(time, 0);
|
|
1530
|
-
const throttle = type === TIMER_THROTTLE;
|
|
1531
|
-
let args;
|
|
1532
|
-
let id;
|
|
1533
|
-
let start;
|
|
1534
|
-
const timer = (...parameters) => {
|
|
1535
|
-
cancel();
|
|
1536
|
-
args = parameters;
|
|
1537
|
-
if (throttle) run();
|
|
1538
|
-
else id = startTimer(run);
|
|
1541
|
+
} else state.timer = startTimer(() => handleAsyncLimiter(state, item));
|
|
1542
|
+
}
|
|
1543
|
+
function handleLimiter(state) {
|
|
1544
|
+
const now = performance.now();
|
|
1545
|
+
state.start ??= now;
|
|
1546
|
+
if (state.interval === 0 || now - state.start >= state.interval - LIMITER_OFFSET) {
|
|
1547
|
+
state.start = state.throttle ? now : void 0;
|
|
1548
|
+
state.callback(...state.parameters);
|
|
1549
|
+
} else state.timer = startTimer(() => handleLimiter(state));
|
|
1550
|
+
}
|
|
1551
|
+
function runAsyncLimiter() {
|
|
1552
|
+
const state = this[LIMITER_SYMBOL];
|
|
1553
|
+
cancelAsyncLimiter.call(this);
|
|
1554
|
+
const next = {
|
|
1555
|
+
parameters: state.parameters,
|
|
1556
|
+
running: false
|
|
1539
1557
|
};
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1558
|
+
next.promise = new Promise((resolve, reject) => {
|
|
1559
|
+
next.reject = reject;
|
|
1560
|
+
next.resolve = resolve;
|
|
1561
|
+
});
|
|
1562
|
+
state.last = next;
|
|
1563
|
+
if (state.throttle) handleAsyncLimiter(state, next);
|
|
1564
|
+
else state.timer = startTimer(() => handleAsyncLimiter(state, next));
|
|
1565
|
+
return next.promise;
|
|
1566
|
+
}
|
|
1567
|
+
function runLimiter(...parameters) {
|
|
1568
|
+
const state = this[LIMITER_SYMBOL];
|
|
1569
|
+
cancelLimiter.call(this);
|
|
1570
|
+
state.parameters = parameters;
|
|
1571
|
+
if (state.throttle) handleLimiter(state);
|
|
1572
|
+
else state.timer = startTimer(() => handleLimiter(state));
|
|
1573
|
+
}
|
|
1574
|
+
const LIMITER_DEBOUNCE = "debounce";
|
|
1575
|
+
const LIMITER_OFFSET = 5;
|
|
1576
|
+
const LIMITER_SYMBOL = Symbol("limiter");
|
|
1577
|
+
const LIMITER_THROTTLE = "throttle";
|
|
1578
|
+
const LIMITER_WAIT = "wait";
|
|
1548
1579
|
// istanbul ignore next
|
|
1549
1580
|
const clearTimer = typeof cancelAnimationFrame === "function" ? cancelAnimationFrame : clearTimeout;
|
|
1550
1581
|
// istanbul ignore next
|
|
@@ -1564,7 +1595,7 @@ const startTimer = typeof requestAnimationFrame === "function" ? requestAnimatio
|
|
|
1564
1595
|
* @returns Debounced callback handler with a `cancel` method
|
|
1565
1596
|
*/
|
|
1566
1597
|
function asyncDebounce(callback, time) {
|
|
1567
|
-
return
|
|
1598
|
+
return getAsyncLimiter(LIMITER_DEBOUNCE, callback, time);
|
|
1568
1599
|
}
|
|
1569
1600
|
/**
|
|
1570
1601
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
@@ -1579,7 +1610,7 @@ function asyncDebounce(callback, time) {
|
|
|
1579
1610
|
* @returns Throttled callback handler with a `cancel` method
|
|
1580
1611
|
*/
|
|
1581
1612
|
function asyncThrottle(callback, time) {
|
|
1582
|
-
return
|
|
1613
|
+
return getAsyncLimiter(LIMITER_THROTTLE, callback, time);
|
|
1583
1614
|
}
|
|
1584
1615
|
/**
|
|
1585
1616
|
* Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
@@ -1591,7 +1622,7 @@ function asyncThrottle(callback, time) {
|
|
|
1591
1622
|
* @returns Debounced callback handler with a `cancel` method
|
|
1592
1623
|
*/
|
|
1593
1624
|
function debounce(callback, time) {
|
|
1594
|
-
return
|
|
1625
|
+
return getLimiter(LIMITER_DEBOUNCE, callback, time);
|
|
1595
1626
|
}
|
|
1596
1627
|
/**
|
|
1597
1628
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
@@ -1601,7 +1632,7 @@ function debounce(callback, time) {
|
|
|
1601
1632
|
* @returns Throttled callback handler with a `cancel` method
|
|
1602
1633
|
*/
|
|
1603
1634
|
function throttle(callback, time) {
|
|
1604
|
-
return
|
|
1635
|
+
return getLimiter(LIMITER_THROTTLE, callback, time);
|
|
1605
1636
|
}
|
|
1606
1637
|
debounce.async = asyncDebounce;
|
|
1607
1638
|
throttle.async = asyncThrottle;
|
|
@@ -1656,6 +1687,10 @@ function unwrap(value, defaultValue) {
|
|
|
1656
1687
|
}
|
|
1657
1688
|
const RESULT_PROPERTY_ERROR = "error";
|
|
1658
1689
|
const RESULT_PROPERTY_VALUE = "value";
|
|
1690
|
+
error.is = isError;
|
|
1691
|
+
ok.is = isOk;
|
|
1692
|
+
Object.defineProperty(error, "is", { value: isError });
|
|
1693
|
+
Object.defineProperty(ok, "is", { value: isOk });
|
|
1659
1694
|
//#endregion
|
|
1660
1695
|
//#region src/internal/value/misc.ts
|
|
1661
1696
|
function findKey(needle, haystack) {
|
|
@@ -1813,6 +1848,74 @@ Object.defineProperties(assert, {
|
|
|
1813
1848
|
});
|
|
1814
1849
|
//#endregion
|
|
1815
1850
|
//#region src/function/once.ts
|
|
1851
|
+
const ONCE_NAME_ASYNC = "asyncOnce";
|
|
1852
|
+
const ONCE_NAME_SYNC = "once";
|
|
1853
|
+
const ONCE_PROPERTY = "$once";
|
|
1854
|
+
function AsyncOnce(callback) {
|
|
1855
|
+
Object.defineProperty(this, ONCE_SYMBOL, { value: {
|
|
1856
|
+
callback,
|
|
1857
|
+
called: false,
|
|
1858
|
+
cleared: false,
|
|
1859
|
+
error: false,
|
|
1860
|
+
finished: false,
|
|
1861
|
+
items: [],
|
|
1862
|
+
value: void 0
|
|
1863
|
+
} });
|
|
1864
|
+
}
|
|
1865
|
+
Object.defineProperties(AsyncOnce.prototype, {
|
|
1866
|
+
[ONCE_PROPERTY]: { value: ONCE_NAME_ASYNC },
|
|
1867
|
+
called: {
|
|
1868
|
+
enumerable: true,
|
|
1869
|
+
get() {
|
|
1870
|
+
return this[ONCE_SYMBOL].called;
|
|
1871
|
+
}
|
|
1872
|
+
},
|
|
1873
|
+
clear: { value: clearOnce },
|
|
1874
|
+
cleared: {
|
|
1875
|
+
enumerable: true,
|
|
1876
|
+
get() {
|
|
1877
|
+
return this[ONCE_SYMBOL].cleared;
|
|
1878
|
+
}
|
|
1879
|
+
},
|
|
1880
|
+
error: {
|
|
1881
|
+
enumerable: true,
|
|
1882
|
+
get() {
|
|
1883
|
+
return this[ONCE_SYMBOL].error;
|
|
1884
|
+
}
|
|
1885
|
+
},
|
|
1886
|
+
finished: {
|
|
1887
|
+
enumerable: true,
|
|
1888
|
+
get() {
|
|
1889
|
+
return this[ONCE_SYMBOL].finished;
|
|
1890
|
+
}
|
|
1891
|
+
},
|
|
1892
|
+
run: { value: runOnceAsync }
|
|
1893
|
+
});
|
|
1894
|
+
function Once(callback) {
|
|
1895
|
+
Object.defineProperty(this, ONCE_SYMBOL, { value: {
|
|
1896
|
+
callback,
|
|
1897
|
+
called: false,
|
|
1898
|
+
cleared: false,
|
|
1899
|
+
value: void 0
|
|
1900
|
+
} });
|
|
1901
|
+
}
|
|
1902
|
+
Object.defineProperties(Once.prototype, {
|
|
1903
|
+
[ONCE_PROPERTY]: { value: ONCE_NAME_SYNC },
|
|
1904
|
+
clear: { value: clearOnce },
|
|
1905
|
+
called: {
|
|
1906
|
+
enumerable: true,
|
|
1907
|
+
get() {
|
|
1908
|
+
return this[ONCE_SYMBOL].called;
|
|
1909
|
+
}
|
|
1910
|
+
},
|
|
1911
|
+
cleared: {
|
|
1912
|
+
enumerable: true,
|
|
1913
|
+
get() {
|
|
1914
|
+
return this[ONCE_SYMBOL].cleared;
|
|
1915
|
+
}
|
|
1916
|
+
},
|
|
1917
|
+
run: { value: runOnce }
|
|
1918
|
+
});
|
|
1816
1919
|
/**
|
|
1817
1920
|
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
1818
1921
|
*
|
|
@@ -1823,59 +1926,12 @@ Object.defineProperties(assert, {
|
|
|
1823
1926
|
*/
|
|
1824
1927
|
function asyncOnce(callback) {
|
|
1825
1928
|
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
1826
|
-
|
|
1827
|
-
called: false,
|
|
1828
|
-
cleared: false,
|
|
1829
|
-
error: false,
|
|
1830
|
-
finished: false,
|
|
1831
|
-
items: [],
|
|
1832
|
-
value: void 0
|
|
1833
|
-
};
|
|
1834
|
-
const fn = (...parameters) => {
|
|
1835
|
-
if (state.cleared) return Promise.reject(new Error(ONCE_MESSAGE_CLEARED));
|
|
1836
|
-
if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
|
|
1837
|
-
if (state.called) return new Promise((resolve, reject) => {
|
|
1838
|
-
state.items.push({
|
|
1839
|
-
reject,
|
|
1840
|
-
resolve
|
|
1841
|
-
});
|
|
1842
|
-
});
|
|
1843
|
-
state.called = true;
|
|
1844
|
-
return new Promise((resolve, reject) => {
|
|
1845
|
-
state.items.push({
|
|
1846
|
-
reject,
|
|
1847
|
-
resolve
|
|
1848
|
-
});
|
|
1849
|
-
callback(...parameters).then((value) => {
|
|
1850
|
-
handleOnceResult(state, value, false);
|
|
1851
|
-
}).catch((error) => {
|
|
1852
|
-
handleOnceResult(state, error, true);
|
|
1853
|
-
});
|
|
1854
|
-
});
|
|
1855
|
-
};
|
|
1856
|
-
Object.defineProperties(fn, {
|
|
1857
|
-
called: {
|
|
1858
|
-
enumerable: true,
|
|
1859
|
-
get: () => state.called
|
|
1860
|
-
},
|
|
1861
|
-
clear: { value: () => clearState(state) },
|
|
1862
|
-
cleared: {
|
|
1863
|
-
enumerable: true,
|
|
1864
|
-
get: () => state.cleared
|
|
1865
|
-
},
|
|
1866
|
-
error: {
|
|
1867
|
-
enumerable: true,
|
|
1868
|
-
get: () => state.error
|
|
1869
|
-
},
|
|
1870
|
-
finished: {
|
|
1871
|
-
enumerable: true,
|
|
1872
|
-
get: () => state.finished
|
|
1873
|
-
}
|
|
1874
|
-
});
|
|
1875
|
-
return fn;
|
|
1929
|
+
return new AsyncOnce(callback);
|
|
1876
1930
|
}
|
|
1877
|
-
function
|
|
1931
|
+
function clearOnce() {
|
|
1932
|
+
const state = this[ONCE_SYMBOL];
|
|
1878
1933
|
if (!state.called || state.cleared) return;
|
|
1934
|
+
state.callback = void 0;
|
|
1879
1935
|
state.cleared = true;
|
|
1880
1936
|
state.value = void 0;
|
|
1881
1937
|
}
|
|
@@ -1892,6 +1948,27 @@ function handleOnceResult(state, value, error) {
|
|
|
1892
1948
|
}
|
|
1893
1949
|
}
|
|
1894
1950
|
/**
|
|
1951
|
+
* Is the value an asynchronous once callback?
|
|
1952
|
+
*
|
|
1953
|
+
* @param value Value to check
|
|
1954
|
+
* @returns `true` if the value is an asynchronous once callback, otherwise `false`
|
|
1955
|
+
*/
|
|
1956
|
+
function isAsyncOnce(value) {
|
|
1957
|
+
return isOnceInstance(value, ONCE_NAME_ASYNC);
|
|
1958
|
+
}
|
|
1959
|
+
/**
|
|
1960
|
+
* Is the value a once callback?
|
|
1961
|
+
*
|
|
1962
|
+
* @param value Value to check
|
|
1963
|
+
* @returns `true` if the value is a once callback, otherwise `false`
|
|
1964
|
+
*/
|
|
1965
|
+
function isOnce(value) {
|
|
1966
|
+
return isOnceInstance(value, ONCE_NAME_SYNC);
|
|
1967
|
+
}
|
|
1968
|
+
function isOnceInstance(value, name) {
|
|
1969
|
+
return typeof value === "object" && value !== null && ONCE_PROPERTY in value && value[ONCE_PROPERTY] === name;
|
|
1970
|
+
}
|
|
1971
|
+
/**
|
|
1895
1972
|
* Create a function that can only be called once, returning the same value on subsequent calls
|
|
1896
1973
|
*
|
|
1897
1974
|
* @param callback Callback to use once
|
|
@@ -1899,35 +1976,52 @@ function handleOnceResult(state, value, error) {
|
|
|
1899
1976
|
*/
|
|
1900
1977
|
function once(callback) {
|
|
1901
1978
|
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1979
|
+
return new Once(callback);
|
|
1980
|
+
}
|
|
1981
|
+
function runOnce(...parameters) {
|
|
1982
|
+
const state = this[ONCE_SYMBOL];
|
|
1983
|
+
if (state.cleared) throw new Error(ONCE_MESSAGE_CLEARED);
|
|
1984
|
+
if (state.called) return state.value;
|
|
1985
|
+
state.called = true;
|
|
1986
|
+
state.value = state.callback(...parameters);
|
|
1987
|
+
return state.value;
|
|
1988
|
+
}
|
|
1989
|
+
function runOnceAsync(...parameters) {
|
|
1990
|
+
const state = this[ONCE_SYMBOL];
|
|
1991
|
+
if (state.cleared) return Promise.reject(new Error(ONCE_MESSAGE_CLEARED));
|
|
1992
|
+
if (state.finished) return state.error ? Promise.reject(state.value) : Promise.resolve(state.value);
|
|
1993
|
+
if (state.called) return new Promise((resolve, reject) => {
|
|
1994
|
+
state.items.push({
|
|
1995
|
+
reject,
|
|
1996
|
+
resolve
|
|
1997
|
+
});
|
|
1998
|
+
});
|
|
1999
|
+
state.called = true;
|
|
2000
|
+
return new Promise((resolve, reject) => {
|
|
2001
|
+
state.items.push({
|
|
2002
|
+
reject,
|
|
2003
|
+
resolve
|
|
2004
|
+
});
|
|
2005
|
+
state.callback(...parameters).then((value) => {
|
|
2006
|
+
handleOnceResult(state, value, false);
|
|
2007
|
+
}).catch((error) => {
|
|
2008
|
+
handleOnceResult(state, error, true);
|
|
2009
|
+
});
|
|
1924
2010
|
});
|
|
1925
|
-
return fn;
|
|
1926
2011
|
}
|
|
1927
2012
|
const ONCE_MESSAGE_CLEARED = "Once has been cleared";
|
|
1928
2013
|
const ONCE_MESSAGE_EXPECTATION = "Once expected a function";
|
|
2014
|
+
const ONCE_SYMBOL = Symbol(ONCE_PROPERTY);
|
|
2015
|
+
asyncOnce.is = isAsyncOnce;
|
|
1929
2016
|
once.async = asyncOnce;
|
|
1930
|
-
|
|
2017
|
+
once.is = isOnce;
|
|
2018
|
+
once.isAsync = isAsyncOnce;
|
|
2019
|
+
Object.defineProperty(asyncOnce, "is", { value: isAsyncOnce });
|
|
2020
|
+
Object.defineProperties(once, {
|
|
2021
|
+
async: { value: asyncOnce },
|
|
2022
|
+
is: { value: isOnce },
|
|
2023
|
+
isAsync: { value: isAsyncOnce }
|
|
2024
|
+
});
|
|
1931
2025
|
//#endregion
|
|
1932
2026
|
//#region src/function/retry.ts
|
|
1933
2027
|
/**
|
|
@@ -1960,12 +2054,12 @@ async function asyncRetry(callback, options) {
|
|
|
1960
2054
|
if (attempts >= times || !when(error)) rejector(new RetryError(RETRY_MESSAGE_FAILED, error));
|
|
1961
2055
|
else {
|
|
1962
2056
|
attempts += 1;
|
|
1963
|
-
|
|
2057
|
+
limiter.run();
|
|
1964
2058
|
}
|
|
1965
2059
|
}
|
|
1966
2060
|
}
|
|
1967
2061
|
const { delay, times, when } = createRetryOptions(options);
|
|
1968
|
-
const
|
|
2062
|
+
const limiter = getLimiter(LIMITER_WAIT, handle, delay);
|
|
1969
2063
|
let attempts = 0;
|
|
1970
2064
|
let rejector;
|
|
1971
2065
|
let resolver;
|
|
@@ -2211,6 +2305,48 @@ var SizedMap = class extends Map {
|
|
|
2211
2305
|
};
|
|
2212
2306
|
//#endregion
|
|
2213
2307
|
//#region src/internal/function/memoize.ts
|
|
2308
|
+
const MEMOIZED_PROPERTY = "$memoized";
|
|
2309
|
+
function Memoized(callback, options) {
|
|
2310
|
+
Object.defineProperty(this, MEMOIZED_SYMBOL, { value: {
|
|
2311
|
+
options,
|
|
2312
|
+
cache: new SizedMap(options.cacheSize),
|
|
2313
|
+
getter: void 0
|
|
2314
|
+
} });
|
|
2315
|
+
this[MEMOIZED_SYMBOL].getter = createGetter(this[MEMOIZED_SYMBOL], callback);
|
|
2316
|
+
Object.defineProperties(this, {
|
|
2317
|
+
maximum: {
|
|
2318
|
+
enumerable: true,
|
|
2319
|
+
get: () => this[MEMOIZED_SYMBOL].cache.maximum
|
|
2320
|
+
},
|
|
2321
|
+
size: {
|
|
2322
|
+
enumerable: true,
|
|
2323
|
+
get: () => this[MEMOIZED_SYMBOL].cache.size
|
|
2324
|
+
}
|
|
2325
|
+
});
|
|
2326
|
+
}
|
|
2327
|
+
Object.defineProperties(Memoized.prototype, {
|
|
2328
|
+
[MEMOIZED_PROPERTY]: { value: true },
|
|
2329
|
+
clear: { value: clearMemoized },
|
|
2330
|
+
delete: { value: deleteMemoizedValue },
|
|
2331
|
+
get: { value: getMemoizedValue },
|
|
2332
|
+
has: { value: hasMemoizedValue },
|
|
2333
|
+
run: { value: runMemoized }
|
|
2334
|
+
});
|
|
2335
|
+
function clearMemoized() {
|
|
2336
|
+
this[MEMOIZED_SYMBOL].cache.clear();
|
|
2337
|
+
}
|
|
2338
|
+
function deleteMemoizedValue(key) {
|
|
2339
|
+
return this[MEMOIZED_SYMBOL].cache.delete(key);
|
|
2340
|
+
}
|
|
2341
|
+
function createGetter(state, callback) {
|
|
2342
|
+
return (...parameters) => {
|
|
2343
|
+
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), MEMOIZED_KEY_SEPARATOR));
|
|
2344
|
+
if (state.cache.has(key)) return state.cache.get(key);
|
|
2345
|
+
const value = callback(...parameters);
|
|
2346
|
+
state.cache.set(key, value);
|
|
2347
|
+
return value;
|
|
2348
|
+
};
|
|
2349
|
+
}
|
|
2214
2350
|
function createMemoizationOptions(input) {
|
|
2215
2351
|
const { cacheKey, cacheSize } = isPlainObject(input) ? input : {};
|
|
2216
2352
|
return {
|
|
@@ -2218,6 +2354,12 @@ function createMemoizationOptions(input) {
|
|
|
2218
2354
|
cacheSize: getNumberOrDefault(cacheSize, MEMOIZED_CACHE_SIZE_DEFAULT)
|
|
2219
2355
|
};
|
|
2220
2356
|
}
|
|
2357
|
+
function getMemoizedValue(key) {
|
|
2358
|
+
return this[MEMOIZED_SYMBOL].cache.get(key);
|
|
2359
|
+
}
|
|
2360
|
+
function hasMemoizedValue(key) {
|
|
2361
|
+
return this[MEMOIZED_SYMBOL].cache.has(key);
|
|
2362
|
+
}
|
|
2221
2363
|
/**
|
|
2222
2364
|
* Memoize a function, caching and retrieving results based on the first parameter
|
|
2223
2365
|
*
|
|
@@ -2227,41 +2369,15 @@ function createMemoizationOptions(input) {
|
|
|
2227
2369
|
*/
|
|
2228
2370
|
function memoize(callback, options) {
|
|
2229
2371
|
if (typeof callback !== "function") throw new TypeError(MEMOIZED_CALLBACK);
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
};
|
|
2235
|
-
state.cache = new SizedMap(state.options.cacheSize);
|
|
2236
|
-
state.getter = (...parameters) => {
|
|
2237
|
-
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), MEMOIZED_KEY_SEPARATOR));
|
|
2238
|
-
if (state.cache.has(key)) return state.cache.get(key);
|
|
2239
|
-
const value = callback(...parameters);
|
|
2240
|
-
state.cache.set(key, value);
|
|
2241
|
-
return value;
|
|
2242
|
-
};
|
|
2243
|
-
const instance = {
|
|
2244
|
-
clear: () => state.cache.clear(),
|
|
2245
|
-
delete: (key) => state.cache.delete(key),
|
|
2246
|
-
get: (key) => state.cache.get(key),
|
|
2247
|
-
has: (key) => state.cache.has(key),
|
|
2248
|
-
run: (...parameters) => state.getter(...parameters)
|
|
2249
|
-
};
|
|
2250
|
-
Object.defineProperties(instance, {
|
|
2251
|
-
maximum: {
|
|
2252
|
-
enumerable: true,
|
|
2253
|
-
get: () => state.cache.maximum
|
|
2254
|
-
},
|
|
2255
|
-
size: {
|
|
2256
|
-
enumerable: true,
|
|
2257
|
-
get: () => state.cache.size
|
|
2258
|
-
}
|
|
2259
|
-
});
|
|
2260
|
-
return Object.freeze(instance);
|
|
2372
|
+
return new Memoized(callback, createMemoizationOptions(options));
|
|
2373
|
+
}
|
|
2374
|
+
function runMemoized(...parameters) {
|
|
2375
|
+
return this[MEMOIZED_SYMBOL].getter(...parameters);
|
|
2261
2376
|
}
|
|
2262
2377
|
const MEMOIZED_CACHE_SIZE_DEFAULT = 1024;
|
|
2263
2378
|
const MEMOIZED_CALLBACK = "Memoized requires a callback function";
|
|
2264
2379
|
const MEMOIZED_KEY_SEPARATOR = "_";
|
|
2380
|
+
const MEMOIZED_SYMBOL = Symbol(MEMOIZED_PROPERTY);
|
|
2265
2381
|
//#endregion
|
|
2266
2382
|
//#region src/internal/string/case.ts
|
|
2267
2383
|
/**
|
|
@@ -2399,6 +2515,17 @@ let memoizedTitleCase;
|
|
|
2399
2515
|
let memoizedUpperCase;
|
|
2400
2516
|
//#endregion
|
|
2401
2517
|
//#region src/internal/value/equal.ts
|
|
2518
|
+
function Equalizer(options) {
|
|
2519
|
+
Object.defineProperty(this, EQUAL_SYMBOL, { value: options });
|
|
2520
|
+
}
|
|
2521
|
+
Object.defineProperties(Equalizer.prototype, {
|
|
2522
|
+
compare: { value: compare$1 },
|
|
2523
|
+
deregister: { value: deregisterEqualizer },
|
|
2524
|
+
register: { value: registerEqualizer }
|
|
2525
|
+
});
|
|
2526
|
+
function compare$1(first, second) {
|
|
2527
|
+
return equalValue(first, second, this[EQUAL_SYMBOL]);
|
|
2528
|
+
}
|
|
2402
2529
|
function createEqualOptions(input) {
|
|
2403
2530
|
const options = {
|
|
2404
2531
|
ignoreCase: false,
|
|
@@ -2433,7 +2560,7 @@ function createEqualOptions(input) {
|
|
|
2433
2560
|
* @param constructor Class constructor
|
|
2434
2561
|
*/
|
|
2435
2562
|
function deregisterEqualizer(constructor) {
|
|
2436
|
-
|
|
2563
|
+
equalHandler.base.deregister(constructor);
|
|
2437
2564
|
}
|
|
2438
2565
|
function filterKey(key, options) {
|
|
2439
2566
|
if (typeof key !== "string") return true;
|
|
@@ -2444,10 +2571,6 @@ function filterKey(key, options) {
|
|
|
2444
2571
|
function equal(first, second, options) {
|
|
2445
2572
|
return equalValue(first, second, createEqualOptions(options));
|
|
2446
2573
|
}
|
|
2447
|
-
equal.handlers = createCompareHandlers(equal, { callback: Object.is });
|
|
2448
|
-
equal.deregister = deregisterEqualizer;
|
|
2449
|
-
equal.initialize = initializeEqualizer;
|
|
2450
|
-
equal.register = registerEqualizer;
|
|
2451
2574
|
function equalArray(first, second, options) {
|
|
2452
2575
|
const { length } = first;
|
|
2453
2576
|
if (length !== second.length) return false;
|
|
@@ -2536,7 +2659,7 @@ function equalValue(first, second, options) {
|
|
|
2536
2659
|
case Array.isArray(first) && Array.isArray(second): return equalArray(first, second, options);
|
|
2537
2660
|
case isPlainObject(first) && isPlainObject(second): return equalPlainObject(first, second, options);
|
|
2538
2661
|
case isTypedArray(first) && isTypedArray(second): return equalTypedArray(first, second);
|
|
2539
|
-
default: return
|
|
2662
|
+
default: return equalHandler.handle(first, second, options);
|
|
2540
2663
|
}
|
|
2541
2664
|
}
|
|
2542
2665
|
/**
|
|
@@ -2548,11 +2671,7 @@ function equalValue(first, second, options) {
|
|
|
2548
2671
|
* @returns Equalizer function
|
|
2549
2672
|
*/
|
|
2550
2673
|
function initializeEqualizer(options) {
|
|
2551
|
-
|
|
2552
|
-
const equalizer = (first, second) => equalValue(first, second, actual);
|
|
2553
|
-
equalizer.deregister = deregisterEqualizer;
|
|
2554
|
-
equalizer.register = registerEqualizer;
|
|
2555
|
-
return equalizer;
|
|
2674
|
+
return new Equalizer(createEqualOptions(options));
|
|
2556
2675
|
}
|
|
2557
2676
|
/**
|
|
2558
2677
|
* Register a equality comparison function for a specific class
|
|
@@ -2563,13 +2682,25 @@ function initializeEqualizer(options) {
|
|
|
2563
2682
|
* @param handler Comparison function
|
|
2564
2683
|
*/
|
|
2565
2684
|
function registerEqualizer(constructor, handler) {
|
|
2566
|
-
|
|
2685
|
+
equalHandler.base.register(constructor, handler);
|
|
2567
2686
|
}
|
|
2568
2687
|
const EQUAL_ARRAY_PEEK_PERCENTAGE = 10;
|
|
2569
2688
|
const EQUAL_ARRAY_THRESHOLD = 100;
|
|
2570
2689
|
const EQUAL_ERROR_PROPERTIES = ["name", "message"];
|
|
2571
2690
|
const EQUAL_EXPRESSION_PROPERTIES = ["source", "flags"];
|
|
2572
2691
|
const EQUAL_MINIMUM_LENGTH_FOR_SET = 16;
|
|
2692
|
+
const EQUAL_SYMBOL = Symbol("equal");
|
|
2693
|
+
const equalHandler = createCompareHandler(equal, { callback: Object.is });
|
|
2694
|
+
equal.deregister = deregisterEqualizer;
|
|
2695
|
+
equal.handler = equalHandler;
|
|
2696
|
+
equal.initialize = initializeEqualizer;
|
|
2697
|
+
equal.register = registerEqualizer;
|
|
2698
|
+
Object.defineProperties(equal, {
|
|
2699
|
+
deregister: { value: deregisterEqualizer },
|
|
2700
|
+
handler: { value: equalHandler },
|
|
2701
|
+
initialize: { value: initializeEqualizer },
|
|
2702
|
+
register: { value: registerEqualizer }
|
|
2703
|
+
});
|
|
2573
2704
|
//#endregion
|
|
2574
2705
|
//#region src/internal/value/get.ts
|
|
2575
2706
|
function getValue(data, path, ignoreCase) {
|
|
@@ -2785,34 +2916,34 @@ function delay(options) {
|
|
|
2785
2916
|
const { signal, time } = createPromiseOptions(options);
|
|
2786
2917
|
if (signal?.aborted ?? false) return Promise.reject(signal?.reason);
|
|
2787
2918
|
const aborter = createAborter(signal, () => {
|
|
2788
|
-
|
|
2919
|
+
limiter.cancel();
|
|
2789
2920
|
rejector(signal?.reason);
|
|
2790
2921
|
});
|
|
2791
|
-
const
|
|
2922
|
+
const limiter = getLimiter(LIMITER_WAIT, () => settlePromise(resolver, void 0, aborter), time);
|
|
2792
2923
|
let rejector;
|
|
2793
2924
|
let resolver;
|
|
2794
2925
|
return new Promise((resolve, reject) => {
|
|
2795
2926
|
rejector = reject;
|
|
2796
2927
|
resolver = resolve;
|
|
2797
2928
|
if (time === 0) settlePromise(resolver, void 0, aborter);
|
|
2798
|
-
else
|
|
2929
|
+
else limiter.run();
|
|
2799
2930
|
});
|
|
2800
2931
|
}
|
|
2801
2932
|
//#endregion
|
|
2802
2933
|
//#region src/promise/timed.ts
|
|
2803
2934
|
async function getTimedPromise(promise, time, signal) {
|
|
2804
2935
|
const aborter = createAborter(signal, () => {
|
|
2805
|
-
|
|
2936
|
+
limiter.cancel();
|
|
2806
2937
|
rejector(signal?.reason);
|
|
2807
2938
|
});
|
|
2808
|
-
const
|
|
2939
|
+
const limiter = getLimiter(LIMITER_WAIT, () => settlePromise(rejector, new PromiseTimeoutError(), aborter), time);
|
|
2809
2940
|
let rejector;
|
|
2810
2941
|
return Promise.race([promise, new Promise((_, reject) => {
|
|
2811
2942
|
rejector = reject;
|
|
2812
|
-
|
|
2943
|
+
limiter.run();
|
|
2813
2944
|
})]).then((value) => {
|
|
2814
2945
|
aborter?.cancel();
|
|
2815
|
-
|
|
2946
|
+
limiter.cancel();
|
|
2816
2947
|
rejector(void 0);
|
|
2817
2948
|
return value;
|
|
2818
2949
|
});
|
|
@@ -3035,6 +3166,30 @@ const MATCH_STARTS_WITH = "startsWith";
|
|
|
3035
3166
|
const matchMemoizers = {};
|
|
3036
3167
|
//#endregion
|
|
3037
3168
|
//#region src/string/fuzzy.ts
|
|
3169
|
+
const FUZZY_PROPERTY = "$fuzzy";
|
|
3170
|
+
const FUZZY_SYMBOL = Symbol(FUZZY_PROPERTY);
|
|
3171
|
+
function Fuzzy(state) {
|
|
3172
|
+
Object.defineProperty(this, FUZZY_SYMBOL, { value: state });
|
|
3173
|
+
}
|
|
3174
|
+
Object.defineProperties(Fuzzy.prototype, {
|
|
3175
|
+
[FUZZY_PROPERTY]: { value: true },
|
|
3176
|
+
items: {
|
|
3177
|
+
enumerable: true,
|
|
3178
|
+
get() {
|
|
3179
|
+
return this[FUZZY_SYMBOL].items.slice();
|
|
3180
|
+
},
|
|
3181
|
+
set(value) {
|
|
3182
|
+
setItems(this[FUZZY_SYMBOL], value);
|
|
3183
|
+
}
|
|
3184
|
+
},
|
|
3185
|
+
search: { value: search },
|
|
3186
|
+
strings: {
|
|
3187
|
+
enumerable: true,
|
|
3188
|
+
get() {
|
|
3189
|
+
return this[FUZZY_SYMBOL].strings.slice();
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
});
|
|
3038
3193
|
function createFuzzyOptions(input, state) {
|
|
3039
3194
|
const options = isPlainObject(input) ? input : {};
|
|
3040
3195
|
const limit = typeof input === "number" ? input : options.limit;
|
|
@@ -3054,43 +3209,13 @@ function createFuzzyState(items, input) {
|
|
|
3054
3209
|
tolerance: options.tolerance
|
|
3055
3210
|
};
|
|
3056
3211
|
}
|
|
3057
|
-
function getHandler(input) {
|
|
3058
|
-
if (input == null || input === getString) return getString;
|
|
3059
|
-
switch (typeof input) {
|
|
3060
|
-
case "function": return input;
|
|
3061
|
-
case "string": return (item) => item[input];
|
|
3062
|
-
default:
|
|
3063
|
-
if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
|
|
3064
|
-
throw new TypeError(FUZZY_MESSAGE_HANDLER);
|
|
3065
|
-
}
|
|
3066
|
-
}
|
|
3067
|
-
function getFuzzyItems(items) {
|
|
3068
|
-
return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
3069
|
-
}
|
|
3070
|
-
function getTolerance(input, state) {
|
|
3071
|
-
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
|
|
3072
|
-
return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
|
|
3073
|
-
}
|
|
3074
3212
|
function fuzzy(items, configuration) {
|
|
3075
3213
|
if (!Array.isArray(items)) throw new TypeError(FUZZY_MESSAGE_ARRAY);
|
|
3076
|
-
|
|
3077
|
-
const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : createFuzzyOptions(options, state)) };
|
|
3078
|
-
Object.defineProperties(instance, {
|
|
3079
|
-
items: {
|
|
3080
|
-
enumerable: true,
|
|
3081
|
-
get: () => state.items.slice(),
|
|
3082
|
-
set: (value) => setItems(state, value)
|
|
3083
|
-
},
|
|
3084
|
-
strings: {
|
|
3085
|
-
enumerable: true,
|
|
3086
|
-
get: () => state.strings.slice()
|
|
3087
|
-
}
|
|
3088
|
-
});
|
|
3089
|
-
return Object.freeze(instance);
|
|
3214
|
+
return new Fuzzy(createFuzzyState(items, configuration));
|
|
3090
3215
|
}
|
|
3091
3216
|
/**
|
|
3092
3217
|
* Does the needle match the haystack in a fuzzy way?
|
|
3093
|
-
*
|
|
3218
|
+
*
|
|
3094
3219
|
* _Available as `fuzzyMatch` and `fuzzy.match`_
|
|
3095
3220
|
*
|
|
3096
3221
|
* @param haystack Haystack to search through
|
|
@@ -3103,20 +3228,21 @@ function fuzzyMatch(haystack, needle) {
|
|
|
3103
3228
|
if (includes(haystack, trimmed, true)) return true;
|
|
3104
3229
|
return getScore(haystack, trimmed) > -1;
|
|
3105
3230
|
}
|
|
3106
|
-
function
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
}
|
|
3118
|
-
|
|
3119
|
-
|
|
3231
|
+
function getHandler(input) {
|
|
3232
|
+
if (input == null || input === getString) return getString;
|
|
3233
|
+
switch (typeof input) {
|
|
3234
|
+
case "function": return input;
|
|
3235
|
+
case "string": return (item) => item[input];
|
|
3236
|
+
default:
|
|
3237
|
+
if (isPlainObject(input)) return getHandler(input.key ?? input.handler);
|
|
3238
|
+
throw new TypeError(FUZZY_MESSAGE_HANDLER);
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
function getFuzzyItems(items) {
|
|
3242
|
+
return items.sort((first, second) => first.haystack.localeCompare(second.haystack)).map(({ item }) => item);
|
|
3243
|
+
}
|
|
3244
|
+
function getScore(haystack, needle) {
|
|
3245
|
+
if (!isSubsequence(haystack, needle)) return -1;
|
|
3120
3246
|
const lowerCaseHaystack = lowerCase(haystack);
|
|
3121
3247
|
const lowerCaseNeedle = lowerCase(needle);
|
|
3122
3248
|
const needleLength = lowerCaseNeedle.length;
|
|
@@ -3139,23 +3265,52 @@ function getScore(haystack, needle) {
|
|
|
3139
3265
|
score -= Math.floor(lowerCaseHaystack.length / FUZZY_LENGTH_DIVISOR);
|
|
3140
3266
|
return Math.max(0, score);
|
|
3141
3267
|
}
|
|
3142
|
-
function
|
|
3268
|
+
function getTolerance(input, state) {
|
|
3269
|
+
if (typeof input === "number" && !Number.isNaN(input)) return input < 0 ? 0 : Math.floor(input);
|
|
3270
|
+
return state?.tolerance ?? FUZZY_PROXIMITY_THRESHOLD;
|
|
3271
|
+
}
|
|
3272
|
+
/**
|
|
3273
|
+
* Is the value a fuzzy searcher?
|
|
3274
|
+
*
|
|
3275
|
+
* _Available as `isFuzzy` and `fuzzy.is`_
|
|
3276
|
+
*
|
|
3277
|
+
* @param value Value to check
|
|
3278
|
+
* @returns `true` if the value is a fuzzy searcher, otherwise `false`
|
|
3279
|
+
*/
|
|
3280
|
+
function isFuzzy(value) {
|
|
3281
|
+
return typeof value === "object" && value !== null && FUZZY_PROPERTY in value && value[FUZZY_PROPERTY] === true;
|
|
3282
|
+
}
|
|
3283
|
+
function isSubsequence(haystack, needle) {
|
|
3284
|
+
const lowerCaseHaystack = lowerCase(haystack);
|
|
3285
|
+
const lowerCaseNeedle = lowerCase(needle);
|
|
3286
|
+
const haystackLength = lowerCaseHaystack.length;
|
|
3287
|
+
const needleLength = lowerCaseNeedle.length;
|
|
3288
|
+
let needleIndex = 0;
|
|
3289
|
+
for (let haystackIndex = 0; haystackIndex < haystackLength; haystackIndex += 1) {
|
|
3290
|
+
if (lowerCaseHaystack[haystackIndex] === lowerCaseNeedle[needleIndex]) needleIndex += 1;
|
|
3291
|
+
if (needleIndex === needleLength) return true;
|
|
3292
|
+
}
|
|
3293
|
+
return false;
|
|
3294
|
+
}
|
|
3295
|
+
function search(input, option) {
|
|
3296
|
+
const state = this[FUZZY_SYMBOL];
|
|
3297
|
+
const options = option == null ? state : createFuzzyOptions(option, state);
|
|
3143
3298
|
const result = {
|
|
3144
3299
|
exact: [],
|
|
3145
3300
|
similar: []
|
|
3146
3301
|
};
|
|
3147
3302
|
const value = typeof input === "string" ? input.trim() : "";
|
|
3148
3303
|
if (value.length === 0) {
|
|
3149
|
-
result.exact = items.slice(0, options.limit);
|
|
3304
|
+
result.exact = state.items.slice(0, options.limit);
|
|
3150
3305
|
return result;
|
|
3151
3306
|
}
|
|
3152
|
-
let { length } = items;
|
|
3307
|
+
let { length } = state.items;
|
|
3153
3308
|
const exact = [];
|
|
3154
3309
|
const similar = [];
|
|
3155
3310
|
const scored = {};
|
|
3156
3311
|
for (let index = 0; index < length; index += 1) {
|
|
3157
|
-
const item = items[index];
|
|
3158
|
-
const haystack = strings[index];
|
|
3312
|
+
const item = state.items[index];
|
|
3313
|
+
const haystack = state.strings[index];
|
|
3159
3314
|
if (includes(haystack, value, true)) {
|
|
3160
3315
|
exact.push({
|
|
3161
3316
|
item,
|
|
@@ -3196,8 +3351,12 @@ const FUZZY_LENGTH_DIVISOR = 3;
|
|
|
3196
3351
|
const FUZZY_MESSAGE_ARRAY = "Fuzzy requires an array of items";
|
|
3197
3352
|
const FUZZY_MESSAGE_HANDLER = "Fuzzy requires a key or function to stringify items";
|
|
3198
3353
|
const FUZZY_PROXIMITY_THRESHOLD = 5;
|
|
3354
|
+
fuzzy.is = isFuzzy;
|
|
3199
3355
|
fuzzy.match = fuzzyMatch;
|
|
3200
|
-
Object.
|
|
3356
|
+
Object.defineProperties(fuzzy, {
|
|
3357
|
+
is: { value: isFuzzy },
|
|
3358
|
+
match: { value: fuzzyMatch }
|
|
3359
|
+
});
|
|
3201
3360
|
//#endregion
|
|
3202
3361
|
//#region src/string/index.ts
|
|
3203
3362
|
function dedent(value, ...values) {
|
|
@@ -3294,6 +3453,10 @@ const STRING_NUMERICAL_PREFIX_PATTERN = /^\d/;
|
|
|
3294
3453
|
const STRING_ZERO = "0";
|
|
3295
3454
|
//#endregion
|
|
3296
3455
|
//#region src/string/normalize.ts
|
|
3456
|
+
function Normalizer(options) {
|
|
3457
|
+
Object.defineProperty(this, NORMALIZE_SYMBOL, { value: options });
|
|
3458
|
+
}
|
|
3459
|
+
Object.defineProperties(Normalizer.prototype, { normalize: { value: normalizeString } });
|
|
3297
3460
|
function createNormalizeOptions(input) {
|
|
3298
3461
|
const options = isPlainObject(input) ? input : {};
|
|
3299
3462
|
return {
|
|
@@ -3328,8 +3491,7 @@ function deburr(value) {
|
|
|
3328
3491
|
* @returns Normalizer function
|
|
3329
3492
|
*/
|
|
3330
3493
|
function initializeNormalizer(options) {
|
|
3331
|
-
|
|
3332
|
-
return (value) => normalizeString(value, normalization);
|
|
3494
|
+
return new Normalizer(createNormalizeOptions(options));
|
|
3333
3495
|
}
|
|
3334
3496
|
/**
|
|
3335
3497
|
* Normalize a string
|
|
@@ -3341,10 +3503,11 @@ function initializeNormalizer(options) {
|
|
|
3341
3503
|
* @returns Normalized string
|
|
3342
3504
|
*/
|
|
3343
3505
|
function normalize(value, options) {
|
|
3344
|
-
return normalizeString(
|
|
3506
|
+
return normalizeString.call(createNormalizeOptions(options), value);
|
|
3345
3507
|
}
|
|
3346
|
-
function normalizeString(value
|
|
3508
|
+
function normalizeString(value) {
|
|
3347
3509
|
if (typeof value !== "string") return "";
|
|
3510
|
+
const options = NORMALIZE_SYMBOL in this ? this[NORMALIZE_SYMBOL] : this;
|
|
3348
3511
|
let result = value;
|
|
3349
3512
|
if (options.trim) result = result.trim();
|
|
3350
3513
|
if (options.whitespace) result = result.replace(NORMALIZE_WHITESPACE_PATTERN, NORMALIZE_WHITESPACE_REPLACEMENT);
|
|
@@ -3391,6 +3554,7 @@ const NORMALIZE_DEBURR_PATTERN_SIMPLE = /[\u0300-\u036f]/g;
|
|
|
3391
3554
|
const NORMALIZE_NORMALIZATION_NORMALIZATION = "NFC";
|
|
3392
3555
|
const NORMALIZE_SPECIAL_PATTERN = /[\p{P}\p{S}]/gu;
|
|
3393
3556
|
const NORMALIZE_SPECIAL_REPLACEMENT = "";
|
|
3557
|
+
const NORMALIZE_SYMBOL = Symbol("normalize");
|
|
3394
3558
|
const NORMALIZE_WHITESPACE_PATTERN = /\s+/g;
|
|
3395
3559
|
const NORMALIZE_WHITESPACE_REPLACEMENT = " ";
|
|
3396
3560
|
let deburrMemoizer;
|
|
@@ -3398,6 +3562,10 @@ normalize.initialize = initializeNormalizer;
|
|
|
3398
3562
|
Object.defineProperty(normalize, "initialize", { value: initializeNormalizer });
|
|
3399
3563
|
//#endregion
|
|
3400
3564
|
//#region src/string/template.ts
|
|
3565
|
+
function Templater(options) {
|
|
3566
|
+
Object.defineProperty(this, TEMPLATE_SYMBOL, { value: options });
|
|
3567
|
+
}
|
|
3568
|
+
Object.defineProperties(Templater.prototype, { render: { value: render } });
|
|
3401
3569
|
function createTemplateOptions(input) {
|
|
3402
3570
|
const options = isPlainObject(input) ? input : {};
|
|
3403
3571
|
return {
|
|
@@ -3431,10 +3599,12 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
|
3431
3599
|
* @returns _Templater_ function
|
|
3432
3600
|
*/
|
|
3433
3601
|
function initializeTemplater(options) {
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
}
|
|
3602
|
+
return new Templater(createTemplateOptions(options));
|
|
3603
|
+
}
|
|
3604
|
+
function render(value, ...parameters) {
|
|
3605
|
+
const { ignoreCase, pattern } = this[TEMPLATE_SYMBOL];
|
|
3606
|
+
if (isTemplateStringsArray(value)) return (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables);
|
|
3607
|
+
return handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
3438
3608
|
}
|
|
3439
3609
|
function template(value, ...parameters) {
|
|
3440
3610
|
if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
|
|
@@ -3442,11 +3612,20 @@ function template(value, ...parameters) {
|
|
|
3442
3612
|
return handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
3443
3613
|
}
|
|
3444
3614
|
const TEMPLATE_EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
3615
|
+
const TEMPLATE_SYMBOL = Symbol("template");
|
|
3445
3616
|
template.initialize = initializeTemplater;
|
|
3446
3617
|
Object.defineProperty(template, "initialize", { value: initializeTemplater });
|
|
3447
3618
|
//#endregion
|
|
3448
3619
|
//#region src/value/clone.ts
|
|
3449
3620
|
const CLONE_NAME = "clone";
|
|
3621
|
+
function Cloner(options) {
|
|
3622
|
+
Object.defineProperty(this, CLONE_SYMBOL, { value: options });
|
|
3623
|
+
}
|
|
3624
|
+
Object.defineProperties(Cloner.prototype, {
|
|
3625
|
+
clone: { value: cloneFromCloner },
|
|
3626
|
+
deregister: { value: deregisterCloner },
|
|
3627
|
+
register: { value: registerCloner }
|
|
3628
|
+
});
|
|
3450
3629
|
function clone(value, options) {
|
|
3451
3630
|
return cloneAny(value, { copy: false }, 0, options);
|
|
3452
3631
|
}
|
|
@@ -3490,6 +3669,12 @@ function cloneDataView(value, parameters, depth) {
|
|
|
3490
3669
|
parameters.references.set(value, cloned);
|
|
3491
3670
|
return cloned;
|
|
3492
3671
|
}
|
|
3672
|
+
function cloneFromCloner(value) {
|
|
3673
|
+
return cloneAny(value, {
|
|
3674
|
+
copy: false,
|
|
3675
|
+
options: this[CLONE_SYMBOL]
|
|
3676
|
+
}, 0);
|
|
3677
|
+
}
|
|
3493
3678
|
function cloneMap(map, parameters, depth) {
|
|
3494
3679
|
if (depth >= CLONE_MAX_DEPTH) return map;
|
|
3495
3680
|
if (parameters.copy) return new Map(map);
|
|
@@ -3561,7 +3746,7 @@ function createCloneOptions(input) {
|
|
|
3561
3746
|
* @param constructor Class constructor
|
|
3562
3747
|
*/
|
|
3563
3748
|
function deregisterCloner(constructor) {
|
|
3564
|
-
|
|
3749
|
+
cloneHandler.base.deregister(constructor);
|
|
3565
3750
|
}
|
|
3566
3751
|
/**
|
|
3567
3752
|
* Create a cloner with predefined options
|
|
@@ -3572,20 +3757,7 @@ function deregisterCloner(constructor) {
|
|
|
3572
3757
|
* @returns Cloner function
|
|
3573
3758
|
*/
|
|
3574
3759
|
function initializeCloner(options) {
|
|
3575
|
-
|
|
3576
|
-
function cloner(value) {
|
|
3577
|
-
return cloneAny(value, {
|
|
3578
|
-
copy: false,
|
|
3579
|
-
options: opts
|
|
3580
|
-
}, 0);
|
|
3581
|
-
}
|
|
3582
|
-
cloner.deregister = deregisterCloner;
|
|
3583
|
-
cloner.register = registerCloner;
|
|
3584
|
-
Object.defineProperties(cloner, {
|
|
3585
|
-
deregister: { value: deregisterCloner },
|
|
3586
|
-
register: { value: registerCloner }
|
|
3587
|
-
});
|
|
3588
|
-
return cloner;
|
|
3760
|
+
return new Cloner(createCloneOptions(options));
|
|
3589
3761
|
}
|
|
3590
3762
|
/**
|
|
3591
3763
|
* Register a clone handler for a specific class
|
|
@@ -3596,7 +3768,7 @@ function initializeCloner(options) {
|
|
|
3596
3768
|
* @param handler Method name or clone function _(defaults to method name `clone`)_
|
|
3597
3769
|
*/
|
|
3598
3770
|
function registerCloner(constructor, handler) {
|
|
3599
|
-
|
|
3771
|
+
cloneHandler.base.register(constructor, handler);
|
|
3600
3772
|
}
|
|
3601
3773
|
function tryStructuredClone(value, parameters, depth) {
|
|
3602
3774
|
if (depth >= CLONE_MAX_DEPTH) return value;
|
|
@@ -3618,7 +3790,7 @@ const CLONE_DEFAULT_OPTIONS = {
|
|
|
3618
3790
|
copySymbols: false
|
|
3619
3791
|
};
|
|
3620
3792
|
const CLONE_MAX_DEPTH = 100;
|
|
3621
|
-
const
|
|
3793
|
+
const cloneHandler = createValueHandler(clone, {
|
|
3622
3794
|
callback: tryStructuredClone,
|
|
3623
3795
|
method: CLONE_NAME
|
|
3624
3796
|
});
|
|
@@ -3632,13 +3804,14 @@ const CLONE_PRIMITIVES = {
|
|
|
3632
3804
|
symbol: false,
|
|
3633
3805
|
undefined: true
|
|
3634
3806
|
};
|
|
3807
|
+
const CLONE_SYMBOL = Symbol(CLONE_NAME);
|
|
3635
3808
|
clone.deregister = deregisterCloner;
|
|
3636
|
-
clone.handlers =
|
|
3809
|
+
clone.handlers = cloneHandler;
|
|
3637
3810
|
clone.initialize = initializeCloner;
|
|
3638
3811
|
clone.register = registerCloner;
|
|
3639
3812
|
Object.defineProperties(clone, {
|
|
3640
3813
|
deregister: { value: deregisterCloner },
|
|
3641
|
-
|
|
3814
|
+
handler: { value: cloneHandler },
|
|
3642
3815
|
initialize: { value: initializeCloner },
|
|
3643
3816
|
register: { value: registerCloner }
|
|
3644
3817
|
});
|
|
@@ -3834,7 +4007,7 @@ function freezeValue(value, references, flat) {
|
|
|
3834
4007
|
}
|
|
3835
4008
|
/**
|
|
3836
4009
|
* Is the value frozen?
|
|
3837
|
-
*
|
|
4010
|
+
*
|
|
3838
4011
|
* _Available as `isFrozen` and `freeze.is`_
|
|
3839
4012
|
*
|
|
3840
4013
|
* @param value Value to check
|
|
@@ -3983,6 +4156,17 @@ function unsmush(value) {
|
|
|
3983
4156
|
}
|
|
3984
4157
|
//#endregion
|
|
3985
4158
|
//#region src/value/merge.ts
|
|
4159
|
+
function Assigner(options) {
|
|
4160
|
+
Object.defineProperty(this, MERGE_SYMBOL_ASSIGN, { value: {
|
|
4161
|
+
...options,
|
|
4162
|
+
assignValues: true
|
|
4163
|
+
} });
|
|
4164
|
+
}
|
|
4165
|
+
Object.defineProperties(Assigner.prototype, { assign: { value: assignFromAssigner } });
|
|
4166
|
+
function Merger(options) {
|
|
4167
|
+
Object.defineProperty(this, MERGE_SYMBOL_MERGE, { value: options });
|
|
4168
|
+
}
|
|
4169
|
+
Object.defineProperties(Merger.prototype, { merge: { value: mergeFromMerger } });
|
|
3986
4170
|
/**
|
|
3987
4171
|
* Assign values from one or more objects to the first one
|
|
3988
4172
|
*
|
|
@@ -3996,6 +4180,9 @@ function assign(to, from, options) {
|
|
|
3996
4180
|
actual.assignValues = true;
|
|
3997
4181
|
return mergeValues([to, ...from], actual);
|
|
3998
4182
|
}
|
|
4183
|
+
function assignFromAssigner(to, from) {
|
|
4184
|
+
return mergeValues([to, ...from], this[MERGE_SYMBOL_ASSIGN]);
|
|
4185
|
+
}
|
|
3999
4186
|
function createMergeOptions(options) {
|
|
4000
4187
|
const actual = {
|
|
4001
4188
|
assignValues: false,
|
|
@@ -4024,9 +4211,7 @@ function getReplaceableObjects(value) {
|
|
|
4024
4211
|
* @returns Assigner function
|
|
4025
4212
|
*/
|
|
4026
4213
|
function initializeAssigner(options) {
|
|
4027
|
-
|
|
4028
|
-
actual.assignValues = true;
|
|
4029
|
-
return ((to, from) => mergeValues([to, ...from], actual));
|
|
4214
|
+
return new Assigner(createMergeOptions(options));
|
|
4030
4215
|
}
|
|
4031
4216
|
/**
|
|
4032
4217
|
* Create a merger with predefined options
|
|
@@ -4037,8 +4222,7 @@ function initializeAssigner(options) {
|
|
|
4037
4222
|
* @returns Merger function
|
|
4038
4223
|
*/
|
|
4039
4224
|
function initializeMerger(options) {
|
|
4040
|
-
|
|
4041
|
-
return ((values) => mergeValues(values, actual));
|
|
4225
|
+
return new Merger(createMergeOptions(options));
|
|
4042
4226
|
}
|
|
4043
4227
|
/**
|
|
4044
4228
|
* Merge multiple arrays or objects into a single one
|
|
@@ -4050,6 +4234,9 @@ function initializeMerger(options) {
|
|
|
4050
4234
|
function merge(values, options) {
|
|
4051
4235
|
return mergeValues(values, createMergeOptions(options));
|
|
4052
4236
|
}
|
|
4237
|
+
function mergeFromMerger(values) {
|
|
4238
|
+
return mergeValues(values, this[MERGE_SYMBOL_MERGE]);
|
|
4239
|
+
}
|
|
4053
4240
|
function mergeObjects(values, options, destination, prefix) {
|
|
4054
4241
|
const { length } = values;
|
|
4055
4242
|
const isArray = Array.isArray(destination ?? values[0]);
|
|
@@ -4079,13 +4266,19 @@ function mergeValues(values, options, prefix) {
|
|
|
4079
4266
|
if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
|
|
4080
4267
|
return options.assignValues ? actual[0] : Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
|
|
4081
4268
|
}
|
|
4269
|
+
const MERGE_SYMBOL_ASSIGN = Symbol("assign");
|
|
4270
|
+
const MERGE_SYMBOL_MERGE = Symbol("merge");
|
|
4082
4271
|
assign.initialize = initializeAssigner;
|
|
4083
4272
|
merge.initialize = initializeMerger;
|
|
4084
4273
|
Object.defineProperty(assign, "initialize", { value: initializeAssigner });
|
|
4085
4274
|
Object.defineProperty(merge, "initialize", { value: initializeMerger });
|
|
4086
4275
|
//#endregion
|
|
4087
4276
|
//#region src/value/transform.ts
|
|
4088
|
-
function
|
|
4277
|
+
function Transformer(transformer) {
|
|
4278
|
+
Object.defineProperty(this, TRANSFORM_SYMBOL, { value: transformer });
|
|
4279
|
+
}
|
|
4280
|
+
Object.defineProperties(Transformer.prototype, { transform: { value: transformValue } });
|
|
4281
|
+
function getTransformHandler(input) {
|
|
4089
4282
|
if (typeof input === "function") return input;
|
|
4090
4283
|
if (isNonPlainObject(input)) return;
|
|
4091
4284
|
const keys = Object.keys(input);
|
|
@@ -4096,18 +4289,18 @@ function getTransformer(input) {
|
|
|
4096
4289
|
const value = input[key];
|
|
4097
4290
|
if (typeof value === "function") transformer[key] = value;
|
|
4098
4291
|
}
|
|
4099
|
-
|
|
4292
|
+
return Object.keys(transformer).length > 0 ? transformer : void 0;
|
|
4100
4293
|
}
|
|
4101
4294
|
function initializeTransformer(transform) {
|
|
4102
|
-
|
|
4103
|
-
return (value) => transformValue(value, transformer);
|
|
4295
|
+
return new Transformer(getTransformHandler(transform));
|
|
4104
4296
|
}
|
|
4105
4297
|
function transform(value, transform) {
|
|
4106
|
-
return transformValue(
|
|
4298
|
+
return transformValue.call(getTransformHandler(transform), value);
|
|
4107
4299
|
}
|
|
4108
|
-
function transformValue(value
|
|
4300
|
+
function transformValue(value) {
|
|
4109
4301
|
if (isNonPlainObject(value)) return {};
|
|
4110
|
-
if (
|
|
4302
|
+
if (this == null) return value;
|
|
4303
|
+
const transformer = TRANSFORM_SYMBOL in this ? this[TRANSFORM_SYMBOL] : this;
|
|
4111
4304
|
const keys = Object.keys(value);
|
|
4112
4305
|
const { length } = keys;
|
|
4113
4306
|
for (let index = 0; index < length; index += 1) {
|
|
@@ -4118,17 +4311,59 @@ function transformValue(value, transformer) {
|
|
|
4118
4311
|
}
|
|
4119
4312
|
return value;
|
|
4120
4313
|
}
|
|
4314
|
+
const TRANSFORM_SYMBOL = Symbol("transform");
|
|
4121
4315
|
transform.initialize = initializeTransformer;
|
|
4122
4316
|
Object.defineProperty(transform, "initialize", { value: initializeTransformer });
|
|
4123
4317
|
//#endregion
|
|
4124
4318
|
//#region src/internal/subscription.ts
|
|
4125
|
-
|
|
4126
|
-
|
|
4319
|
+
const SUBSCRIPTION_NAME = "subscription";
|
|
4320
|
+
const SUBSCRIPTION_PROPERTY = "$subscription";
|
|
4321
|
+
const SUBSCRIPTION_STORE = "subscriptions";
|
|
4322
|
+
function Subscription(state, property, parameters) {
|
|
4323
|
+
Object.defineProperty(this, SUBSCRIPTION_SYMBOL, { value: state });
|
|
4324
|
+
state.aborter = createAborter(parameters.signal, () => this.unsubscribe(subscriptions, this, state));
|
|
4325
|
+
Object.defineProperties(this, {
|
|
4326
|
+
[property.key]: { value: property.value },
|
|
4327
|
+
active: {
|
|
4328
|
+
enumerable: true,
|
|
4329
|
+
get: () => (state.parameters?.isActive?.() ?? true) && state.active
|
|
4330
|
+
}
|
|
4331
|
+
});
|
|
4332
|
+
addSubscription(this);
|
|
4333
|
+
}
|
|
4334
|
+
Object.defineProperties(Subscription.prototype, {
|
|
4335
|
+
[SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
|
|
4336
|
+
unsubscribe: { value: removeSubscription }
|
|
4337
|
+
});
|
|
4338
|
+
function Subscriptions(parameters) {
|
|
4339
|
+
const { keys, property } = createSubscriptionsParameters(parameters);
|
|
4340
|
+
Object.defineProperty(this, SUBSCRIPTION_SYMBOL, { value: createSubscriptionsState(property, keys) });
|
|
4341
|
+
}
|
|
4342
|
+
Object.defineProperties(Subscriptions.prototype, {
|
|
4343
|
+
[SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
|
|
4344
|
+
clear: { value: clearSubscriptions },
|
|
4345
|
+
create: { value: createSubscription },
|
|
4346
|
+
items: {
|
|
4347
|
+
enumerable: true,
|
|
4348
|
+
get() {
|
|
4349
|
+
return this[SUBSCRIPTION_SYMBOL].items;
|
|
4350
|
+
}
|
|
4351
|
+
},
|
|
4352
|
+
values: {
|
|
4353
|
+
enumerable: true,
|
|
4354
|
+
get() {
|
|
4355
|
+
return this[SUBSCRIPTION_SYMBOL].values;
|
|
4356
|
+
}
|
|
4357
|
+
}
|
|
4358
|
+
});
|
|
4359
|
+
function addSubscription(instance) {
|
|
4360
|
+
const state = instance[SUBSCRIPTION_SYMBOL];
|
|
4127
4361
|
const { key, value } = state.parameters;
|
|
4362
|
+
const { items, values } = state.subscriptions;
|
|
4128
4363
|
if (!isKey(key)) {
|
|
4129
|
-
items.any.add(
|
|
4130
|
-
values.from.any.set(value,
|
|
4131
|
-
values.to.any.set(
|
|
4364
|
+
items.any.add(instance);
|
|
4365
|
+
values.from.any.set(value, instance);
|
|
4366
|
+
values.to.any.set(instance, value);
|
|
4132
4367
|
return;
|
|
4133
4368
|
}
|
|
4134
4369
|
/* istanbul ignore if */
|
|
@@ -4140,29 +4375,32 @@ function addSubscription(subscriptions, subscription, state) {
|
|
|
4140
4375
|
keyedItems = /* @__PURE__ */ new Set();
|
|
4141
4376
|
items.keyed.set(key, keyedItems);
|
|
4142
4377
|
}
|
|
4143
|
-
keyedItems.add(
|
|
4378
|
+
keyedItems.add(instance);
|
|
4144
4379
|
let keyedFrom = values.from.keyed.get(key);
|
|
4145
4380
|
if (keyedFrom == null) {
|
|
4146
4381
|
keyedFrom = /* @__PURE__ */ new Map();
|
|
4147
4382
|
values.from.keyed.set(key, keyedFrom);
|
|
4148
4383
|
}
|
|
4149
|
-
keyedFrom.set(value,
|
|
4384
|
+
keyedFrom.set(value, instance);
|
|
4150
4385
|
let keyedTo = values.to.keyed.get(key);
|
|
4151
4386
|
if (keyedTo == null) {
|
|
4152
4387
|
keyedTo = /* @__PURE__ */ new Map();
|
|
4153
4388
|
values.to.keyed.set(key, keyedTo);
|
|
4154
4389
|
}
|
|
4155
|
-
keyedTo.set(
|
|
4390
|
+
keyedTo.set(instance, value);
|
|
4156
4391
|
}
|
|
4157
|
-
function clearSubscriptions(
|
|
4158
|
-
|
|
4159
|
-
|
|
4392
|
+
function clearSubscriptions() {
|
|
4393
|
+
const state = this[SUBSCRIPTION_SYMBOL];
|
|
4394
|
+
for (const susbcription of state.values.to.any.keys()) susbcription.unsubscribe();
|
|
4395
|
+
if (state.values.to.keyed != null && state.values.to.keyed.size > 0) for (const values of state.values.to.keyed.values()) for (const susbcription of values.keys()) susbcription.unsubscribe();
|
|
4160
4396
|
}
|
|
4161
|
-
function createSubscription(
|
|
4397
|
+
function createSubscription(params) {
|
|
4162
4398
|
const parameters = createSubscriptionParameters(params);
|
|
4163
4399
|
if (parameters.signal?.aborted ?? false) throw new Error(parameters.signal?.reason);
|
|
4400
|
+
const subscriptions = this[SUBSCRIPTION_SYMBOL];
|
|
4164
4401
|
const state = {
|
|
4165
4402
|
parameters,
|
|
4403
|
+
subscriptions,
|
|
4166
4404
|
active: true
|
|
4167
4405
|
};
|
|
4168
4406
|
const existing = getExistingSubscription(subscriptions, state);
|
|
@@ -4171,18 +4409,7 @@ function createSubscription(subscriptions, property, params) {
|
|
|
4171
4409
|
if (subscriptions.keys === false) throw new Error(SUBSCRIPTION_DISALLOWED_KEY);
|
|
4172
4410
|
else if (subscriptions.keys !== true && !subscriptions.keys.has(parameters.key)) throw new Error(SUBSCRIPTION_INVALID_KEY);
|
|
4173
4411
|
}
|
|
4174
|
-
|
|
4175
|
-
const instance = { unsubscribe: () => unsubscribe(subscriptions, instance, state) };
|
|
4176
|
-
Object.defineProperties(instance, {
|
|
4177
|
-
[SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_NAME },
|
|
4178
|
-
[property.key]: { value: property.value },
|
|
4179
|
-
active: {
|
|
4180
|
-
enumerable: true,
|
|
4181
|
-
get: () => (parameters.isActive?.() ?? true) && state.active
|
|
4182
|
-
}
|
|
4183
|
-
});
|
|
4184
|
-
addSubscription(subscriptions, instance, state);
|
|
4185
|
-
return [Object.freeze(instance), false];
|
|
4412
|
+
return [new Subscription(state, subscriptions.property, parameters), false];
|
|
4186
4413
|
}
|
|
4187
4414
|
function getExistingSubscription(subscriptions, state) {
|
|
4188
4415
|
const { values } = subscriptions;
|
|
@@ -4216,9 +4443,10 @@ function createSubscriptionsProperty(input) {
|
|
|
4216
4443
|
value: values.value == null ? SUBSCRIPTION_NAME : values.value
|
|
4217
4444
|
};
|
|
4218
4445
|
}
|
|
4219
|
-
function createSubscriptionsState(keys) {
|
|
4446
|
+
function createSubscriptionsState(property, keys) {
|
|
4220
4447
|
return {
|
|
4221
4448
|
keys,
|
|
4449
|
+
property,
|
|
4222
4450
|
items: {
|
|
4223
4451
|
any: /* @__PURE__ */ new Set(),
|
|
4224
4452
|
keyed: keys === false ? void 0 : /* @__PURE__ */ new Map()
|
|
@@ -4245,7 +4473,7 @@ function isSubscription(value) {
|
|
|
4245
4473
|
return isSubscriptionInstance(value, SUBSCRIPTION_NAME);
|
|
4246
4474
|
}
|
|
4247
4475
|
function isSubscriptionInstance(value, name) {
|
|
4248
|
-
return
|
|
4476
|
+
return typeof value === "object" && value !== null && SUBSCRIPTION_PROPERTY in value && value[SUBSCRIPTION_PROPERTY] === name;
|
|
4249
4477
|
}
|
|
4250
4478
|
/**
|
|
4251
4479
|
* Is the value a subscriptions store?
|
|
@@ -4266,16 +4494,17 @@ function removeFromStore(items, values, subscription, value, key) {
|
|
|
4266
4494
|
values.to.keyed?.get(key)?.delete(subscription);
|
|
4267
4495
|
}
|
|
4268
4496
|
}
|
|
4269
|
-
function removeSubscription(
|
|
4497
|
+
function removeSubscription() {
|
|
4498
|
+
const state = this[SUBSCRIPTION_SYMBOL];
|
|
4270
4499
|
if (!state.active) return;
|
|
4271
4500
|
state.aborter = void 0;
|
|
4272
4501
|
state.active = false;
|
|
4273
|
-
|
|
4274
|
-
state.parameters.signal = void 0;
|
|
4275
|
-
const { items, values } = subscriptionsState;
|
|
4502
|
+
const { items, values } = state.subscriptions;
|
|
4276
4503
|
const { key, value } = state.parameters;
|
|
4504
|
+
state.parameters = void 0;
|
|
4505
|
+
state.subscriptions = void 0;
|
|
4277
4506
|
if (!isKey(key)) {
|
|
4278
|
-
removeFromStore(items.any, values,
|
|
4507
|
+
removeFromStore(items.any, values, this, value);
|
|
4279
4508
|
return;
|
|
4280
4509
|
}
|
|
4281
4510
|
const keyed = items.keyed?.get(key);
|
|
@@ -4283,7 +4512,7 @@ function removeSubscription(subscriptionsState, subscription, state) {
|
|
|
4283
4512
|
if (items.keyed == null || keyed == null)
|
|
4284
4513
|
// istanbul ignore next
|
|
4285
4514
|
return;
|
|
4286
|
-
removeFromStore(keyed, values,
|
|
4515
|
+
removeFromStore(keyed, values, this, value, key);
|
|
4287
4516
|
if (keyed.size === 0) items.keyed.delete(key);
|
|
4288
4517
|
}
|
|
4289
4518
|
/**
|
|
@@ -4293,37 +4522,67 @@ function removeSubscription(subscriptionsState, subscription, state) {
|
|
|
4293
4522
|
* @returns Subscription store
|
|
4294
4523
|
*/
|
|
4295
4524
|
function subscriptions(parameters) {
|
|
4296
|
-
|
|
4297
|
-
const state = createSubscriptionsState(keys);
|
|
4298
|
-
const instance = {
|
|
4299
|
-
clear: () => clearSubscriptions(state),
|
|
4300
|
-
create: (parameters) => createSubscription(state, property, parameters)
|
|
4301
|
-
};
|
|
4302
|
-
Object.defineProperties(instance, {
|
|
4303
|
-
[SUBSCRIPTION_PROPERTY]: { value: SUBSCRIPTION_STORE },
|
|
4304
|
-
items: {
|
|
4305
|
-
enumerable: true,
|
|
4306
|
-
value: state.items
|
|
4307
|
-
},
|
|
4308
|
-
values: {
|
|
4309
|
-
enumerable: true,
|
|
4310
|
-
value: state.values
|
|
4311
|
-
}
|
|
4312
|
-
});
|
|
4313
|
-
return Object.freeze(instance);
|
|
4314
|
-
}
|
|
4315
|
-
function unsubscribe(subscriptionsState, subscription, state) {
|
|
4316
|
-
state.aborter?.cancel();
|
|
4317
|
-
removeSubscription(subscriptionsState, subscription, state);
|
|
4525
|
+
return new Subscriptions(parameters);
|
|
4318
4526
|
}
|
|
4319
4527
|
const SUBSCRIPTION_DISALLOWED_KEY = "Disallowed key for subscription";
|
|
4320
4528
|
const SUBSCRIPTION_INVALID_KEY = "Invalid key for subscription";
|
|
4321
4529
|
const SUBSCRIPTION_INVALID_VALUE = "A subscription requires a non-null value to identify it";
|
|
4322
|
-
const
|
|
4323
|
-
const SUBSCRIPTION_PROPERTY = "$subscriptions";
|
|
4324
|
-
const SUBSCRIPTION_STORE = "subscriptions";
|
|
4530
|
+
const SUBSCRIPTION_SYMBOL = Symbol(SUBSCRIPTION_PROPERTY);
|
|
4325
4531
|
//#endregion
|
|
4326
4532
|
//#region src/beacon.ts
|
|
4533
|
+
const BEACON_PROPERTY = "$beacon";
|
|
4534
|
+
const BEACON_NAME = "beacon";
|
|
4535
|
+
const BEACON_OBSERVABLE = "observable";
|
|
4536
|
+
function Beacon(value, options) {
|
|
4537
|
+
Object.defineProperty(this, BEACON_SYMBOL, { value: {
|
|
4538
|
+
value,
|
|
4539
|
+
active: true,
|
|
4540
|
+
options: createBeaconOptions(options)
|
|
4541
|
+
} });
|
|
4542
|
+
}
|
|
4543
|
+
Object.defineProperties(Beacon.prototype, {
|
|
4544
|
+
[BEACON_PROPERTY]: { value: BEACON_NAME },
|
|
4545
|
+
active: {
|
|
4546
|
+
enumerable: true,
|
|
4547
|
+
get() {
|
|
4548
|
+
return this[BEACON_SYMBOL].active;
|
|
4549
|
+
}
|
|
4550
|
+
},
|
|
4551
|
+
deactivate: { value: deactivateBeacon },
|
|
4552
|
+
emit: { value: emitBeaconValue },
|
|
4553
|
+
error: { value: emitBeaconError },
|
|
4554
|
+
finish: { value: finishBeacon },
|
|
4555
|
+
observable: {
|
|
4556
|
+
enumerable: true,
|
|
4557
|
+
get() {
|
|
4558
|
+
return getObservable(this[BEACON_SYMBOL]);
|
|
4559
|
+
}
|
|
4560
|
+
},
|
|
4561
|
+
value: {
|
|
4562
|
+
enumerable: true,
|
|
4563
|
+
get() {
|
|
4564
|
+
return this[BEACON_SYMBOL].value;
|
|
4565
|
+
}
|
|
4566
|
+
}
|
|
4567
|
+
});
|
|
4568
|
+
function Observable(beacon) {
|
|
4569
|
+
Object.defineProperty(this, BEACON_SYMBOL, { value: {
|
|
4570
|
+
beacon,
|
|
4571
|
+
active: beacon.active
|
|
4572
|
+
} });
|
|
4573
|
+
}
|
|
4574
|
+
Object.defineProperties(Observable.prototype, {
|
|
4575
|
+
[BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
|
|
4576
|
+
active: {
|
|
4577
|
+
enumerable: true,
|
|
4578
|
+
get() {
|
|
4579
|
+
const state = this[BEACON_SYMBOL];
|
|
4580
|
+
return state.beacon.active && state.active;
|
|
4581
|
+
}
|
|
4582
|
+
},
|
|
4583
|
+
deactivate: { value: deactiveateObservable },
|
|
4584
|
+
subscribe: { value: subscribeToObservable }
|
|
4585
|
+
});
|
|
4327
4586
|
/**
|
|
4328
4587
|
* Create a new beacon
|
|
4329
4588
|
*
|
|
@@ -4332,61 +4591,24 @@ const SUBSCRIPTION_STORE = "subscriptions";
|
|
|
4332
4591
|
* @returns Beacon instance
|
|
4333
4592
|
*/
|
|
4334
4593
|
function beacon(value, options) {
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
};
|
|
4348
|
-
Object.defineProperties(instance, {
|
|
4349
|
-
[BEACON_PROPERTY]: { value: BEACON_NAME },
|
|
4350
|
-
active: {
|
|
4351
|
-
enumerable: true,
|
|
4352
|
-
get: () => state.active
|
|
4353
|
-
},
|
|
4354
|
-
observable: {
|
|
4355
|
-
enumerable: true,
|
|
4356
|
-
get: () => getObservable(state)
|
|
4357
|
-
},
|
|
4358
|
-
value: {
|
|
4359
|
-
enumerable: true,
|
|
4360
|
-
get: () => state.value
|
|
4361
|
-
}
|
|
4362
|
-
});
|
|
4363
|
-
return Object.freeze(instance);
|
|
4594
|
+
return new Beacon(value, options);
|
|
4595
|
+
}
|
|
4596
|
+
function closeBeacon(state, emit) {
|
|
4597
|
+
if (!state.active) return;
|
|
4598
|
+
state.active = false;
|
|
4599
|
+
const subscriptions = state.subscriptions?.values.to.any;
|
|
4600
|
+
if (subscriptions != null && subscriptions.size > 0) {
|
|
4601
|
+
for (const [, observer] of subscriptions) if (emit) observer.complete?.();
|
|
4602
|
+
}
|
|
4603
|
+
state.subscriptions?.clear();
|
|
4604
|
+
state.observable?.deactivate();
|
|
4605
|
+
state.observable = void 0;
|
|
4364
4606
|
}
|
|
4365
4607
|
function createBeaconOptions(input) {
|
|
4366
4608
|
const options = isPlainObject(input) ? input : {};
|
|
4367
4609
|
options.equal = typeof options.equal === "function" ? options.equal : Object.is;
|
|
4368
4610
|
return options;
|
|
4369
4611
|
}
|
|
4370
|
-
function createObservable(beacon) {
|
|
4371
|
-
const state = {
|
|
4372
|
-
beacon,
|
|
4373
|
-
active: beacon.active
|
|
4374
|
-
};
|
|
4375
|
-
const instance = {
|
|
4376
|
-
deactivate: () => {
|
|
4377
|
-
state.active = false;
|
|
4378
|
-
},
|
|
4379
|
-
subscribe: (first, second, third) => subscribeToObservable(state, first, second, third)
|
|
4380
|
-
};
|
|
4381
|
-
Object.defineProperties(instance, {
|
|
4382
|
-
[BEACON_PROPERTY]: { value: BEACON_OBSERVABLE },
|
|
4383
|
-
active: {
|
|
4384
|
-
enumerable: true,
|
|
4385
|
-
get: () => beacon.active && state.active
|
|
4386
|
-
}
|
|
4387
|
-
});
|
|
4388
|
-
return Object.freeze(instance);
|
|
4389
|
-
}
|
|
4390
4612
|
function createObserver(first, second, third) {
|
|
4391
4613
|
let observer = { next: noop };
|
|
4392
4614
|
if (typeof first === "function") observer = {
|
|
@@ -4401,17 +4623,24 @@ function createObserver(first, second, third) {
|
|
|
4401
4623
|
}
|
|
4402
4624
|
return observer;
|
|
4403
4625
|
}
|
|
4404
|
-
function
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4626
|
+
function deactivateBeacon() {
|
|
4627
|
+
closeBeacon(this[BEACON_SYMBOL], false);
|
|
4628
|
+
}
|
|
4629
|
+
function deactiveateObservable() {
|
|
4630
|
+
this[BEACON_SYMBOL].active = false;
|
|
4631
|
+
}
|
|
4632
|
+
function emitBeaconError(error, finish) {
|
|
4633
|
+
updateBeacon(this, BEACON_TYPE_ERROR, error, finish ?? false);
|
|
4634
|
+
}
|
|
4635
|
+
function emitBeaconValue(value, finish) {
|
|
4636
|
+
updateBeacon(this, BEACON_TYPE_NEXT, value, finish ?? false);
|
|
4637
|
+
}
|
|
4638
|
+
function finishBeacon() {
|
|
4639
|
+
closeBeacon(this[BEACON_SYMBOL], true);
|
|
4411
4640
|
}
|
|
4412
4641
|
function getObservable(state) {
|
|
4413
4642
|
if (!state.active) throw new Error(BEACON_MESSAGE_RETRIEVE);
|
|
4414
|
-
state.observable ??=
|
|
4643
|
+
state.observable ??= new Observable(state);
|
|
4415
4644
|
return state.observable;
|
|
4416
4645
|
}
|
|
4417
4646
|
function getObservableCallback(value) {
|
|
@@ -4427,7 +4656,7 @@ function isBeacon(value) {
|
|
|
4427
4656
|
return isBeaconInstance(BEACON_NAME, value);
|
|
4428
4657
|
}
|
|
4429
4658
|
function isBeaconInstance(name, value) {
|
|
4430
|
-
return
|
|
4659
|
+
return typeof value === "object" && value !== null && value[BEACON_PROPERTY] === name;
|
|
4431
4660
|
}
|
|
4432
4661
|
/**
|
|
4433
4662
|
* Is the value a beacon subscription?
|
|
@@ -4447,8 +4676,10 @@ function isBeaconSubscription(value) {
|
|
|
4447
4676
|
function isObservable(value) {
|
|
4448
4677
|
return isBeaconInstance(BEACON_OBSERVABLE, value);
|
|
4449
4678
|
}
|
|
4450
|
-
function subscribeToObservable(
|
|
4679
|
+
function subscribeToObservable(first, second, third) {
|
|
4680
|
+
const state = this[BEACON_SYMBOL];
|
|
4451
4681
|
if (!state.beacon.active || !state.active) throw new Error(BEACON_MESSAGE_SUBSCRIBE);
|
|
4682
|
+
state.beacon.subscriptions ??= subscriptions({ property: beaconSubscription });
|
|
4452
4683
|
const observer = createObserver(first, second, third);
|
|
4453
4684
|
const [subscription] = state.beacon.subscriptions.create({
|
|
4454
4685
|
isActive: () => state.beacon.active && state.active,
|
|
@@ -4457,20 +4688,20 @@ function subscribeToObservable(state, first, second, third) {
|
|
|
4457
4688
|
observer.next?.(state.beacon.value);
|
|
4458
4689
|
return subscription;
|
|
4459
4690
|
}
|
|
4460
|
-
function updateBeacon(
|
|
4691
|
+
function updateBeacon(instance, type, value, finish) {
|
|
4692
|
+
const state = instance[BEACON_SYMBOL];
|
|
4461
4693
|
if (!state.active) return;
|
|
4462
4694
|
if (type === BEACON_TYPE_NEXT) {
|
|
4463
4695
|
if (state.options.equal(state.value, value)) return;
|
|
4464
4696
|
state.value = value;
|
|
4465
4697
|
}
|
|
4466
|
-
|
|
4467
|
-
if (
|
|
4698
|
+
const subscriptions = state.subscriptions?.values.to.any;
|
|
4699
|
+
if (subscriptions != null && subscriptions.size > 0) for (const [, observer] of subscriptions) observer[type]?.(value);
|
|
4700
|
+
if (finish === true) closeBeacon(state, true);
|
|
4468
4701
|
}
|
|
4469
4702
|
const BEACON_MESSAGE_RETRIEVE = "Cannot retrieve observable from a closed beacon";
|
|
4470
4703
|
const BEACON_MESSAGE_SUBSCRIBE = "Cannot subscribe to a closed observable";
|
|
4471
|
-
const
|
|
4472
|
-
const BEACON_NAME = "beacon";
|
|
4473
|
-
const BEACON_OBSERVABLE = "observable";
|
|
4704
|
+
const BEACON_SYMBOL = Symbol(BEACON_PROPERTY);
|
|
4474
4705
|
const BEACON_TYPE_ERROR = "error";
|
|
4475
4706
|
const BEACON_TYPE_NEXT = "next";
|
|
4476
4707
|
const beaconSubscription = {
|
|
@@ -4479,11 +4710,34 @@ const beaconSubscription = {
|
|
|
4479
4710
|
};
|
|
4480
4711
|
//#endregion
|
|
4481
4712
|
//#region src/internal/herald.ts
|
|
4482
|
-
|
|
4483
|
-
|
|
4484
|
-
|
|
4485
|
-
|
|
4486
|
-
|
|
4713
|
+
const HERALD_NAME_EVENTS = "events";
|
|
4714
|
+
const HERALD_NAME_HERALD = "herald";
|
|
4715
|
+
const HERALD_PROPERTY = "$herald";
|
|
4716
|
+
function Events(herald, state) {
|
|
4717
|
+
for (const key of state.keys) Object.defineProperty(this, key, { value: (callback, signal) => herald.subscribe(key, callback, signal) });
|
|
4718
|
+
}
|
|
4719
|
+
Events.prototype[HERALD_PROPERTY] = HERALD_NAME_EVENTS;
|
|
4720
|
+
function Herald(state) {
|
|
4721
|
+
Object.defineProperty(this, HERALD_SYMBOL, { value: {
|
|
4722
|
+
state,
|
|
4723
|
+
events: new Events(this, state)
|
|
4724
|
+
} });
|
|
4725
|
+
}
|
|
4726
|
+
Object.defineProperties(Herald.prototype, {
|
|
4727
|
+
[HERALD_PROPERTY]: { value: HERALD_NAME_HERALD },
|
|
4728
|
+
clear: { value: clearHerald },
|
|
4729
|
+
emit: { value: emitForHerald },
|
|
4730
|
+
events: {
|
|
4731
|
+
enumerable: true,
|
|
4732
|
+
get() {
|
|
4733
|
+
return this[HERALD_SYMBOL].events;
|
|
4734
|
+
}
|
|
4735
|
+
},
|
|
4736
|
+
observed: { value: eventIsObserved },
|
|
4737
|
+
subscribe: { value: subscribeToHerald }
|
|
4738
|
+
});
|
|
4739
|
+
function clearHerald() {
|
|
4740
|
+
this[HERALD_SYMBOL].state.store.clear();
|
|
4487
4741
|
}
|
|
4488
4742
|
function createHeraldState(input) {
|
|
4489
4743
|
const options = isPlainObject(input) ? input : {};
|
|
@@ -4508,11 +4762,15 @@ function createHeraldSubscriptionProperty(input) {
|
|
|
4508
4762
|
value: property.value
|
|
4509
4763
|
};
|
|
4510
4764
|
}
|
|
4511
|
-
function emitForHerald(
|
|
4765
|
+
function emitForHerald(event, ...parameters) {
|
|
4766
|
+
const { state } = this[HERALD_SYMBOL];
|
|
4512
4767
|
const items = state.store.values.from.keyed?.get(event);
|
|
4513
4768
|
if (items == null || items.size === 0) return;
|
|
4514
4769
|
for (const [callback] of items) callback(...parameters);
|
|
4515
4770
|
}
|
|
4771
|
+
function eventIsObserved(event) {
|
|
4772
|
+
return (this[HERALD_SYMBOL].state.store.items.keyed?.get(event)?.size ?? 0) > 0;
|
|
4773
|
+
}
|
|
4516
4774
|
/**
|
|
4517
4775
|
* Create a _Herald_ for announcing named events
|
|
4518
4776
|
*
|
|
@@ -4521,21 +4779,7 @@ function emitForHerald(state, event, ...parameters) {
|
|
|
4521
4779
|
* @returns _Herald_ instance
|
|
4522
4780
|
*/
|
|
4523
4781
|
function herald(options) {
|
|
4524
|
-
|
|
4525
|
-
const instance = {
|
|
4526
|
-
clear: () => state.store.clear(),
|
|
4527
|
-
emit: (event, ...parameters) => emitForHerald(state, event, ...parameters),
|
|
4528
|
-
observed: (event) => (state.store.items.keyed?.get(event)?.size ?? 0) > 0,
|
|
4529
|
-
subscribe: (key, callback, signal) => subscribeToHerald(state, key, callback, signal)
|
|
4530
|
-
};
|
|
4531
|
-
Object.defineProperties(instance, {
|
|
4532
|
-
[HERALD_PROPERTY]: { value: HERALD_NAME_HERALD },
|
|
4533
|
-
events: {
|
|
4534
|
-
enumerable: true,
|
|
4535
|
-
value: createEvents(instance, state)
|
|
4536
|
-
}
|
|
4537
|
-
});
|
|
4538
|
-
return Object.freeze(instance);
|
|
4782
|
+
return new Herald(createHeraldState(options));
|
|
4539
4783
|
}
|
|
4540
4784
|
/**
|
|
4541
4785
|
* Is the value a herald?
|
|
@@ -4556,7 +4800,7 @@ function isHeraldEvents(value) {
|
|
|
4556
4800
|
return isHeraldInstance(HERALD_NAME_EVENTS, value);
|
|
4557
4801
|
}
|
|
4558
4802
|
function isHeraldInstance(name, value) {
|
|
4559
|
-
return
|
|
4803
|
+
return typeof value === "object" && value !== null && HERALD_PROPERTY in value && value[HERALD_PROPERTY] === name;
|
|
4560
4804
|
}
|
|
4561
4805
|
/**
|
|
4562
4806
|
* Is the value a herald subscription?
|
|
@@ -4567,7 +4811,8 @@ function isHeraldInstance(name, value) {
|
|
|
4567
4811
|
function isHeraldSubscription(value) {
|
|
4568
4812
|
return isSubscription(value) && value[HERALD_PROPERTY] === "subscription";
|
|
4569
4813
|
}
|
|
4570
|
-
function subscribeToHerald(
|
|
4814
|
+
function subscribeToHerald(key, callback, signal) {
|
|
4815
|
+
const { state } = this[HERALD_SYMBOL];
|
|
4571
4816
|
const [subscription, existing] = state.store.create({
|
|
4572
4817
|
key,
|
|
4573
4818
|
signal,
|
|
@@ -4576,12 +4821,10 @@ function subscribeToHerald(state, key, callback, signal) {
|
|
|
4576
4821
|
if (!existing) state.onCreate?.(key, callback, subscription);
|
|
4577
4822
|
return subscription;
|
|
4578
4823
|
}
|
|
4579
|
-
const HERALD_PROPERTY = "$herald";
|
|
4580
4824
|
const HERALD_MESSAGE_ARRAY = "Herald requires an array of event names.";
|
|
4581
4825
|
const HERALD_MESSAGE_ONCREATE = `Herald requires a valid onCreate callback for subscription creation`;
|
|
4582
4826
|
const HERALD_MESSAGE_PROPERTY = `Herald requires valid property information for subscription identification`;
|
|
4583
|
-
const
|
|
4584
|
-
const HERALD_NAME_HERALD = "herald";
|
|
4827
|
+
const HERALD_SYMBOL = Symbol(HERALD_PROPERTY);
|
|
4585
4828
|
const heraldSubscription = {
|
|
4586
4829
|
key: HERALD_PROPERTY,
|
|
4587
4830
|
value: SUBSCRIPTION_NAME
|
|
@@ -4656,7 +4899,9 @@ const COLOR_MAX = {
|
|
|
4656
4899
|
hex: 255,
|
|
4657
4900
|
percent: 100
|
|
4658
4901
|
};
|
|
4659
|
-
const
|
|
4902
|
+
const COLOR_NAME = "color";
|
|
4903
|
+
const COLOR_PROPERTY = "$color";
|
|
4904
|
+
const COLOR_SYMBOL = Symbol(COLOR_PROPERTY);
|
|
4660
4905
|
const COLOR_TYPE = {
|
|
4661
4906
|
all: void 0,
|
|
4662
4907
|
hex: "hex",
|
|
@@ -4691,6 +4936,10 @@ const COLOR_SRGB = {
|
|
|
4691
4936
|
luminanceRed: .2126,
|
|
4692
4937
|
luminanceThreshold: .625
|
|
4693
4938
|
};
|
|
4939
|
+
const colorSubscription = {
|
|
4940
|
+
key: COLOR_PROPERTY,
|
|
4941
|
+
value: SUBSCRIPTION_NAME
|
|
4942
|
+
};
|
|
4694
4943
|
//#endregion
|
|
4695
4944
|
//#region src/internal/math/misc.ts
|
|
4696
4945
|
/**
|
|
@@ -4893,7 +5142,7 @@ function isBytey(value) {
|
|
|
4893
5142
|
* @returns `true` if the value is a _Color_, otherwise `false`
|
|
4894
5143
|
*/
|
|
4895
5144
|
function isColor(value) {
|
|
4896
|
-
return
|
|
5145
|
+
return typeof value === "object" && value !== null && "$color" in value && value["$color"] === "color";
|
|
4897
5146
|
}
|
|
4898
5147
|
function isColorValue(obj, properties) {
|
|
4899
5148
|
if (typeof obj !== "object" || obj === null) return false;
|
|
@@ -5579,41 +5828,43 @@ function getDefaultColorState() {
|
|
|
5579
5828
|
origin: COLOR_TYPE.hex
|
|
5580
5829
|
};
|
|
5581
5830
|
}
|
|
5582
|
-
function setColorValue(
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
|
|
5588
|
-
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
changes.emit(
|
|
5592
|
-
|
|
5593
|
-
|
|
5594
|
-
|
|
5831
|
+
function setColorValue(instance, type, value, alpha) {
|
|
5832
|
+
const { changes, values } = instance[COLOR_SYMBOL];
|
|
5833
|
+
values.hex = void 0;
|
|
5834
|
+
values.hsl = void 0;
|
|
5835
|
+
values.hwb = void 0;
|
|
5836
|
+
values.rgb = void 0;
|
|
5837
|
+
values.origin = type;
|
|
5838
|
+
values[type] = value;
|
|
5839
|
+
if (alpha != null) values.alpha = getAlpha(alpha, type === COLOR_TYPE.hex);
|
|
5840
|
+
for (const type of COLOR_TYPE.all) if (changes.observed(type)) changes.emit(type, instance[type]);
|
|
5841
|
+
changes.emit(COLOR_TYPE.wildcard, instance);
|
|
5842
|
+
}
|
|
5843
|
+
function setHexColor(instance, value, alpha) {
|
|
5844
|
+
const { values } = instance[COLOR_SYMBOL];
|
|
5845
|
+
if (!isHexColor(value) || !alpha && value === values.hex) return;
|
|
5595
5846
|
const normalized = getNormalizedHex(value, true);
|
|
5596
|
-
setColorValue(
|
|
5847
|
+
setColorValue(instance, COLOR_TYPE.hex, normalized.slice(0, COLOR_LENGTHS.hexLong), alpha ? normalized.slice(COLOR_LENGTHS.hexLong) : void 0);
|
|
5597
5848
|
}
|
|
5598
|
-
function setHSLColor(
|
|
5849
|
+
function setHSLColor(instance, value, alpha) {
|
|
5599
5850
|
if (!isHslLike(value)) return;
|
|
5600
|
-
setColorValue(
|
|
5851
|
+
setColorValue(instance, COLOR_TYPE.hsl, {
|
|
5601
5852
|
hue: getDegrees(value.hue),
|
|
5602
5853
|
saturation: getPercentage(value.saturation),
|
|
5603
5854
|
lightness: getPercentage(value.lightness)
|
|
5604
5855
|
}, alpha ? value.alpha : void 0);
|
|
5605
5856
|
}
|
|
5606
|
-
function setHWBColor(
|
|
5857
|
+
function setHWBColor(instance, value, alpha) {
|
|
5607
5858
|
if (!isHwbLike(value)) return;
|
|
5608
|
-
setColorValue(
|
|
5859
|
+
setColorValue(instance, COLOR_TYPE.hwb, {
|
|
5609
5860
|
hue: getDegrees(value.hue),
|
|
5610
5861
|
whiteness: getPercentage(value.whiteness),
|
|
5611
5862
|
blackness: getPercentage(value.blackness)
|
|
5612
5863
|
}, alpha ? value.alpha : void 0);
|
|
5613
5864
|
}
|
|
5614
|
-
function setRGBColor(
|
|
5865
|
+
function setRGBColor(instance, value, alpha) {
|
|
5615
5866
|
if (!isRgbLike(value)) return;
|
|
5616
|
-
setColorValue(
|
|
5867
|
+
setColorValue(instance, COLOR_TYPE.rgb, {
|
|
5617
5868
|
red: getHexValue(value.red),
|
|
5618
5869
|
green: getHexValue(value.green),
|
|
5619
5870
|
blue: getHexValue(value.blue)
|
|
@@ -5627,82 +5878,152 @@ const getters = {
|
|
|
5627
5878
|
};
|
|
5628
5879
|
//#endregion
|
|
5629
5880
|
//#region src/color/misc/format.ts
|
|
5630
|
-
function formatHexColor(
|
|
5631
|
-
return `#${alpha === true ?
|
|
5881
|
+
function formatHexColor(alpha) {
|
|
5882
|
+
return `#${alpha === true ? this.hexa : this.hex}`;
|
|
5632
5883
|
}
|
|
5633
|
-
function formatHslColor(
|
|
5634
|
-
const {
|
|
5635
|
-
|
|
5884
|
+
function formatHslColor(alpha) {
|
|
5885
|
+
const { values } = this[COLOR_SYMBOL];
|
|
5886
|
+
const { hue, lightness, saturation } = getColorFromState(values, COLOR_TYPE.hsl);
|
|
5887
|
+
return `hsl(${hue}deg ${saturation}% ${lightness}%${getSuffix(values, alpha)})`;
|
|
5636
5888
|
}
|
|
5637
|
-
function formatHwbColor(
|
|
5638
|
-
const {
|
|
5639
|
-
|
|
5889
|
+
function formatHwbColor(alpha) {
|
|
5890
|
+
const { values } = this[COLOR_SYMBOL];
|
|
5891
|
+
const { blackness, hue, whiteness } = getColorFromState(values, COLOR_TYPE.hwb);
|
|
5892
|
+
return `hwb(${hue}deg ${whiteness}% ${blackness}%${getSuffix(values, alpha)})`;
|
|
5640
5893
|
}
|
|
5641
|
-
function formatRgbColor(
|
|
5642
|
-
const {
|
|
5643
|
-
|
|
5894
|
+
function formatRgbColor(alpha) {
|
|
5895
|
+
const { values } = this[COLOR_SYMBOL];
|
|
5896
|
+
const { blue, green, red } = getColorFromState(values, COLOR_TYPE.rgb);
|
|
5897
|
+
return `rgb(${red} ${green} ${blue}${getSuffix(values, alpha)})`;
|
|
5644
5898
|
}
|
|
5645
5899
|
function getSuffix(state, alpha) {
|
|
5646
5900
|
return alpha === true ? ` / ${state.alpha.value}%` : "";
|
|
5647
5901
|
}
|
|
5648
5902
|
//#endregion
|
|
5649
5903
|
//#region src/color/instance.ts
|
|
5650
|
-
function
|
|
5651
|
-
|
|
5652
|
-
|
|
5653
|
-
|
|
5654
|
-
|
|
5655
|
-
|
|
5656
|
-
|
|
5657
|
-
|
|
5658
|
-
|
|
5659
|
-
|
|
5660
|
-
|
|
5661
|
-
|
|
5662
|
-
|
|
5663
|
-
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
Object.defineProperties(instance, {
|
|
5667
|
-
[COLOR_PROPERTY.name]: { value: true },
|
|
5668
|
-
alpha: {
|
|
5669
|
-
enumerable: true,
|
|
5670
|
-
get: () => state.alpha.value,
|
|
5671
|
-
set: (value) => setAlphaValue(state, value)
|
|
5904
|
+
function Color(value) {
|
|
5905
|
+
Object.defineProperty(this, COLOR_SYMBOL, { value: {
|
|
5906
|
+
changes: herald({
|
|
5907
|
+
names: [COLOR_TYPE.wildcard, ...COLOR_TYPE.all],
|
|
5908
|
+
property: colorSubscription,
|
|
5909
|
+
onCreate: (event, callback) => onCreateSubscription(this, event, callback)
|
|
5910
|
+
}),
|
|
5911
|
+
values: getColorState(value)
|
|
5912
|
+
} });
|
|
5913
|
+
}
|
|
5914
|
+
Object.defineProperties(Color.prototype, {
|
|
5915
|
+
[COLOR_PROPERTY]: { value: COLOR_NAME },
|
|
5916
|
+
alpha: {
|
|
5917
|
+
enumerable: true,
|
|
5918
|
+
get() {
|
|
5919
|
+
return this[COLOR_SYMBOL].values.alpha.value;
|
|
5672
5920
|
},
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5921
|
+
set(value) {
|
|
5922
|
+
setAlphaValue(this[COLOR_SYMBOL].values, value);
|
|
5923
|
+
}
|
|
5924
|
+
},
|
|
5925
|
+
changes: {
|
|
5926
|
+
enumerable: true,
|
|
5927
|
+
get() {
|
|
5928
|
+
return this[COLOR_SYMBOL].changes.events;
|
|
5929
|
+
}
|
|
5930
|
+
},
|
|
5931
|
+
hex: {
|
|
5932
|
+
enumerable: true,
|
|
5933
|
+
get() {
|
|
5934
|
+
return getColorValue(this, COLOR_TYPE.hex, false);
|
|
5676
5935
|
},
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5681
|
-
|
|
5682
|
-
|
|
5683
|
-
|
|
5684
|
-
|
|
5685
|
-
get: () => state.origin
|
|
5936
|
+
set(value) {
|
|
5937
|
+
setHexColor(this, value, false);
|
|
5938
|
+
}
|
|
5939
|
+
},
|
|
5940
|
+
hexa: {
|
|
5941
|
+
enumerable: true,
|
|
5942
|
+
get() {
|
|
5943
|
+
return getColorValue(this, COLOR_TYPE.hex, true);
|
|
5686
5944
|
},
|
|
5687
|
-
|
|
5688
|
-
|
|
5689
|
-
|
|
5690
|
-
|
|
5691
|
-
|
|
5692
|
-
function createColorProperty(space, color, state, changes, alpha) {
|
|
5693
|
-
const setValue = setters[space];
|
|
5694
|
-
return {
|
|
5945
|
+
set(value) {
|
|
5946
|
+
setHexColor(this, value, true);
|
|
5947
|
+
}
|
|
5948
|
+
},
|
|
5949
|
+
hsl: {
|
|
5695
5950
|
enumerable: true,
|
|
5696
|
-
get
|
|
5697
|
-
|
|
5698
|
-
|
|
5951
|
+
get() {
|
|
5952
|
+
return getColorValue(this, COLOR_TYPE.hsl, false);
|
|
5953
|
+
},
|
|
5954
|
+
set(value) {
|
|
5955
|
+
setHSLColor(this, value, false);
|
|
5956
|
+
}
|
|
5957
|
+
},
|
|
5958
|
+
hsla: {
|
|
5959
|
+
enumerable: true,
|
|
5960
|
+
get() {
|
|
5961
|
+
return getColorValue(this, COLOR_TYPE.hsl, true);
|
|
5962
|
+
},
|
|
5963
|
+
set(value) {
|
|
5964
|
+
setHSLColor(this, value, true);
|
|
5965
|
+
}
|
|
5966
|
+
},
|
|
5967
|
+
hwb: {
|
|
5968
|
+
enumerable: true,
|
|
5969
|
+
get() {
|
|
5970
|
+
return getColorValue(this, COLOR_TYPE.hwb, false);
|
|
5971
|
+
},
|
|
5972
|
+
set(value) {
|
|
5973
|
+
setHWBColor(this, value, false);
|
|
5974
|
+
}
|
|
5975
|
+
},
|
|
5976
|
+
hwba: {
|
|
5977
|
+
enumerable: true,
|
|
5978
|
+
get() {
|
|
5979
|
+
return getColorValue(this, COLOR_TYPE.hwb, true);
|
|
5980
|
+
},
|
|
5981
|
+
set(value) {
|
|
5982
|
+
setHWBColor(this, value, true);
|
|
5983
|
+
}
|
|
5984
|
+
},
|
|
5985
|
+
origin: {
|
|
5986
|
+
enumerable: true,
|
|
5987
|
+
get() {
|
|
5988
|
+
return this[COLOR_SYMBOL].values.origin;
|
|
5989
|
+
}
|
|
5990
|
+
},
|
|
5991
|
+
rgb: {
|
|
5992
|
+
enumerable: true,
|
|
5993
|
+
get() {
|
|
5994
|
+
return getColorValue(this, COLOR_TYPE.rgb, false);
|
|
5995
|
+
},
|
|
5996
|
+
set(value) {
|
|
5997
|
+
setRGBColor(this, value, false);
|
|
5998
|
+
}
|
|
5999
|
+
},
|
|
6000
|
+
rgba: {
|
|
6001
|
+
enumerable: true,
|
|
6002
|
+
get() {
|
|
6003
|
+
return getColorValue(this, COLOR_TYPE.rgb, true);
|
|
6004
|
+
},
|
|
6005
|
+
set(value) {
|
|
6006
|
+
setRGBColor(this, value, true);
|
|
6007
|
+
}
|
|
6008
|
+
},
|
|
6009
|
+
subscribe: { value: subscribeToColor },
|
|
6010
|
+
toHexString: { value: formatHexColor },
|
|
6011
|
+
toHslString: { value: formatHslColor },
|
|
6012
|
+
toHwbString: { value: formatHwbColor },
|
|
6013
|
+
toRgbString: { value: formatRgbColor },
|
|
6014
|
+
toString: { value: formatHexColor },
|
|
6015
|
+
unsubscribe: { value: unsubscribeFromColor }
|
|
6016
|
+
});
|
|
6017
|
+
function color(value) {
|
|
6018
|
+
return new Color(value);
|
|
5699
6019
|
}
|
|
5700
|
-
function getColorValue(
|
|
5701
|
-
const
|
|
5702
|
-
|
|
6020
|
+
function getColorValue(instance, type, alpha) {
|
|
6021
|
+
const { values } = instance[COLOR_SYMBOL];
|
|
6022
|
+
const value = getColorFromState(values, type);
|
|
6023
|
+
if (typeof value === "string") return alpha ? `${value}${values.alpha.hex}` : value;
|
|
5703
6024
|
return alpha ? {
|
|
5704
6025
|
...value,
|
|
5705
|
-
alpha:
|
|
6026
|
+
alpha: values.alpha.value
|
|
5706
6027
|
} : { ...value };
|
|
5707
6028
|
}
|
|
5708
6029
|
function onCreateSubscription(instance, event, callback) {
|
|
@@ -5714,16 +6035,13 @@ function onCreateSubscription(instance, event, callback) {
|
|
|
5714
6035
|
function setAlphaValue(state, value) {
|
|
5715
6036
|
if (typeof value === "number" && !Number.isNaN(value)) state.alpha = getAlpha(value, false);
|
|
5716
6037
|
}
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
}
|
|
5721
|
-
|
|
5722
|
-
|
|
5723
|
-
|
|
5724
|
-
hwb: setHWBColor,
|
|
5725
|
-
rgb: setRGBColor
|
|
5726
|
-
};
|
|
6038
|
+
function subscribeToColor(callback, signal) {
|
|
6039
|
+
const { changes } = this[COLOR_SYMBOL];
|
|
6040
|
+
return changes.subscribe(COLOR_TYPE.wildcard, callback, signal);
|
|
6041
|
+
}
|
|
6042
|
+
function unsubscribeFromColor() {
|
|
6043
|
+
this[COLOR_SYMBOL].changes.clear();
|
|
6044
|
+
}
|
|
5727
6045
|
//#endregion
|
|
5728
6046
|
//#region src/color/index.ts
|
|
5729
6047
|
/**
|
|
@@ -5859,46 +6177,73 @@ function isObject(value) {
|
|
|
5859
6177
|
const EXPRESSION_WHITESPACE = /^\s*$/;
|
|
5860
6178
|
//#endregion
|
|
5861
6179
|
//#region src/logger.ts
|
|
6180
|
+
const LOGGER_NAME = "Logger";
|
|
6181
|
+
const LOGGER_NAME_TIMED = "TimedLogger";
|
|
6182
|
+
const LOGGER_PROPERTY = "$logger";
|
|
6183
|
+
function Lumberjack() {
|
|
6184
|
+
for (const method of methods) {
|
|
6185
|
+
const bound = console[method].bind(console);
|
|
6186
|
+
Object.defineProperty(this, method, {
|
|
6187
|
+
enumerable: true,
|
|
6188
|
+
get() {
|
|
6189
|
+
return enabled ? bound : noop;
|
|
6190
|
+
}
|
|
6191
|
+
});
|
|
6192
|
+
}
|
|
6193
|
+
}
|
|
6194
|
+
Lumberjack.prototype[LOGGER_PROPERTY] = LOGGER_NAME;
|
|
6195
|
+
Object.defineProperties(Lumberjack.prototype, {
|
|
6196
|
+
enabled: {
|
|
6197
|
+
enumerable: true,
|
|
6198
|
+
get: () => enabled,
|
|
6199
|
+
set: (value) => {
|
|
6200
|
+
enabled = typeof value === "boolean" ? value : enabled;
|
|
6201
|
+
}
|
|
6202
|
+
},
|
|
6203
|
+
time: { value: (label) => new TimeLogger(getString(label)) }
|
|
6204
|
+
});
|
|
6205
|
+
function TimeLogger(label) {
|
|
6206
|
+
Object.defineProperty(this, LOGGER_SYMBOL, { value: {
|
|
6207
|
+
label,
|
|
6208
|
+
started: enabled,
|
|
6209
|
+
stopped: false
|
|
6210
|
+
} });
|
|
6211
|
+
this[LOGGER_SYMBOL].isActive = () => {
|
|
6212
|
+
return this[LOGGER_SYMBOL].started && !this[LOGGER_SYMBOL].stopped && enabled;
|
|
6213
|
+
};
|
|
6214
|
+
if (this[LOGGER_SYMBOL].started) console.time(label);
|
|
6215
|
+
}
|
|
6216
|
+
TimeLogger.prototype[LOGGER_PROPERTY] = LOGGER_NAME_TIMED;
|
|
6217
|
+
Object.defineProperties(TimeLogger.prototype, {
|
|
6218
|
+
active: {
|
|
6219
|
+
enumerable: true,
|
|
6220
|
+
get() {
|
|
6221
|
+
return this[LOGGER_SYMBOL].isActive();
|
|
6222
|
+
}
|
|
6223
|
+
},
|
|
6224
|
+
log: { get() {
|
|
6225
|
+
const state = this[LOGGER_SYMBOL];
|
|
6226
|
+
return state.isActive() ? console.timeLog.bind(console, state.label) : noop;
|
|
6227
|
+
} },
|
|
6228
|
+
stop: { get() {
|
|
6229
|
+
const state = this[LOGGER_SYMBOL];
|
|
6230
|
+
if (state.isActive()) {
|
|
6231
|
+
state.stopped = true;
|
|
6232
|
+
return console.timeEnd.bind(console, state.label);
|
|
6233
|
+
}
|
|
6234
|
+
return noop;
|
|
6235
|
+
} }
|
|
6236
|
+
});
|
|
5862
6237
|
function isLogger(value) {
|
|
5863
6238
|
return isLoggerInstance(LOGGER_NAME, value);
|
|
5864
6239
|
}
|
|
5865
6240
|
function isLoggerInstance(name, value) {
|
|
5866
6241
|
return typeof value === "object" && value !== null && value[LOGGER_PROPERTY] === name;
|
|
5867
6242
|
}
|
|
5868
|
-
function
|
|
6243
|
+
function isTimeLogger(value) {
|
|
5869
6244
|
return isLoggerInstance(LOGGER_NAME_TIMED, value);
|
|
5870
6245
|
}
|
|
5871
|
-
|
|
5872
|
-
function stop() {
|
|
5873
|
-
const fn = stopper;
|
|
5874
|
-
state.stopped = true;
|
|
5875
|
-
logger = void 0;
|
|
5876
|
-
stopper = void 0;
|
|
5877
|
-
return fn;
|
|
5878
|
-
}
|
|
5879
|
-
let logger = console.timeLog.bind(console, label);
|
|
5880
|
-
let stopper = console.timeEnd.bind(console, label);
|
|
5881
|
-
const state = {
|
|
5882
|
-
label,
|
|
5883
|
-
started: enabled,
|
|
5884
|
-
stopped: false
|
|
5885
|
-
};
|
|
5886
|
-
const instance = {};
|
|
5887
|
-
Object.defineProperties(instance, {
|
|
5888
|
-
[LOGGER_PROPERTY]: { value: LOGGER_NAME_TIMED },
|
|
5889
|
-
active: {
|
|
5890
|
-
enumerable: true,
|
|
5891
|
-
get: () => state.started && !state.stopped && enabled
|
|
5892
|
-
},
|
|
5893
|
-
log: { get: () => instance.active ? logger : noop },
|
|
5894
|
-
stop: { get: () => instance.active ? stop() : noop }
|
|
5895
|
-
});
|
|
5896
|
-
if (state.started) console.time(label);
|
|
5897
|
-
return Object.freeze(instance);
|
|
5898
|
-
}
|
|
5899
|
-
const LOGGER_NAME = "Logger";
|
|
5900
|
-
const LOGGER_NAME_TIMED = "TimedLogger";
|
|
5901
|
-
const LOGGER_PROPERTY = "$logger";
|
|
6246
|
+
const LOGGER_SYMBOL = Symbol(LOGGER_PROPERTY);
|
|
5902
6247
|
const methods = [
|
|
5903
6248
|
"debug",
|
|
5904
6249
|
"dir",
|
|
@@ -5914,27 +6259,7 @@ const methods = [
|
|
|
5914
6259
|
*
|
|
5915
6260
|
* _(Logging can be enabled or disabled by setting the `enabled` property)_
|
|
5916
6261
|
*/
|
|
5917
|
-
const Logger = (
|
|
5918
|
-
const instance = {};
|
|
5919
|
-
Object.defineProperties(instance, {
|
|
5920
|
-
[LOGGER_PROPERTY]: { value: LOGGER_NAME },
|
|
5921
|
-
enabled: {
|
|
5922
|
-
enumerable: true,
|
|
5923
|
-
get: () => enabled,
|
|
5924
|
-
set: (value) => {
|
|
5925
|
-
enabled = typeof value === "boolean" ? value : enabled;
|
|
5926
|
-
}
|
|
5927
|
-
},
|
|
5928
|
-
time: { value: (label) => timedLogger(getString(label)) }
|
|
5929
|
-
});
|
|
5930
|
-
for (const method of methods) Object.defineProperty(instance, method, {
|
|
5931
|
-
enumerable: true,
|
|
5932
|
-
get() {
|
|
5933
|
-
return enabled ? console[method].bind(console) : noop;
|
|
5934
|
-
}
|
|
5935
|
-
});
|
|
5936
|
-
return Object.freeze(instance);
|
|
5937
|
-
})();
|
|
6262
|
+
const Logger = new Lumberjack();
|
|
5938
6263
|
let enabled = true;
|
|
5939
6264
|
//#endregion
|
|
5940
6265
|
//#region src/math.ts
|
|
@@ -6080,6 +6405,9 @@ const QUERY_TYPES = /* @__PURE__ */ new Set([
|
|
|
6080
6405
|
]);
|
|
6081
6406
|
//#endregion
|
|
6082
6407
|
//#region src/queue.ts
|
|
6408
|
+
const QUEUE_NAME_KEYED = "keyedQueue";
|
|
6409
|
+
const QUEUE_NAME_QUEUE = "queue";
|
|
6410
|
+
const QUEUE_PROPERTY = "$queue";
|
|
6083
6411
|
/**
|
|
6084
6412
|
* An error thrown by the Queue when an operation fails
|
|
6085
6413
|
*/
|
|
@@ -6089,10 +6417,159 @@ var QueueError = class extends Error {
|
|
|
6089
6417
|
this.name = QUEUE_ERROR_NAME;
|
|
6090
6418
|
}
|
|
6091
6419
|
};
|
|
6092
|
-
function
|
|
6093
|
-
|
|
6420
|
+
function KeyedQueue(callback, options) {
|
|
6421
|
+
Object.defineProperty(this, QUEUE_SYMBOL, { value: {
|
|
6422
|
+
callback,
|
|
6423
|
+
options: createQueueOptions(options),
|
|
6424
|
+
queues: /* @__PURE__ */ new Map()
|
|
6425
|
+
} });
|
|
6426
|
+
}
|
|
6427
|
+
Object.defineProperties(KeyedQueue.prototype, {
|
|
6428
|
+
[QUEUE_PROPERTY]: { value: QUEUE_NAME_KEYED },
|
|
6429
|
+
active: {
|
|
6430
|
+
enumerable: true,
|
|
6431
|
+
get() {
|
|
6432
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_ACTIVE);
|
|
6433
|
+
}
|
|
6434
|
+
},
|
|
6435
|
+
add: { value: addKeyedQueue },
|
|
6436
|
+
autostart: {
|
|
6437
|
+
enumerable: true,
|
|
6438
|
+
get() {
|
|
6439
|
+
return this[QUEUE_SYMBOL].options.autostart;
|
|
6440
|
+
}
|
|
6441
|
+
},
|
|
6442
|
+
clear: { value: clearQueues },
|
|
6443
|
+
concurrency: {
|
|
6444
|
+
enumerable: true,
|
|
6445
|
+
get() {
|
|
6446
|
+
return this[QUEUE_SYMBOL].options.concurrency;
|
|
6447
|
+
}
|
|
6448
|
+
},
|
|
6449
|
+
empty: {
|
|
6450
|
+
enumerable: true,
|
|
6451
|
+
get() {
|
|
6452
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_EMPTY);
|
|
6453
|
+
}
|
|
6454
|
+
},
|
|
6455
|
+
full: {
|
|
6456
|
+
enumerable: true,
|
|
6457
|
+
get() {
|
|
6458
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_FULL);
|
|
6459
|
+
}
|
|
6460
|
+
},
|
|
6461
|
+
get: { value: getQueue },
|
|
6462
|
+
items: {
|
|
6463
|
+
enumerable: true,
|
|
6464
|
+
get() {
|
|
6465
|
+
return getQueueItems(this[QUEUE_SYMBOL]);
|
|
6466
|
+
}
|
|
6467
|
+
},
|
|
6468
|
+
keys: {
|
|
6469
|
+
enumerable: true,
|
|
6470
|
+
get() {
|
|
6471
|
+
return [...this[QUEUE_SYMBOL].queues.keys()];
|
|
6472
|
+
}
|
|
6473
|
+
},
|
|
6474
|
+
maximum: {
|
|
6475
|
+
enumerable: true,
|
|
6476
|
+
get() {
|
|
6477
|
+
return this[QUEUE_SYMBOL].options.maximum;
|
|
6478
|
+
}
|
|
6479
|
+
},
|
|
6480
|
+
pause: { value: pauseQueues },
|
|
6481
|
+
paused: {
|
|
6482
|
+
enumerable: true,
|
|
6483
|
+
get() {
|
|
6484
|
+
return getStatus(this[QUEUE_SYMBOL], QUEUE_STATUS_PAUSED);
|
|
6485
|
+
}
|
|
6486
|
+
},
|
|
6487
|
+
queues: {
|
|
6488
|
+
enumerable: true,
|
|
6489
|
+
get() {
|
|
6490
|
+
return this[QUEUE_SYMBOL].queues.size;
|
|
6491
|
+
}
|
|
6492
|
+
},
|
|
6493
|
+
remove: { value: removeQueue },
|
|
6494
|
+
resume: { value: resumeQueues }
|
|
6495
|
+
});
|
|
6496
|
+
function Queue(callback, options, key) {
|
|
6497
|
+
Object.defineProperty(this, QUEUE_SYMBOL, { value: {
|
|
6498
|
+
callback,
|
|
6499
|
+
key,
|
|
6500
|
+
options,
|
|
6501
|
+
handled: [],
|
|
6502
|
+
id: 0,
|
|
6503
|
+
items: [],
|
|
6504
|
+
paused: !options.autostart,
|
|
6505
|
+
runners: 0
|
|
6506
|
+
} });
|
|
6507
|
+
}
|
|
6508
|
+
Object.defineProperties(Queue.prototype, {
|
|
6509
|
+
[QUEUE_PROPERTY]: { value: QUEUE_NAME_QUEUE },
|
|
6510
|
+
active: {
|
|
6511
|
+
enumerable: true,
|
|
6512
|
+
get() {
|
|
6513
|
+
return this[QUEUE_SYMBOL].runners > 0;
|
|
6514
|
+
}
|
|
6515
|
+
},
|
|
6516
|
+
add: { value: addToQueue },
|
|
6517
|
+
autostart: {
|
|
6518
|
+
enumerable: true,
|
|
6519
|
+
get() {
|
|
6520
|
+
return this[QUEUE_SYMBOL].options.autostart;
|
|
6521
|
+
}
|
|
6522
|
+
},
|
|
6523
|
+
clear: { value: clearQueue },
|
|
6524
|
+
concurrency: {
|
|
6525
|
+
enumerable: true,
|
|
6526
|
+
get() {
|
|
6527
|
+
return this[QUEUE_SYMBOL].options.concurrency;
|
|
6528
|
+
}
|
|
6529
|
+
},
|
|
6530
|
+
empty: {
|
|
6531
|
+
enumerable: true,
|
|
6532
|
+
get() {
|
|
6533
|
+
return this[QUEUE_SYMBOL].items.length === 0;
|
|
6534
|
+
}
|
|
6535
|
+
},
|
|
6536
|
+
full: {
|
|
6537
|
+
enumerable: true,
|
|
6538
|
+
get() {
|
|
6539
|
+
const state = this[QUEUE_SYMBOL];
|
|
6540
|
+
return state.options.maximum > 0 && state.items.length >= state.options.maximum;
|
|
6541
|
+
}
|
|
6542
|
+
},
|
|
6543
|
+
maximum: {
|
|
6544
|
+
enumerable: true,
|
|
6545
|
+
get() {
|
|
6546
|
+
return this[QUEUE_SYMBOL].options.maximum;
|
|
6547
|
+
}
|
|
6548
|
+
},
|
|
6549
|
+
pause: { value: pauseQueue },
|
|
6550
|
+
paused: {
|
|
6551
|
+
enumerable: true,
|
|
6552
|
+
get() {
|
|
6553
|
+
return this[QUEUE_SYMBOL].paused;
|
|
6554
|
+
}
|
|
6555
|
+
},
|
|
6556
|
+
remove: { value: removeQueued },
|
|
6557
|
+
resume: { value: resumeQueue },
|
|
6558
|
+
size: {
|
|
6559
|
+
enumerable: true,
|
|
6560
|
+
get() {
|
|
6561
|
+
return this[QUEUE_SYMBOL].items.length;
|
|
6562
|
+
}
|
|
6563
|
+
}
|
|
6564
|
+
});
|
|
6565
|
+
function addKeyedQueue(key, parameters, signal) {
|
|
6566
|
+
return getQueue.call(this, key, true).add(parameters, signal);
|
|
6567
|
+
}
|
|
6568
|
+
function addToQueue(parameters, signal) {
|
|
6569
|
+
if (this.full) throw new QueueError(QUEUE_MESSAGE_MAXIMUM);
|
|
6094
6570
|
const abortSignal = signal instanceof AbortSignal ? signal : void 0;
|
|
6095
6571
|
if (abortSignal?.aborted ?? false) throw new Error(abortSignal?.reason);
|
|
6572
|
+
const state = this[QUEUE_SYMBOL];
|
|
6096
6573
|
const id = identify(state);
|
|
6097
6574
|
let rejector;
|
|
6098
6575
|
let resolver;
|
|
@@ -6116,8 +6593,8 @@ function addToQueue(instance, state, parameters, signal) {
|
|
|
6116
6593
|
promise
|
|
6117
6594
|
};
|
|
6118
6595
|
}
|
|
6119
|
-
function clearQueue(
|
|
6120
|
-
const items =
|
|
6596
|
+
function clearQueue() {
|
|
6597
|
+
const items = this[QUEUE_SYMBOL].items.splice(0);
|
|
6121
6598
|
const { length } = items;
|
|
6122
6599
|
for (let index = 0; index < length; index += 1) {
|
|
6123
6600
|
const { aborter, reject } = items[index];
|
|
@@ -6125,63 +6602,12 @@ function clearQueue(state) {
|
|
|
6125
6602
|
reject(new QueueError(QUEUE_MESSAGE_CLEAR));
|
|
6126
6603
|
}
|
|
6127
6604
|
}
|
|
6605
|
+
function clearQueues(key) {
|
|
6606
|
+
handleQueues(this, QUEUE_HANDLE_CLEAR, key);
|
|
6607
|
+
}
|
|
6128
6608
|
function createQueue(callback, options, key) {
|
|
6129
6609
|
if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
|
|
6130
|
-
|
|
6131
|
-
callback,
|
|
6132
|
-
key,
|
|
6133
|
-
handled: [],
|
|
6134
|
-
id: 0,
|
|
6135
|
-
items: [],
|
|
6136
|
-
options: createQueueOptions(options),
|
|
6137
|
-
paused: !getBooleanOrDefault(options?.autostart, true),
|
|
6138
|
-
runners: 0
|
|
6139
|
-
};
|
|
6140
|
-
const instance = {
|
|
6141
|
-
add: (parameters, signal) => addToQueue(instance, state, parameters, signal),
|
|
6142
|
-
clear: () => clearQueue(state),
|
|
6143
|
-
pause: () => {
|
|
6144
|
-
state.paused = true;
|
|
6145
|
-
},
|
|
6146
|
-
remove: (id) => removeQueued(state, id),
|
|
6147
|
-
resume: () => resumeQueue(state)
|
|
6148
|
-
};
|
|
6149
|
-
Object.defineProperties(instance, {
|
|
6150
|
-
[QUEUE_PROPERTY]: { value: QUEUE_NAME_QUEUE },
|
|
6151
|
-
active: {
|
|
6152
|
-
enumerable: true,
|
|
6153
|
-
get: () => state.runners > 0
|
|
6154
|
-
},
|
|
6155
|
-
autostart: {
|
|
6156
|
-
enumerable: true,
|
|
6157
|
-
get: () => state.options.autostart
|
|
6158
|
-
},
|
|
6159
|
-
concurrency: {
|
|
6160
|
-
enumerable: true,
|
|
6161
|
-
get: () => state.options.concurrency
|
|
6162
|
-
},
|
|
6163
|
-
empty: {
|
|
6164
|
-
enumerable: true,
|
|
6165
|
-
get: () => state.items.length === 0
|
|
6166
|
-
},
|
|
6167
|
-
full: {
|
|
6168
|
-
enumerable: true,
|
|
6169
|
-
get: () => state.options.maximum > 0 && state.items.length >= state.options.maximum
|
|
6170
|
-
},
|
|
6171
|
-
maximum: {
|
|
6172
|
-
enumerable: true,
|
|
6173
|
-
get: () => state.options.maximum
|
|
6174
|
-
},
|
|
6175
|
-
paused: {
|
|
6176
|
-
enumerable: true,
|
|
6177
|
-
get: () => state.paused
|
|
6178
|
-
},
|
|
6179
|
-
size: {
|
|
6180
|
-
enumerable: true,
|
|
6181
|
-
get: () => state.items.length
|
|
6182
|
-
}
|
|
6183
|
-
});
|
|
6184
|
-
return Object.freeze(instance);
|
|
6610
|
+
return new Queue(callback, createQueueOptions(options), key);
|
|
6185
6611
|
}
|
|
6186
6612
|
function createQueueOptions(input) {
|
|
6187
6613
|
const options = typeof input === "object" && input != null ? input : {};
|
|
@@ -6191,8 +6617,9 @@ function createQueueOptions(input) {
|
|
|
6191
6617
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
6192
6618
|
};
|
|
6193
6619
|
}
|
|
6194
|
-
function getQueue(
|
|
6620
|
+
function getQueue(key, add) {
|
|
6195
6621
|
if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(QUEUE_MESSAGE_KEY);
|
|
6622
|
+
const state = this[QUEUE_SYMBOL];
|
|
6196
6623
|
let queue = state.queues.get(key);
|
|
6197
6624
|
if (queue == null && add === true) {
|
|
6198
6625
|
queue = createQueue(state.callback, state.options, key);
|
|
@@ -6224,12 +6651,12 @@ function handleQueuedResult(item, error, result) {
|
|
|
6224
6651
|
}
|
|
6225
6652
|
item.resolve(result);
|
|
6226
6653
|
}
|
|
6227
|
-
function handleQueues(
|
|
6654
|
+
function handleQueues(instance, type, key) {
|
|
6228
6655
|
if (typeof key === "string") {
|
|
6229
|
-
getQueue(
|
|
6656
|
+
getQueue.call(instance, key)?.[type]();
|
|
6230
6657
|
return;
|
|
6231
6658
|
}
|
|
6232
|
-
const queues =
|
|
6659
|
+
const queues = instance[QUEUE_SYMBOL].queues.values();
|
|
6233
6660
|
for (const queue of queues) queue[type]();
|
|
6234
6661
|
}
|
|
6235
6662
|
function identify(state) {
|
|
@@ -6255,78 +6682,29 @@ function isQueue(value) {
|
|
|
6255
6682
|
return isQueueInstance(QUEUE_NAME_QUEUE, value);
|
|
6256
6683
|
}
|
|
6257
6684
|
function isQueueInstance(name, value) {
|
|
6258
|
-
return typeof value === "object" && value != null && value[QUEUE_PROPERTY] === name;
|
|
6685
|
+
return typeof value === "object" && value != null && QUEUE_PROPERTY in value && value[QUEUE_PROPERTY] === name;
|
|
6259
6686
|
}
|
|
6260
6687
|
function keyedQueue(callback, options) {
|
|
6261
6688
|
if (typeof callback !== "function") throw new TypeError(QUEUE_MESSAGE_CALLBACK);
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
clear: (key) => handleQueues(state, QUEUE_HANDLE_CLEAR, key),
|
|
6270
|
-
get: (key) => getQueue(state, key),
|
|
6271
|
-
pause: (key) => handleQueues(state, QUEUE_HANDLE_PAUSE, key),
|
|
6272
|
-
remove: (key, id) => removeQueue(state, key, id),
|
|
6273
|
-
resume: (key) => handleQueues(state, QUEUE_HANDLE_RESUME, key)
|
|
6274
|
-
};
|
|
6275
|
-
Object.defineProperties(instance, {
|
|
6276
|
-
[QUEUE_PROPERTY]: { value: QUEUE_NAME_KEYED },
|
|
6277
|
-
active: {
|
|
6278
|
-
enumerable: true,
|
|
6279
|
-
get: () => getStatus(state, QUEUE_STATUS_ACTIVE)
|
|
6280
|
-
},
|
|
6281
|
-
autostart: {
|
|
6282
|
-
enumerable: true,
|
|
6283
|
-
get: () => state.options.autostart
|
|
6284
|
-
},
|
|
6285
|
-
concurrency: {
|
|
6286
|
-
enumerable: true,
|
|
6287
|
-
get: () => state.options.concurrency
|
|
6288
|
-
},
|
|
6289
|
-
empty: {
|
|
6290
|
-
enumerable: true,
|
|
6291
|
-
get: () => getStatus(state, QUEUE_STATUS_EMPTY)
|
|
6292
|
-
},
|
|
6293
|
-
full: {
|
|
6294
|
-
enumerable: true,
|
|
6295
|
-
get: () => getStatus(state, QUEUE_STATUS_FULL)
|
|
6296
|
-
},
|
|
6297
|
-
items: {
|
|
6298
|
-
enumerable: true,
|
|
6299
|
-
get: () => getQueueItems(state)
|
|
6300
|
-
},
|
|
6301
|
-
keys: {
|
|
6302
|
-
enumerable: true,
|
|
6303
|
-
get: () => [...state.queues.keys()]
|
|
6304
|
-
},
|
|
6305
|
-
maximum: {
|
|
6306
|
-
enumerable: true,
|
|
6307
|
-
get: () => state.options.maximum
|
|
6308
|
-
},
|
|
6309
|
-
paused: {
|
|
6310
|
-
enumerable: true,
|
|
6311
|
-
get: () => getStatus(state, QUEUE_STATUS_PAUSED)
|
|
6312
|
-
},
|
|
6313
|
-
queues: {
|
|
6314
|
-
enumerable: true,
|
|
6315
|
-
get: () => state.queues.size
|
|
6316
|
-
}
|
|
6317
|
-
});
|
|
6318
|
-
return Object.freeze(instance);
|
|
6689
|
+
return new KeyedQueue(callback, createQueueOptions(options));
|
|
6690
|
+
}
|
|
6691
|
+
function pauseQueue() {
|
|
6692
|
+
this[QUEUE_SYMBOL].paused = true;
|
|
6693
|
+
}
|
|
6694
|
+
function pauseQueues(key) {
|
|
6695
|
+
handleQueues(this, QUEUE_HANDLE_PAUSE, key);
|
|
6319
6696
|
}
|
|
6320
6697
|
function queue(callback, options) {
|
|
6321
6698
|
return createQueue(callback, options);
|
|
6322
6699
|
}
|
|
6323
|
-
function removeQueue(
|
|
6700
|
+
function removeQueue(key, id) {
|
|
6701
|
+
const state = this[QUEUE_SYMBOL];
|
|
6324
6702
|
if (key == null) {
|
|
6325
|
-
handleQueues(
|
|
6703
|
+
handleQueues(this, QUEUE_HANDLE_CLEAR);
|
|
6326
6704
|
state.queues.clear();
|
|
6327
6705
|
return;
|
|
6328
6706
|
}
|
|
6329
|
-
const queue = getQueue(
|
|
6707
|
+
const queue = getQueue.call(this, key);
|
|
6330
6708
|
if (queue == null) return;
|
|
6331
6709
|
if (typeof id === "number") {
|
|
6332
6710
|
queue.remove(id);
|
|
@@ -6335,7 +6713,8 @@ function removeQueue(state, key, id) {
|
|
|
6335
6713
|
queue.clear();
|
|
6336
6714
|
state.queues.delete(key);
|
|
6337
6715
|
}
|
|
6338
|
-
function removeQueued(
|
|
6716
|
+
function removeQueued(id) {
|
|
6717
|
+
const state = this[QUEUE_SYMBOL];
|
|
6339
6718
|
const index = state.items.findIndex((item) => item.id === id);
|
|
6340
6719
|
if (index > -1) {
|
|
6341
6720
|
const { aborter, reject } = state.items.splice(index, 1)[0];
|
|
@@ -6343,7 +6722,8 @@ function removeQueued(state, id) {
|
|
|
6343
6722
|
reject(new QueueError(QUEUE_MESSAGE_REMOVE));
|
|
6344
6723
|
}
|
|
6345
6724
|
}
|
|
6346
|
-
function resumeQueue(
|
|
6725
|
+
function resumeQueue() {
|
|
6726
|
+
const state = this[QUEUE_SYMBOL];
|
|
6347
6727
|
if (state.paused) {
|
|
6348
6728
|
const handled = state.handled.splice(0);
|
|
6349
6729
|
const { length } = handled;
|
|
@@ -6353,6 +6733,9 @@ function resumeQueue(state) {
|
|
|
6353
6733
|
const length = Math.min(state.options.concurrency, state.items.length);
|
|
6354
6734
|
for (let index = 0; index < length; index += 1) run(state);
|
|
6355
6735
|
}
|
|
6736
|
+
function resumeQueues(key) {
|
|
6737
|
+
handleQueues(this, QUEUE_HANDLE_RESUME, key);
|
|
6738
|
+
}
|
|
6356
6739
|
async function run(state) {
|
|
6357
6740
|
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
6358
6741
|
state.runners += 1;
|
|
@@ -6380,7 +6763,6 @@ async function run(state) {
|
|
|
6380
6763
|
state.runners -= 1;
|
|
6381
6764
|
}
|
|
6382
6765
|
const QUEUE_ERROR_NAME = "QueueError";
|
|
6383
|
-
const QUEUE_PROPERTY = "$queue";
|
|
6384
6766
|
const QUEUE_HANDLE_CLEAR = "clear";
|
|
6385
6767
|
const QUEUE_HANDLE_PAUSE = "pause";
|
|
6386
6768
|
const QUEUE_HANDLE_RESUME = "resume";
|
|
@@ -6389,12 +6771,11 @@ const QUEUE_MESSAGE_CLEAR = "Queue was cleared";
|
|
|
6389
6771
|
const QUEUE_MESSAGE_KEY = "Key must be a non-empty string";
|
|
6390
6772
|
const QUEUE_MESSAGE_MAXIMUM = "Queue has reached its maximum size";
|
|
6391
6773
|
const QUEUE_MESSAGE_REMOVE = "Item removed from queue";
|
|
6392
|
-
const QUEUE_NAME_KEYED = "keyedQueue";
|
|
6393
|
-
const QUEUE_NAME_QUEUE = "queue";
|
|
6394
6774
|
const QUEUE_STATUS_ACTIVE = "active";
|
|
6395
6775
|
const QUEUE_STATUS_EMPTY = "empty";
|
|
6396
6776
|
const QUEUE_STATUS_FULL = "full";
|
|
6397
6777
|
const QUEUE_STATUS_PAUSED = "paused";
|
|
6778
|
+
const QUEUE_SYMBOL = Symbol(QUEUE_PROPERTY);
|
|
6398
6779
|
queue.keyed = keyedQueue;
|
|
6399
6780
|
Object.defineProperty(queue, "keyed", { value: keyedQueue });
|
|
6400
6781
|
//#endregion
|
|
@@ -6514,4 +6895,4 @@ var SizedSet = class extends Set {
|
|
|
6514
6895
|
}
|
|
6515
6896
|
};
|
|
6516
6897
|
//#endregion
|
|
6517
|
-
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions,
|
|
6898
|
+
export { CancelablePromise, Logger, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeCloner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isAsyncOnce, isBeacon, isBeaconSubscription, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isFuzzy, isHerald, isHeraldEvents, isHeraldSubscription, isHexColor, isHslColor, isHslaColor, isHwbColor, isHwbaColor, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isOnce, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbaColor, isSorted, isSubscription, isSubscriptions, isTimeLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, reverseSelect, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, subscriptions, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|