@oscarpalmer/atoms 0.186.2 → 0.187.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array/filter.d.mts +4 -4
- package/dist/array/find.d.mts +4 -4
- package/dist/array/first.d.mts +4 -4
- package/dist/array/get.d.mts +27 -1
- package/dist/array/get.mjs +5 -3
- package/dist/array/group-by.d.mts +6 -6
- package/dist/array/last.d.mts +4 -4
- package/dist/array/match.d.mts +7 -6
- package/dist/array/move.d.mts +7 -7
- package/dist/array/move.mjs +1 -1
- package/dist/array/select.d.mts +1 -0
- package/dist/array/slice.d.mts +3 -3
- package/dist/array/sort.d.mts +10 -7
- package/dist/array/sort.mjs +4 -3
- package/dist/array/swap.d.mts +1 -1
- package/dist/array/swap.mjs +1 -1
- package/dist/array/to-map.d.mts +32 -32
- package/dist/array/to-record.d.mts +6 -6
- package/dist/array/to-set.d.mts +6 -6
- package/dist/beacon.d.mts +6 -0
- package/dist/beacon.mjs +3 -0
- package/dist/color/index.d.mts +6 -2
- package/dist/color/index.mjs +6 -2
- package/dist/color/instance.d.mts +78 -14
- package/dist/color/instance.mjs +78 -14
- package/dist/color/misc/get.d.mts +39 -11
- package/dist/color/misc/get.mjs +39 -11
- package/dist/color/misc/is.d.mts +26 -11
- package/dist/color/misc/is.mjs +26 -11
- package/dist/color/misc/state.mjs +1 -1
- package/dist/color/models.d.mts +7 -4
- package/dist/color/space/hex.d.mts +15 -6
- package/dist/color/space/hex.mjs +15 -6
- package/dist/color/space/hsl.d.mts +10 -4
- package/dist/color/space/hsl.mjs +10 -4
- package/dist/color/space/rgb.d.mts +21 -12
- package/dist/color/space/rgb.mjs +21 -12
- package/dist/function/assert.d.mts +20 -14
- package/dist/function/assert.mjs +19 -13
- package/dist/function/limit.d.mts +8 -6
- package/dist/function/limit.mjs +8 -6
- package/dist/function/memoize.d.mts +15 -4
- package/dist/function/memoize.mjs +18 -4
- package/dist/function/once.d.mts +5 -3
- package/dist/function/once.mjs +5 -3
- package/dist/function/retry.d.mts +5 -2
- package/dist/function/retry.mjs +3 -1
- package/dist/function/work.d.mts +146 -98
- package/dist/{kalas.d.mts → herald.d.mts} +17 -8
- package/dist/{kalas.mjs → herald.mjs} +22 -13
- package/dist/index.d.mts +1464 -708
- package/dist/index.mjs +703 -342
- package/dist/internal/array/index-of.d.mts +4 -4
- package/dist/internal/array/insert.mjs +1 -1
- package/dist/internal/array/shuffle.d.mts +1 -0
- package/dist/internal/array/shuffle.mjs +2 -1
- package/dist/internal/is.d.mts +26 -8
- package/dist/internal/is.mjs +26 -8
- package/dist/internal/math/aggregate.d.mts +9 -9
- package/dist/internal/number.d.mts +13 -2
- package/dist/internal/number.mjs +13 -2
- package/dist/internal/random.d.mts +4 -2
- package/dist/internal/random.mjs +7 -5
- package/dist/internal/result.d.mts +17 -11
- package/dist/internal/result.mjs +10 -14
- package/dist/internal/string.d.mts +16 -1
- package/dist/internal/string.mjs +24 -1
- package/dist/internal/value/compare.d.mts +5 -2
- package/dist/internal/value/compare.mjs +5 -2
- package/dist/internal/value/equal.d.mts +12 -3
- package/dist/internal/value/equal.mjs +7 -4
- package/dist/internal/value/get.d.mts +17 -17
- package/dist/internal/value/has.d.mts +55 -11
- package/dist/internal/value/set.d.mts +24 -0
- package/dist/internal/value/set.mjs +1 -1
- package/dist/is.d.mts +12 -0
- package/dist/is.mjs +16 -1
- package/dist/logger.d.mts +7 -6
- package/dist/logger.mjs +6 -5
- package/dist/math.d.mts +36 -18
- package/dist/math.mjs +6 -3
- package/dist/models.d.mts +3 -3
- package/dist/promise/delay.d.mts +2 -0
- package/dist/promise/helpers.d.mts +6 -4
- package/dist/promise/helpers.mjs +6 -4
- package/dist/promise/index.d.mts +49 -38
- package/dist/promise/misc.d.mts +10 -7
- package/dist/promise/misc.mjs +4 -3
- package/dist/promise/models.d.mts +18 -19
- package/dist/promise/models.mjs +4 -3
- package/dist/promise/timed.d.mts +8 -6
- package/dist/query.d.mts +2 -0
- package/dist/query.mjs +27 -17
- package/dist/queue.d.mts +15 -4
- package/dist/queue.mjs +10 -3
- package/dist/random.d.mts +9 -2
- package/dist/random.mjs +7 -2
- package/dist/result/index.d.mts +14 -8
- package/dist/result/match.d.mts +18 -10
- package/dist/result/misc.d.mts +14 -7
- package/dist/result/misc.mjs +4 -2
- package/dist/result/models.d.mts +2 -0
- package/dist/result/work/flow.d.mts +86 -62
- package/dist/result/work/pipe.d.mts +55 -33
- package/dist/sized/map.d.mts +19 -16
- package/dist/sized/map.mjs +4 -4
- package/dist/sized/set.d.mts +20 -16
- package/dist/sized/set.mjs +8 -7
- package/dist/string/case.d.mts +8 -0
- package/dist/string/case.mjs +8 -0
- package/dist/string/fuzzy.d.mts +19 -5
- package/dist/string/fuzzy.mjs +7 -0
- package/dist/string/index.d.mts +17 -2
- package/dist/string/index.mjs +7 -9
- package/dist/string/match.d.mts +3 -0
- package/dist/string/match.mjs +3 -0
- package/dist/string/normalize.d.mts +6 -2
- package/dist/string/normalize.mjs +5 -2
- package/dist/string/template.d.mts +38 -9
- package/dist/string/template.mjs +19 -19
- package/dist/value/clone.d.mts +25 -4
- package/dist/value/clone.mjs +36 -22
- package/dist/value/collection.d.mts +9 -6
- package/dist/value/collection.mjs +3 -2
- package/dist/value/diff.d.mts +3 -1
- package/dist/value/diff.mjs +1 -0
- package/dist/value/freeze.d.mts +118 -9
- package/dist/value/freeze.mjs +56 -14
- package/dist/value/index.d.mts +1 -2
- package/dist/value/index.mjs +1 -2
- package/dist/value/merge.d.mts +11 -5
- package/dist/value/merge.mjs +2 -2
- package/dist/value/omit.d.mts +1 -0
- package/dist/value/omit.mjs +1 -0
- package/dist/value/pick.d.mts +1 -0
- package/dist/value/pick.mjs +1 -0
- package/dist/value/shake.d.mts +1 -0
- package/dist/value/shake.mjs +1 -0
- package/dist/value/smush.d.mts +1 -0
- package/dist/value/smush.mjs +1 -0
- package/dist/value/transform.d.mts +7 -3
- package/dist/value/unsmush.d.mts +1 -0
- package/dist/value/unsmush.mjs +1 -0
- package/package.json +12 -8
- package/src/array/filter.ts +4 -4
- package/src/array/find.ts +4 -4
- package/src/array/first.ts +4 -4
- package/src/array/get.ts +40 -5
- package/src/array/group-by.ts +6 -6
- package/src/array/last.ts +4 -4
- package/src/array/match.ts +7 -6
- package/src/array/move.ts +7 -7
- package/src/array/select.ts +1 -0
- package/src/array/slice.ts +3 -3
- package/src/array/sort.ts +15 -10
- package/src/array/swap.ts +1 -1
- package/src/array/to-map.ts +32 -32
- package/src/array/to-record.ts +6 -6
- package/src/array/to-set.ts +6 -6
- package/src/beacon.ts +6 -0
- package/src/color/index.ts +6 -2
- package/src/color/instance.ts +78 -14
- package/src/color/misc/get.ts +39 -11
- package/src/color/misc/is.ts +26 -11
- package/src/color/misc/state.ts +1 -1
- package/src/color/models.ts +7 -4
- package/src/color/space/hex.ts +15 -6
- package/src/color/space/hsl.ts +10 -4
- package/src/color/space/rgb.ts +21 -12
- package/src/function/assert.ts +20 -14
- package/src/function/limit.ts +8 -6
- package/src/function/memoize.ts +24 -5
- package/src/function/once.ts +5 -3
- package/src/function/retry.ts +7 -3
- package/src/function/work.ts +146 -98
- package/src/{kalas.ts → herald.ts} +23 -14
- package/src/index.ts +3 -2
- package/src/internal/array/index-of.ts +4 -4
- package/src/internal/array/insert.ts +1 -1
- package/src/internal/array/shuffle.ts +2 -1
- package/src/internal/is.ts +26 -8
- package/src/internal/math/aggregate.ts +9 -9
- package/src/internal/number.ts +13 -2
- package/src/internal/random.ts +10 -4
- package/src/internal/result.ts +30 -29
- package/src/internal/string.ts +28 -0
- package/src/internal/value/compare.ts +5 -2
- package/src/internal/value/equal.ts +13 -4
- package/src/internal/value/get.ts +17 -17
- package/src/internal/value/has.ts +54 -11
- package/src/internal/value/set.ts +25 -1
- package/src/is.ts +15 -1
- package/src/logger.ts +8 -7
- package/src/math.ts +36 -18
- package/src/models.ts +3 -3
- package/src/promise/delay.ts +2 -0
- package/src/promise/helpers.ts +6 -4
- package/src/promise/index.ts +49 -38
- package/src/promise/misc.ts +10 -7
- package/src/promise/models.ts +18 -19
- package/src/promise/timed.ts +8 -6
- package/src/query.ts +39 -28
- package/src/queue.ts +15 -4
- package/src/random.ts +8 -1
- package/src/result/index.ts +14 -8
- package/src/result/match.ts +18 -10
- package/src/result/misc.ts +17 -9
- package/src/result/models.ts +2 -0
- package/src/result/work/flow.ts +86 -62
- package/src/result/work/pipe.ts +55 -33
- package/src/sized/map.ts +20 -17
- package/src/sized/set.ts +21 -17
- package/src/string/case.ts +8 -0
- package/src/string/fuzzy.ts +19 -5
- package/src/string/index.ts +18 -15
- package/src/string/match.ts +3 -0
- package/src/string/normalize.ts +6 -2
- package/src/string/template.ts +69 -18
- package/src/value/clone.ts +51 -26
- package/src/value/collection.ts +9 -6
- package/src/value/diff.ts +3 -1
- package/src/value/freeze.ts +239 -25
- package/src/value/index.ts +0 -1
- package/src/value/merge.ts +11 -5
- package/src/value/omit.ts +1 -0
- package/src/value/pick.ts +1 -0
- package/src/value/shake.ts +1 -0
- package/src/value/smush.ts +1 -0
- package/src/value/transform.ts +7 -3
- package/src/value/unsmush.ts +1 -0
package/dist/index.mjs
CHANGED
|
@@ -193,15 +193,17 @@ function lastIndexOf(array, ...parameters) {
|
|
|
193
193
|
//#endregion
|
|
194
194
|
//#region src/internal/is.ts
|
|
195
195
|
/**
|
|
196
|
-
* Is the value an array or a
|
|
196
|
+
* Is the value an array or a plain object?
|
|
197
|
+
*
|
|
197
198
|
* @param value Value to check
|
|
198
|
-
* @returns `true` if the value is an array or a
|
|
199
|
+
* @returns `true` if the value is an array or a plain object, otherwise `false`
|
|
199
200
|
*/
|
|
200
201
|
function isArrayOrPlainObject(value) {
|
|
201
202
|
return Array.isArray(value) || isPlainObject(value);
|
|
202
203
|
}
|
|
203
204
|
/**
|
|
204
205
|
* Is the value a constructor function?
|
|
206
|
+
*
|
|
205
207
|
* @param value Value to check
|
|
206
208
|
* @returns `true` if the value is a constructor function, otherwise `false`
|
|
207
209
|
*/
|
|
@@ -210,6 +212,7 @@ function isConstructor(value) {
|
|
|
210
212
|
}
|
|
211
213
|
/**
|
|
212
214
|
* Is the value an instance of the constructor?
|
|
215
|
+
*
|
|
213
216
|
* @param constructor Class constructor
|
|
214
217
|
* @param value Value to check
|
|
215
218
|
* @returns `true` if the value is an instance of the constructor, otherwise `false`
|
|
@@ -218,15 +221,17 @@ function isInstanceOf(constructor, value) {
|
|
|
218
221
|
return isConstructor(constructor) && value instanceof constructor;
|
|
219
222
|
}
|
|
220
223
|
/**
|
|
221
|
-
* Is the value a
|
|
224
|
+
* Is the value a _Key_?
|
|
225
|
+
*
|
|
222
226
|
* @param value Value to check
|
|
223
|
-
* @returns `true` if the value is a
|
|
227
|
+
* @returns `true` if the value is a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
224
228
|
*/
|
|
225
229
|
function isKey(value) {
|
|
226
230
|
return typeof value === "number" || typeof value === "string";
|
|
227
231
|
}
|
|
228
232
|
/**
|
|
229
233
|
* Is the value not an array or a plain object?
|
|
234
|
+
*
|
|
230
235
|
* @param value Value to check
|
|
231
236
|
* @returns `true` if the value is not an array or a plain object, otherwise `false`
|
|
232
237
|
*/
|
|
@@ -235,6 +240,7 @@ function isNonArrayOrPlainObject(value) {
|
|
|
235
240
|
}
|
|
236
241
|
/**
|
|
237
242
|
* Is the value not a constructor function?
|
|
243
|
+
*
|
|
238
244
|
* @param value Value to check
|
|
239
245
|
* @returns `true` if the value is not a constructor function, otherwise `false`
|
|
240
246
|
*/
|
|
@@ -243,6 +249,7 @@ function isNonConstructor(value) {
|
|
|
243
249
|
}
|
|
244
250
|
/**
|
|
245
251
|
* Is the value not an instance of the constructor?
|
|
252
|
+
*
|
|
246
253
|
* @param constructor Class constructor
|
|
247
254
|
* @param value Value to check
|
|
248
255
|
* @returns `true` if the value is not an instance of the constructor, otherwise `false`
|
|
@@ -251,15 +258,17 @@ function isNonInstanceOf(constructor, value) {
|
|
|
251
258
|
return !isInstanceOf(constructor, value);
|
|
252
259
|
}
|
|
253
260
|
/**
|
|
254
|
-
* Is the value not a
|
|
261
|
+
* Is the value not a _Key_?
|
|
262
|
+
*
|
|
255
263
|
* @param value Value to check
|
|
256
|
-
* @returns `true` if the value is not a
|
|
264
|
+
* @returns `true` if the value is not a _Key_ _(`number` or `string`)_, otherwise `false`
|
|
257
265
|
*/
|
|
258
266
|
function isNonKey(value) {
|
|
259
267
|
return !isKey(value);
|
|
260
268
|
}
|
|
261
269
|
/**
|
|
262
270
|
* Is the value not a number?
|
|
271
|
+
*
|
|
263
272
|
* @param value Value to check
|
|
264
273
|
* @returns `true` if the value is not a `number`, otherwise `false`
|
|
265
274
|
*/
|
|
@@ -268,6 +277,7 @@ function isNonNumber(value) {
|
|
|
268
277
|
}
|
|
269
278
|
/**
|
|
270
279
|
* Is the value not a plain object?
|
|
280
|
+
*
|
|
271
281
|
* @param value Value to check
|
|
272
282
|
* @returns `true` if the value is not a plain object, otherwise `false`
|
|
273
283
|
*/
|
|
@@ -276,6 +286,7 @@ function isNonPlainObject(value) {
|
|
|
276
286
|
}
|
|
277
287
|
/**
|
|
278
288
|
* Is the value not a primitive value?
|
|
289
|
+
*
|
|
279
290
|
* @param value Value to check
|
|
280
291
|
* @returns `true` if the value is not a primitive value, otherwise `false`
|
|
281
292
|
*/
|
|
@@ -284,6 +295,7 @@ function isNonPrimitive(value) {
|
|
|
284
295
|
}
|
|
285
296
|
/**
|
|
286
297
|
* Is the value not a typed array?
|
|
298
|
+
*
|
|
287
299
|
* @param value Value to check
|
|
288
300
|
* @returns `true` if the value is not a typed array, otherwise `false`
|
|
289
301
|
*/
|
|
@@ -292,6 +304,7 @@ function isNonTypedArray(value) {
|
|
|
292
304
|
}
|
|
293
305
|
/**
|
|
294
306
|
* Is the value a number?
|
|
307
|
+
*
|
|
295
308
|
* @param value Value to check
|
|
296
309
|
* @returns `true` if the value is a `number`, otherwise `false`
|
|
297
310
|
*/
|
|
@@ -300,6 +313,7 @@ function isNumber(value) {
|
|
|
300
313
|
}
|
|
301
314
|
/**
|
|
302
315
|
* Is the value a plain object?
|
|
316
|
+
*
|
|
303
317
|
* @param value Value to check
|
|
304
318
|
* @returns `true` if the value is a plain object, otherwise `false`
|
|
305
319
|
*/
|
|
@@ -310,9 +324,10 @@ function isPlainObject(value) {
|
|
|
310
324
|
return prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null;
|
|
311
325
|
}
|
|
312
326
|
/**
|
|
313
|
-
*
|
|
327
|
+
* Is the value a primitive value?
|
|
328
|
+
*
|
|
314
329
|
* @param value Value to check
|
|
315
|
-
* @returns `true` if the value
|
|
330
|
+
* @returns `true` if the value is a primitive value, otherwise `false`
|
|
316
331
|
*/
|
|
317
332
|
function isPrimitive(value) {
|
|
318
333
|
if (value == null) return true;
|
|
@@ -321,6 +336,7 @@ function isPrimitive(value) {
|
|
|
321
336
|
}
|
|
322
337
|
/**
|
|
323
338
|
* Is the value a template strings array?
|
|
339
|
+
*
|
|
324
340
|
* @param value Value to check
|
|
325
341
|
* @returns `true` if the value is a `TemplateStringsArray`, otherwise `false`
|
|
326
342
|
*/
|
|
@@ -329,6 +345,7 @@ function isTemplateStringsArray(value) {
|
|
|
329
345
|
}
|
|
330
346
|
/**
|
|
331
347
|
* Is the value a typed array?
|
|
348
|
+
*
|
|
332
349
|
* @param value Value to check
|
|
333
350
|
* @returns `true` if the value is a typed array, otherwise `false`
|
|
334
351
|
*/
|
|
@@ -350,7 +367,7 @@ function isTypedArray(value) {
|
|
|
350
367
|
}
|
|
351
368
|
//#endregion
|
|
352
369
|
//#region src/internal/random.ts
|
|
353
|
-
function
|
|
370
|
+
function getRandomFloatingNumberValue(inclusive, minimum, maximum) {
|
|
354
371
|
let maxFloat = isNumber(maximum) && maximum <= Number.MAX_SAFE_INTEGER ? maximum : Number.MAX_SAFE_INTEGER;
|
|
355
372
|
let minFloat = isNumber(minimum) && minimum >= Number.MIN_SAFE_INTEGER ? minimum : Number.MIN_SAFE_INTEGER;
|
|
356
373
|
if (minFloat === maxFloat) return minFloat;
|
|
@@ -359,26 +376,29 @@ function _getRandomFloat(inclusive, minimum, maximum) {
|
|
|
359
376
|
}
|
|
360
377
|
/**
|
|
361
378
|
* Get a random floating-point number
|
|
379
|
+
*
|
|
362
380
|
* @param minimum Minimum value
|
|
363
381
|
* @param maximum Maximum value
|
|
364
382
|
* @returns Random floating-point number
|
|
365
383
|
*/
|
|
366
|
-
function
|
|
367
|
-
return
|
|
384
|
+
function getRandomFloatingNumber(minimum, maximum) {
|
|
385
|
+
return getRandomFloatingNumberValue(false, minimum, maximum);
|
|
368
386
|
}
|
|
369
387
|
/**
|
|
370
388
|
* Get a random integer
|
|
389
|
+
*
|
|
371
390
|
* @param minimum Minimum value
|
|
372
391
|
* @param maximum Maximum value
|
|
373
392
|
* @returns Random integer
|
|
374
393
|
*/
|
|
375
394
|
function getRandomInteger(minimum, maximum) {
|
|
376
|
-
return Math.floor(
|
|
395
|
+
return Math.floor(getRandomFloatingNumberValue(true, minimum, maximum));
|
|
377
396
|
}
|
|
378
397
|
//#endregion
|
|
379
398
|
//#region src/internal/array/shuffle.ts
|
|
380
399
|
/**
|
|
381
400
|
* Shuffle items in array
|
|
401
|
+
*
|
|
382
402
|
* @param array Original array
|
|
383
403
|
* @returns Shuffled array
|
|
384
404
|
*/
|
|
@@ -386,7 +406,7 @@ function shuffle(array) {
|
|
|
386
406
|
if (!Array.isArray(array)) return [];
|
|
387
407
|
const shuffled = array.slice();
|
|
388
408
|
if (shuffled.length < 2) return shuffled;
|
|
389
|
-
let index =
|
|
409
|
+
let index = shuffled.length;
|
|
390
410
|
while (--index >= 0) {
|
|
391
411
|
const random = getRandomInteger(0, index);
|
|
392
412
|
[shuffled[index], shuffled[random]] = [shuffled[random], shuffled[index]];
|
|
@@ -482,15 +502,17 @@ function times(length, value) {
|
|
|
482
502
|
//#region src/array/get.ts
|
|
483
503
|
function getArray(value, indiced) {
|
|
484
504
|
if (Array.isArray(value)) return value;
|
|
485
|
-
if (value instanceof Map
|
|
505
|
+
if (value instanceof Map) return [...value.entries()];
|
|
506
|
+
if (value instanceof Set) return [...value.values()];
|
|
486
507
|
if (isNonPlainObject(value)) return [value];
|
|
487
|
-
if (indiced !== true) return Object.
|
|
508
|
+
if (indiced !== true) return Object.entries(value);
|
|
488
509
|
const keys = Object.keys(value);
|
|
489
510
|
const { length } = keys;
|
|
490
511
|
const array = [];
|
|
491
512
|
for (let index = 0; index < length; index += 1) {
|
|
492
513
|
const key = keys[index];
|
|
493
|
-
|
|
514
|
+
const asNumber = Number.parseInt(key, 10);
|
|
515
|
+
if (!Number.isNaN(asNumber)) array[asNumber] = value[key];
|
|
494
516
|
}
|
|
495
517
|
return array;
|
|
496
518
|
}
|
|
@@ -501,7 +523,7 @@ function insertChunkedValues(type, array, items, start, deleteCount) {
|
|
|
501
523
|
const actualStart = Math.min(Math.max(0, start), array.length);
|
|
502
524
|
const chunked = chunk(items);
|
|
503
525
|
const lastIndex = chunked.length - 1;
|
|
504
|
-
let index =
|
|
526
|
+
let index = chunked.length;
|
|
505
527
|
let returned;
|
|
506
528
|
while (index > 0) {
|
|
507
529
|
index -= 1;
|
|
@@ -816,7 +838,7 @@ move.toIndex = moveToIndex;
|
|
|
816
838
|
*
|
|
817
839
|
* If the from index is out of bounds, the array will be returned unchanged
|
|
818
840
|
*
|
|
819
|
-
*
|
|
841
|
+
* _Available as `moveIndices` and `move.indices`_
|
|
820
842
|
*
|
|
821
843
|
* @param array Array to move within
|
|
822
844
|
* @param from Index to move from
|
|
@@ -909,8 +931,20 @@ const aggregators = {
|
|
|
909
931
|
//#region src/internal/string.ts
|
|
910
932
|
/**
|
|
911
933
|
* Get the string value from any value
|
|
934
|
+
*
|
|
912
935
|
* @param value Original value
|
|
913
936
|
* @returns String representation of the value
|
|
937
|
+
*
|
|
938
|
+
* @example
|
|
939
|
+
* ```typescript
|
|
940
|
+
* getString(null) // => ''
|
|
941
|
+
* getString('foo') // => 'foo'
|
|
942
|
+
* getString(123) // => '123'
|
|
943
|
+
* getString(true) // => 'true'
|
|
944
|
+
* getString([1, 2, 3]) // => '1,2,3'
|
|
945
|
+
* getString({a: 1}) // => '{"a":1}'
|
|
946
|
+
* getString(() => 123) // => '123'
|
|
947
|
+
* ```
|
|
914
948
|
*/
|
|
915
949
|
function getString(value) {
|
|
916
950
|
if (typeof value === "string") return value;
|
|
@@ -923,10 +957,20 @@ function getString(value) {
|
|
|
923
957
|
function ignoreKey(key) {
|
|
924
958
|
return EXPRESSION_IGNORED.test(key);
|
|
925
959
|
}
|
|
960
|
+
function interpolate(strings, values) {
|
|
961
|
+
const { length } = strings;
|
|
962
|
+
let interpolated = "";
|
|
963
|
+
for (let index = 0; index < length; index += 1) {
|
|
964
|
+
const value = values[index];
|
|
965
|
+
interpolated += `${strings[index]}${Array.isArray(value) ? join(value.map(getString)) : getString(value)}`;
|
|
966
|
+
}
|
|
967
|
+
return interpolated;
|
|
968
|
+
}
|
|
926
969
|
/**
|
|
927
970
|
* Join an array of values into a string _(while ignoring empty values)_
|
|
928
971
|
*
|
|
929
972
|
* _(`null`, `undefined`, and any values that become whitespace-only strings are considered empty)_
|
|
973
|
+
*
|
|
930
974
|
* @param array Array of values
|
|
931
975
|
* @param delimiter Delimiter to use between values
|
|
932
976
|
* @returns Joined string
|
|
@@ -957,6 +1001,7 @@ function tryEncode(value) {
|
|
|
957
1001
|
}
|
|
958
1002
|
/**
|
|
959
1003
|
* Split a string into words _(and other readable parts)_
|
|
1004
|
+
*
|
|
960
1005
|
* @param value Original string
|
|
961
1006
|
* @returns Array of words found in the string
|
|
962
1007
|
*/
|
|
@@ -1025,6 +1070,7 @@ function isConstructable(value) {
|
|
|
1025
1070
|
const COMPARE_NAME = "compare";
|
|
1026
1071
|
/**
|
|
1027
1072
|
* Compare two values _(for sorting purposes)_
|
|
1073
|
+
*
|
|
1028
1074
|
* @param first First value
|
|
1029
1075
|
* @param second Second value
|
|
1030
1076
|
* @returns `0` if equal; `-1` first comes before second; `1` first comes after second
|
|
@@ -1077,7 +1123,8 @@ function compareValue(first, second, compareStrings) {
|
|
|
1077
1123
|
/**
|
|
1078
1124
|
* Deregister a custom comparison handler for a class
|
|
1079
1125
|
*
|
|
1080
|
-
*
|
|
1126
|
+
* _Available as `deregisterComparator` and `compare.deregister`_
|
|
1127
|
+
*
|
|
1081
1128
|
* @param constructor Class constructor
|
|
1082
1129
|
*/
|
|
1083
1130
|
function deregisterComparator(constructor) {
|
|
@@ -1090,7 +1137,8 @@ function getComparisonParts(value) {
|
|
|
1090
1137
|
/**
|
|
1091
1138
|
* Register a custom comparison handler for a class
|
|
1092
1139
|
*
|
|
1093
|
-
*
|
|
1140
|
+
* _Available as `registerComparator` and `compare.register`_
|
|
1141
|
+
*
|
|
1094
1142
|
* @param constructor Class constructor
|
|
1095
1143
|
* @param handler Method name or comparison function _(defaults to `compare`)_
|
|
1096
1144
|
*/
|
|
@@ -1110,7 +1158,7 @@ function getComparisonSorter(callback, modifier) {
|
|
|
1110
1158
|
modifier,
|
|
1111
1159
|
compare: { simple: callback },
|
|
1112
1160
|
get: false,
|
|
1113
|
-
identifier:
|
|
1161
|
+
identifier: callback.toString()
|
|
1114
1162
|
};
|
|
1115
1163
|
}
|
|
1116
1164
|
function getComparisonValue(first, second, sorters, length) {
|
|
@@ -1179,11 +1227,12 @@ function getSorters(value, modifier) {
|
|
|
1179
1227
|
return sorters.filter((value, index, array) => array.findIndex((next) => next.identifier === value.identifier) === index);
|
|
1180
1228
|
}
|
|
1181
1229
|
function getValueSorter(value, modifier) {
|
|
1230
|
+
const isFunction = typeof value === "function";
|
|
1182
1231
|
return {
|
|
1183
1232
|
modifier,
|
|
1184
1233
|
get: true,
|
|
1185
|
-
identifier:
|
|
1186
|
-
value:
|
|
1234
|
+
identifier: isFunction ? value.toString() : value,
|
|
1235
|
+
value: isFunction ? value : (item) => item[value]
|
|
1187
1236
|
};
|
|
1188
1237
|
}
|
|
1189
1238
|
function initializeSorter(first, second) {
|
|
@@ -1271,7 +1320,7 @@ function swapArrays(array, from, to, key) {
|
|
|
1271
1320
|
*
|
|
1272
1321
|
* If either index is out of bounds, the array will be returned unchanged
|
|
1273
1322
|
*
|
|
1274
|
-
*
|
|
1323
|
+
* _Available as `swapIndices` and `swap.indices`_
|
|
1275
1324
|
*
|
|
1276
1325
|
* @param array Array of items to swap
|
|
1277
1326
|
* @param first First index _(can be negative to count from the end)_
|
|
@@ -1333,28 +1382,24 @@ function toRecordArrays(array, first, second) {
|
|
|
1333
1382
|
}
|
|
1334
1383
|
//#endregion
|
|
1335
1384
|
//#region src/internal/result.ts
|
|
1336
|
-
function _isResult(value, okValue) {
|
|
1337
|
-
if (isNonPlainObject(value)) return false;
|
|
1338
|
-
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1339
|
-
}
|
|
1340
1385
|
function isError(value, extended) {
|
|
1341
|
-
return
|
|
1386
|
+
return isResultValue(value, false) && (extended === true ? value.original instanceof Error : true);
|
|
1342
1387
|
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Is the result ok?
|
|
1345
|
-
* @param result Result to check
|
|
1346
|
-
* @returns `true` if the result is ok, `false` otherwise
|
|
1347
|
-
*/
|
|
1348
1388
|
function isOk(value) {
|
|
1349
|
-
return
|
|
1389
|
+
return isResultValue(value, true);
|
|
1350
1390
|
}
|
|
1351
1391
|
/**
|
|
1352
|
-
* Is the value a
|
|
1392
|
+
* Is the value a _Result_?
|
|
1393
|
+
*
|
|
1353
1394
|
* @param value Value to check
|
|
1354
|
-
* @returns `true` if the value is a
|
|
1395
|
+
* @returns `true` if the value is a _Result_, `false` otherwise
|
|
1355
1396
|
*/
|
|
1356
1397
|
function isResult(value) {
|
|
1357
|
-
return
|
|
1398
|
+
return isResultValue(value, true) || isResultValue(value, false);
|
|
1399
|
+
}
|
|
1400
|
+
function isResultValue(value, okValue) {
|
|
1401
|
+
if (isNonPlainObject(value)) return false;
|
|
1402
|
+
return value.ok === okValue && (okValue ? PROPERTY_VALUE : PROPERTY_ERROR) in value;
|
|
1358
1403
|
}
|
|
1359
1404
|
const PROPERTY_ERROR = "error";
|
|
1360
1405
|
const PROPERTY_VALUE = "value";
|
|
@@ -1373,6 +1418,7 @@ function getError(value, original) {
|
|
|
1373
1418
|
}
|
|
1374
1419
|
/**
|
|
1375
1420
|
* Creates an ok result
|
|
1421
|
+
*
|
|
1376
1422
|
* @param value Value
|
|
1377
1423
|
* @returns Ok result
|
|
1378
1424
|
*/
|
|
@@ -1383,10 +1429,11 @@ function ok(value) {
|
|
|
1383
1429
|
};
|
|
1384
1430
|
}
|
|
1385
1431
|
/**
|
|
1386
|
-
* Converts a
|
|
1432
|
+
* Converts a _Result_ to a _Promise_
|
|
1387
1433
|
*
|
|
1388
1434
|
* Resolves if ok, rejects for error
|
|
1389
|
-
*
|
|
1435
|
+
*
|
|
1436
|
+
* @param result _Result_ to convert
|
|
1390
1437
|
* @returns Promised result
|
|
1391
1438
|
*/
|
|
1392
1439
|
async function toPromise(result) {
|
|
@@ -1455,6 +1502,7 @@ function hasValueResult(data, path, ignoreCase) {
|
|
|
1455
1502
|
//#region src/function/assert.ts
|
|
1456
1503
|
/**
|
|
1457
1504
|
* Asserts that a condition is true, throwing an error if it is not
|
|
1505
|
+
*
|
|
1458
1506
|
* @param condition Condition to assert
|
|
1459
1507
|
* @param message Error message
|
|
1460
1508
|
* @param error Error constructor _(defaults to `Error`)_
|
|
@@ -1468,13 +1516,14 @@ assert.instanceOf = assertInstanceOf;
|
|
|
1468
1516
|
assert.is = assertIs;
|
|
1469
1517
|
assert.property = assertProperty;
|
|
1470
1518
|
/**
|
|
1471
|
-
* Creates an
|
|
1519
|
+
* Creates an _Asserter_ that asserts a condition is true, throwing an error if it is not
|
|
1520
|
+
*
|
|
1521
|
+
* _Available as `assertCondition` and `assert.condition`_
|
|
1472
1522
|
*
|
|
1473
|
-
* Available as `assertCondition` and `assert.condition`
|
|
1474
1523
|
* @param condition Condition to assert
|
|
1475
1524
|
* @param message Error message
|
|
1476
1525
|
* @param error Error constructor _(defaults to `Error`)_
|
|
1477
|
-
* @returns
|
|
1526
|
+
* @returns _Asserter_
|
|
1478
1527
|
*/
|
|
1479
1528
|
function assertCondition(condition, message, error) {
|
|
1480
1529
|
return (value) => {
|
|
@@ -1484,7 +1533,8 @@ function assertCondition(condition, message, error) {
|
|
|
1484
1533
|
/**
|
|
1485
1534
|
* Asserts that a value is defined, throwing an error if it is not
|
|
1486
1535
|
*
|
|
1487
|
-
*
|
|
1536
|
+
* _Available as `assertDefined` and `assert.defined`_
|
|
1537
|
+
*
|
|
1488
1538
|
* @param value Value to assert
|
|
1489
1539
|
* @param message Error message
|
|
1490
1540
|
* @param error Error constructor _(defaults to `Error`)_
|
|
@@ -1493,13 +1543,14 @@ function assertDefined(value, message, error) {
|
|
|
1493
1543
|
assert(() => value != null, message ?? MESSAGE_VALUE_DEFINED, error);
|
|
1494
1544
|
}
|
|
1495
1545
|
/**
|
|
1496
|
-
* Creates an
|
|
1546
|
+
* Creates an _Asserter_ that asserts a value is an instance of a constructor, throwing an error if it is not
|
|
1547
|
+
*
|
|
1548
|
+
* _Available as `assertInstanceOf` and `assert.instanceOf`_
|
|
1497
1549
|
*
|
|
1498
|
-
* Available as `assertInstanceOf` and `assert.instanceOf`
|
|
1499
1550
|
* @param constructor Constructor to check against
|
|
1500
1551
|
* @param message Error message
|
|
1501
1552
|
* @param error Error constructor _(defaults to `Error`)_
|
|
1502
|
-
* @returns
|
|
1553
|
+
* @returns _Asserter_
|
|
1503
1554
|
*/
|
|
1504
1555
|
function assertInstanceOf(constructor, message, error) {
|
|
1505
1556
|
return (value) => {
|
|
@@ -1507,13 +1558,14 @@ function assertInstanceOf(constructor, message, error) {
|
|
|
1507
1558
|
};
|
|
1508
1559
|
}
|
|
1509
1560
|
/**
|
|
1510
|
-
* Creates an
|
|
1561
|
+
* Creates an _Asserter_ that asserts a value is of a specific type, throwing an error if it is not
|
|
1562
|
+
*
|
|
1563
|
+
* _Available as `assertIs` and `assert.is`_
|
|
1511
1564
|
*
|
|
1512
|
-
* Available as `assertIs` and `assert.is`
|
|
1513
1565
|
* @param condition Type guard function to check the value
|
|
1514
1566
|
* @param message Error message
|
|
1515
1567
|
* @param error Error constructor _(defaults to `Error`)_
|
|
1516
|
-
* @returns
|
|
1568
|
+
* @returns _Asserter_
|
|
1517
1569
|
*/
|
|
1518
1570
|
function assertIs(condition, message, error) {
|
|
1519
1571
|
return (value) => {
|
|
@@ -1521,14 +1573,15 @@ function assertIs(condition, message, error) {
|
|
|
1521
1573
|
};
|
|
1522
1574
|
}
|
|
1523
1575
|
/**
|
|
1524
|
-
* Creates an
|
|
1576
|
+
* Creates an _Asserter_ that asserts a property of a value exists and satisfies a condition, throwing an error if it does not
|
|
1577
|
+
*
|
|
1578
|
+
* _Available as `assertProperty` and `assert.property`_
|
|
1525
1579
|
*
|
|
1526
|
-
* Available as `assertProperty` and `assert.property`
|
|
1527
1580
|
* @param path Path to the property to check, e.g., `foo.bar.baz` for a nested property
|
|
1528
1581
|
* @param condition Condition to assert for the property
|
|
1529
1582
|
* @param message Error message
|
|
1530
1583
|
* @param error Error constructor _(defaults to `Error`)_
|
|
1531
|
-
* @returns
|
|
1584
|
+
* @returns _Asserter_
|
|
1532
1585
|
*/
|
|
1533
1586
|
function assertProperty(path, condition, message, error) {
|
|
1534
1587
|
return (value) => {
|
|
@@ -1549,6 +1602,7 @@ function noop() {}
|
|
|
1549
1602
|
//#region src/internal/number.ts
|
|
1550
1603
|
/**
|
|
1551
1604
|
* Is the number between a minimum and maximum value?
|
|
1605
|
+
*
|
|
1552
1606
|
* @param value Value to check
|
|
1553
1607
|
* @param minimum Minimum value
|
|
1554
1608
|
* @param maximum Maximum value
|
|
@@ -1565,11 +1619,18 @@ function between(value, minimum, maximum) {
|
|
|
1565
1619
|
}
|
|
1566
1620
|
/**
|
|
1567
1621
|
* Clamp a number between a minimum and maximum value
|
|
1622
|
+
*
|
|
1568
1623
|
* @param value Value to clamp
|
|
1569
1624
|
* @param minimum Minimum value
|
|
1570
1625
|
* @param maximum Maximum value
|
|
1571
1626
|
* @param loop If `true`, the value will loop around when smaller than the minimum or larger than the maximum _(defaults to `false`)_
|
|
1572
1627
|
* @returns Clamped value
|
|
1628
|
+
*
|
|
1629
|
+
* @example
|
|
1630
|
+
* ```typescript
|
|
1631
|
+
* clamp(10, 0, 5); // => 5
|
|
1632
|
+
* clamp(10, 0, 5, true); // => 0
|
|
1633
|
+
* ```
|
|
1573
1634
|
*/
|
|
1574
1635
|
function clamp(value, minimum, maximum, loop) {
|
|
1575
1636
|
if (![
|
|
@@ -1581,9 +1642,12 @@ function clamp(value, minimum, maximum, loop) {
|
|
|
1581
1642
|
return value > maximum ? loop === true ? minimum : maximum : value;
|
|
1582
1643
|
}
|
|
1583
1644
|
/**
|
|
1584
|
-
* Get the number value from an unknown value
|
|
1645
|
+
* Get the number value from an unknown value
|
|
1646
|
+
*
|
|
1647
|
+
* _(Based on Lodash)_
|
|
1648
|
+
*
|
|
1585
1649
|
* @param value Original value
|
|
1586
|
-
* @returns Original value as a number, or `NaN` if the value is unable to be parsed
|
|
1650
|
+
* @returns Original value as a number, or `Number.NaN` if the value is unable to be parsed
|
|
1587
1651
|
*/
|
|
1588
1652
|
function getNumber(value) {
|
|
1589
1653
|
if (typeof value === "number") return value;
|
|
@@ -1620,17 +1684,17 @@ const MAXIMUM_DEFAULT = 1048576;
|
|
|
1620
1684
|
//#endregion
|
|
1621
1685
|
//#region src/sized/map.ts
|
|
1622
1686
|
/**
|
|
1623
|
-
* A
|
|
1687
|
+
* A _Map_ with a maximum size
|
|
1624
1688
|
*
|
|
1625
|
-
* Behavior is similar to a _LRU_
|
|
1689
|
+
* Behavior is similar to a _LRU_ cache, where the least recently used entries are removed
|
|
1626
1690
|
*/
|
|
1627
1691
|
var SizedMap = class extends Map {
|
|
1628
1692
|
/**
|
|
1629
|
-
* The maximum size of the
|
|
1693
|
+
* The maximum size of the _Map_
|
|
1630
1694
|
*/
|
|
1631
1695
|
#maximumSize;
|
|
1632
1696
|
/**
|
|
1633
|
-
* Is the
|
|
1697
|
+
* Is the _Map_ full?
|
|
1634
1698
|
*/
|
|
1635
1699
|
get full() {
|
|
1636
1700
|
return super.size >= this.#maximumSize;
|
|
@@ -1674,18 +1738,22 @@ var SizedMap = class extends Map {
|
|
|
1674
1738
|
//#endregion
|
|
1675
1739
|
//#region src/function/memoize.ts
|
|
1676
1740
|
/**
|
|
1677
|
-
* A
|
|
1741
|
+
* A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
1678
1742
|
*/
|
|
1679
1743
|
var Memoized = class {
|
|
1680
1744
|
#state;
|
|
1681
1745
|
/**
|
|
1682
1746
|
* Maximum cache size
|
|
1747
|
+
*
|
|
1748
|
+
* @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
1683
1749
|
*/
|
|
1684
1750
|
get maximum() {
|
|
1685
1751
|
return this.#state.cache?.maximum ?? NaN;
|
|
1686
1752
|
}
|
|
1687
1753
|
/**
|
|
1688
1754
|
* Current cache size
|
|
1755
|
+
*
|
|
1756
|
+
* @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
1689
1757
|
*/
|
|
1690
1758
|
get size() {
|
|
1691
1759
|
return this.#state.cache?.size ?? NaN;
|
|
@@ -1712,6 +1780,7 @@ var Memoized = class {
|
|
|
1712
1780
|
}
|
|
1713
1781
|
/**
|
|
1714
1782
|
* Delete a result from the cache
|
|
1783
|
+
*
|
|
1715
1784
|
* @param key Key to delete
|
|
1716
1785
|
* @returns `true` if the key existed and was removed, otherwise `false`
|
|
1717
1786
|
*/
|
|
@@ -1719,7 +1788,9 @@ var Memoized = class {
|
|
|
1719
1788
|
return this.#state.cache?.delete(key) ?? false;
|
|
1720
1789
|
}
|
|
1721
1790
|
/**
|
|
1722
|
-
* Destroy the instance
|
|
1791
|
+
* Destroy the instance
|
|
1792
|
+
*
|
|
1793
|
+
* _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
|
|
1723
1794
|
*/
|
|
1724
1795
|
destroy() {
|
|
1725
1796
|
this.#state.cache?.clear();
|
|
@@ -1728,6 +1799,7 @@ var Memoized = class {
|
|
|
1728
1799
|
}
|
|
1729
1800
|
/**
|
|
1730
1801
|
* Get a result from the cache
|
|
1802
|
+
*
|
|
1731
1803
|
* @param key Key to get
|
|
1732
1804
|
* @returns Cached result or `undefined` if it does not exist
|
|
1733
1805
|
*/
|
|
@@ -1736,6 +1808,7 @@ var Memoized = class {
|
|
|
1736
1808
|
}
|
|
1737
1809
|
/**
|
|
1738
1810
|
* Does the result exist?
|
|
1811
|
+
*
|
|
1739
1812
|
* @param key Key to check
|
|
1740
1813
|
* @returns `true` if the result exists, otherwise `false`
|
|
1741
1814
|
*/
|
|
@@ -1744,11 +1817,12 @@ var Memoized = class {
|
|
|
1744
1817
|
}
|
|
1745
1818
|
/**
|
|
1746
1819
|
* Run the callback with the provided parameters
|
|
1820
|
+
*
|
|
1747
1821
|
* @param parameters Parameters to pass to the callback
|
|
1748
1822
|
* @returns Cached or computed _(then cached)_ result
|
|
1749
1823
|
*/
|
|
1750
1824
|
run(...parameters) {
|
|
1751
|
-
if (this.#state.cache == null || this.#state.getter == null) throw new Error(
|
|
1825
|
+
if (this.#state.cache == null || this.#state.getter == null) throw new Error(MEMOIZED_ERROR_DESTROYED);
|
|
1752
1826
|
return this.#state.getter(...parameters);
|
|
1753
1827
|
}
|
|
1754
1828
|
};
|
|
@@ -1761,14 +1835,18 @@ function getMemoizationOptions(input) {
|
|
|
1761
1835
|
}
|
|
1762
1836
|
/**
|
|
1763
1837
|
* Memoize a function, caching and retrieving results based on the first parameter
|
|
1838
|
+
*
|
|
1764
1839
|
* @param callback Callback to memoize
|
|
1765
1840
|
* @param options Memoization options
|
|
1766
|
-
* @returns
|
|
1841
|
+
* @returns _Memoized_ instance
|
|
1767
1842
|
*/
|
|
1768
1843
|
function memoize(callback, options) {
|
|
1844
|
+
if (typeof callback !== "function") throw new TypeError(MEMOIZED_ERROR_CALLBACK);
|
|
1769
1845
|
return new Memoized(callback, getMemoizationOptions(options));
|
|
1770
1846
|
}
|
|
1771
1847
|
const DEFAULT_CACHE_SIZE = 1024;
|
|
1848
|
+
const MEMOIZED_ERROR_CALLBACK = "Memoized requires a callback function";
|
|
1849
|
+
const MEMOIZED_ERROR_DESTROYED = "The Memoized instance has been destroyed";
|
|
1772
1850
|
const SEPARATOR = "_";
|
|
1773
1851
|
//#endregion
|
|
1774
1852
|
//#region src/internal/function/timer.ts
|
|
@@ -1859,11 +1937,11 @@ const startTimer = typeof requestAnimationFrame === "function" ? requestAnimatio
|
|
|
1859
1937
|
/**
|
|
1860
1938
|
* Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
1861
1939
|
*
|
|
1862
|
-
* When called, successful _(finished)_ results will resolve and errors will reject
|
|
1940
|
+
* - When called, successful _(finished)_ results will resolve and errors will reject
|
|
1941
|
+
* - On subsequent calls, existing calls will be canceled _(rejected)_, the timer reset, and will wait another `time` milliseconds before the new call is made _(and so on...)_
|
|
1863
1942
|
*
|
|
1864
|
-
*
|
|
1943
|
+
* _Available as `asyncDebounce` and `debounce.async`_
|
|
1865
1944
|
*
|
|
1866
|
-
* Available as `asyncDebounce` and `debounce.async`
|
|
1867
1945
|
* @param callback Callback to debounce
|
|
1868
1946
|
* @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
|
|
1869
1947
|
* @returns Debounced callback handler with a `cancel` method
|
|
@@ -1874,11 +1952,11 @@ function asyncDebounce(callback, time) {
|
|
|
1874
1952
|
/**
|
|
1875
1953
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
1876
1954
|
*
|
|
1877
|
-
* When called, successful _(finished)_ results will resolve and errors will reject
|
|
1955
|
+
* - When called, successful _(finished)_ results will resolve and errors will reject
|
|
1956
|
+
* - On subsequent calls, existing calls will be canceled _(rejected)_ and will wait until the next valid time to call the callback again _(and so on...)_
|
|
1878
1957
|
*
|
|
1879
|
-
*
|
|
1958
|
+
* _Available as `asyncThrottle` and `throttle.async`_
|
|
1880
1959
|
*
|
|
1881
|
-
* Available as `asyncThrottle` and `throttle.async`
|
|
1882
1960
|
* @param callback Callback to throttle
|
|
1883
1961
|
* @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
|
|
1884
1962
|
* @returns Throttled callback handler with a `cancel` method
|
|
@@ -1890,6 +1968,7 @@ function asyncThrottle(callback, time) {
|
|
|
1890
1968
|
* Debounce a function, ensuring it is only called after `time` milliseconds have passed
|
|
1891
1969
|
*
|
|
1892
1970
|
* On subsequent calls, the timer is reset and will wait another `time` milliseconds _(and so on...)_
|
|
1971
|
+
*
|
|
1893
1972
|
* @param callback Callback to debounce
|
|
1894
1973
|
* @param time Time in milliseconds to wait before calling the callback _(defaults to `0`; e.g., as soon as possible)_
|
|
1895
1974
|
* @returns Debounced callback handler with a `cancel` method
|
|
@@ -1900,6 +1979,7 @@ function debounce(callback, time) {
|
|
|
1900
1979
|
debounce.async = asyncDebounce;
|
|
1901
1980
|
/**
|
|
1902
1981
|
* Throttle a function, ensuring it is only called once every `time` milliseconds
|
|
1982
|
+
*
|
|
1903
1983
|
* @param callback Callback to throttle
|
|
1904
1984
|
* @param time Time in milliseconds to wait before calling the callback again _(defaults to `0`; e.g., as soon as possible)_
|
|
1905
1985
|
* @returns Throttled callback handler with a `cancel` method
|
|
@@ -1913,9 +1993,10 @@ throttle.async = asyncThrottle;
|
|
|
1913
1993
|
/**
|
|
1914
1994
|
* Create an asynchronous function that can only be called once, rejecting or resolving the same result on subsequent calls
|
|
1915
1995
|
*
|
|
1916
|
-
*
|
|
1996
|
+
* _Available as `asyncOnce` and `once.async`_
|
|
1997
|
+
*
|
|
1917
1998
|
* @param callback Callback to use once
|
|
1918
|
-
* @returns
|
|
1999
|
+
* @returns _Once_ callback
|
|
1919
2000
|
*/
|
|
1920
2001
|
function asyncOnce(callback) {
|
|
1921
2002
|
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
@@ -1976,8 +2057,9 @@ function handleOnceResult(state, value, error) {
|
|
|
1976
2057
|
}
|
|
1977
2058
|
/**
|
|
1978
2059
|
* Create a function that can only be called once, returning the same value on subsequent calls
|
|
2060
|
+
*
|
|
1979
2061
|
* @param callback Callback to use once
|
|
1980
|
-
* @returns
|
|
2062
|
+
* @returns _Once_ callback
|
|
1981
2063
|
*/
|
|
1982
2064
|
function once(callback) {
|
|
1983
2065
|
assert(() => typeof callback === "function", ONCE_MESSAGE_EXPECTATION);
|
|
@@ -2023,7 +2105,8 @@ var RetryError = class extends Error {
|
|
|
2023
2105
|
/**
|
|
2024
2106
|
* Retry a callback a specified number of times, with a delay between attempts
|
|
2025
2107
|
*
|
|
2026
|
-
*
|
|
2108
|
+
* _Available as `asyncRetry` and `retry.async`_
|
|
2109
|
+
*
|
|
2027
2110
|
* @param callback Callback to retry
|
|
2028
2111
|
* @param options Retry options
|
|
2029
2112
|
* @returns Callback result
|
|
@@ -2066,6 +2149,7 @@ function getRetryOptions(input) {
|
|
|
2066
2149
|
}
|
|
2067
2150
|
/**
|
|
2068
2151
|
* Retry a callback a specified number of times
|
|
2152
|
+
*
|
|
2069
2153
|
* @param callback Callback to retry
|
|
2070
2154
|
* @param options Retry options
|
|
2071
2155
|
* @returns Callback result
|
|
@@ -2152,11 +2236,112 @@ const MESSAGE_PIPE_PROMISE = "Synchronous Pipe received a promise. Use `pipe.asy
|
|
|
2152
2236
|
const assertFlowFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_FLOW_ARRAY, TypeError);
|
|
2153
2237
|
const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_PIPE_ARRAY, TypeError);
|
|
2154
2238
|
//#endregion
|
|
2239
|
+
//#region src/herald.ts
|
|
2240
|
+
var Events = class {
|
|
2241
|
+
#herald;
|
|
2242
|
+
constructor(herald) {
|
|
2243
|
+
this.#herald = herald;
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* Subscribe to an event with a callback
|
|
2247
|
+
*
|
|
2248
|
+
* @param event Event name
|
|
2249
|
+
* @param callback Callback function
|
|
2250
|
+
* @returns Unsubscriber function
|
|
2251
|
+
*/
|
|
2252
|
+
subscribe(event, callback) {
|
|
2253
|
+
return this.#herald.subscribe(event, callback);
|
|
2254
|
+
}
|
|
2255
|
+
/**
|
|
2256
|
+
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
2257
|
+
*
|
|
2258
|
+
* @param event Event name
|
|
2259
|
+
* @param callback Callback function
|
|
2260
|
+
* @returns Unsubscriber function
|
|
2261
|
+
*/
|
|
2262
|
+
unsubscribe(event, callback) {
|
|
2263
|
+
return this.#herald.unsubscribe(event, callback);
|
|
2264
|
+
}
|
|
2265
|
+
};
|
|
2266
|
+
/**
|
|
2267
|
+
* A _Herald_ is an announcer for named events, allowing emission, subscription, and unsubscription of events
|
|
2268
|
+
*/
|
|
2269
|
+
var Herald = class {
|
|
2270
|
+
#names;
|
|
2271
|
+
#subscribers = /* @__PURE__ */ new Map();
|
|
2272
|
+
constructor(names) {
|
|
2273
|
+
this.#names = new Set(names);
|
|
2274
|
+
Object.defineProperty(this, "events", { value: new Events(this) });
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Remove all event subscribers
|
|
2278
|
+
*/
|
|
2279
|
+
clear() {
|
|
2280
|
+
this.#subscribers.clear();
|
|
2281
|
+
}
|
|
2282
|
+
/**
|
|
2283
|
+
* Emit an event with parameters
|
|
2284
|
+
*
|
|
2285
|
+
* @param event Event name
|
|
2286
|
+
* @param parameters Event parameters
|
|
2287
|
+
*/
|
|
2288
|
+
emit(event, ...parameters) {
|
|
2289
|
+
const subscribers = this.#subscribers.get(event);
|
|
2290
|
+
if (subscribers == null) return;
|
|
2291
|
+
for (const callback of subscribers) callback(...parameters);
|
|
2292
|
+
}
|
|
2293
|
+
/**
|
|
2294
|
+
* Subscribe to an event with a callback
|
|
2295
|
+
*
|
|
2296
|
+
* @param event Event name
|
|
2297
|
+
* @param callback Callback function
|
|
2298
|
+
* @returns Unsubscriber function
|
|
2299
|
+
*/
|
|
2300
|
+
subscribe(event, callback) {
|
|
2301
|
+
if (!this.#names.has(event) || typeof callback !== "function") return noop;
|
|
2302
|
+
let subscribers = this.#subscribers.get(event);
|
|
2303
|
+
if (subscribers == null) {
|
|
2304
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
2305
|
+
this.#subscribers.set(event, subscribers);
|
|
2306
|
+
}
|
|
2307
|
+
subscribers.add(callback);
|
|
2308
|
+
return () => {
|
|
2309
|
+
subscribers?.delete(callback);
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
2314
|
+
*
|
|
2315
|
+
* @param event Event name
|
|
2316
|
+
* @param callback Callback function
|
|
2317
|
+
*/
|
|
2318
|
+
unsubscribe(event, callback) {
|
|
2319
|
+
if (!this.#names.has(event) || (callback != null ? typeof callback !== "function" : false)) return;
|
|
2320
|
+
const subscribers = this.#subscribers.get(event);
|
|
2321
|
+
if (subscribers == null) return;
|
|
2322
|
+
if (callback == null) subscribers.clear();
|
|
2323
|
+
else subscribers.delete(callback);
|
|
2324
|
+
if (callback == null || subscribers.size === 0) this.#subscribers.delete(event);
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
/**
|
|
2328
|
+
* Create a _Herald_ for announcing named events
|
|
2329
|
+
*
|
|
2330
|
+
* @param names Event names
|
|
2331
|
+
* @returns _Herald_ instance
|
|
2332
|
+
*/
|
|
2333
|
+
function herald(names) {
|
|
2334
|
+
if (!Array.isArray(names) || names.length === 0 || !names.every((name) => typeof name === "string")) throw new Error(MESSAGE);
|
|
2335
|
+
return new Herald(names);
|
|
2336
|
+
}
|
|
2337
|
+
const MESSAGE = "Herald requires an array of event names.";
|
|
2338
|
+
//#endregion
|
|
2155
2339
|
//#region src/internal/value/equal.ts
|
|
2156
2340
|
/**
|
|
2157
2341
|
* Deregister a equality comparison handler for a specific class
|
|
2158
2342
|
*
|
|
2159
|
-
*
|
|
2343
|
+
* _Available as `deregisterEqualizer` and `equal.deregister`_
|
|
2344
|
+
*
|
|
2160
2345
|
* @param constructor Class constructor
|
|
2161
2346
|
*/
|
|
2162
2347
|
function deregisterEqualizer(constructor) {
|
|
@@ -2254,7 +2439,7 @@ function equalValue(first, second, options) {
|
|
|
2254
2439
|
case typeof first !== typeof second: return false;
|
|
2255
2440
|
case typeof first === "string" && options.ignoreCase === true: return Object.is(first.toLocaleLowerCase(), second.toLocaleLowerCase());
|
|
2256
2441
|
case first instanceof ArrayBuffer && second instanceof ArrayBuffer: return equalArrayBuffer(first, second, options);
|
|
2257
|
-
case first instanceof Date && second instanceof Date: return Object.is(
|
|
2442
|
+
case first instanceof Date && second instanceof Date: return Object.is(first.getTime(), second.getTime());
|
|
2258
2443
|
case first instanceof DataView && second instanceof DataView: return equalDataView(first, second, options);
|
|
2259
2444
|
case first instanceof Error && second instanceof Error: return equalProperties(first, second, ERROR_PROPERTIES, options);
|
|
2260
2445
|
case first instanceof Map && second instanceof Map: return equalMap(first, second, options);
|
|
@@ -2295,7 +2480,8 @@ function getEqualOptions(input) {
|
|
|
2295
2480
|
/**
|
|
2296
2481
|
* Create an equalizer with predefined options
|
|
2297
2482
|
*
|
|
2298
|
-
*
|
|
2483
|
+
* _Available as `initializeEqualizer` and `equal.initialize`_
|
|
2484
|
+
*
|
|
2299
2485
|
* @param options Comparison options
|
|
2300
2486
|
* @returns Equalizer function
|
|
2301
2487
|
*/
|
|
@@ -2309,7 +2495,8 @@ function initializeEqualizer(options) {
|
|
|
2309
2495
|
/**
|
|
2310
2496
|
* Register a equality comparison function for a specific class
|
|
2311
2497
|
*
|
|
2312
|
-
*
|
|
2498
|
+
* _Available as `registerEqualizer` and `equal.register`_
|
|
2499
|
+
*
|
|
2313
2500
|
* @param constructor Class constructor
|
|
2314
2501
|
* @param handler Comparison function
|
|
2315
2502
|
*/
|
|
@@ -2348,7 +2535,7 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
2348
2535
|
let next = handleValue(target, currentPath, null, true, shouldIgnoreCase).value;
|
|
2349
2536
|
if (typeof next !== "object" || next === null) {
|
|
2350
2537
|
const nextPath = paths[index + 1];
|
|
2351
|
-
if (EXPRESSION_INDEX.test(nextPath)) next = Array.from({ length: Number
|
|
2538
|
+
if (EXPRESSION_INDEX.test(nextPath)) next = Array.from({ length: Number(nextPath) + 1 }, () => void 0);
|
|
2352
2539
|
else next = {};
|
|
2353
2540
|
target[currentPath] = next;
|
|
2354
2541
|
}
|
|
@@ -2358,100 +2545,10 @@ function setValue(data, path, value, ignoreCase) {
|
|
|
2358
2545
|
}
|
|
2359
2546
|
const EXPRESSION_INDEX = /^\d+$/;
|
|
2360
2547
|
//#endregion
|
|
2361
|
-
//#region src/kalas.ts
|
|
2362
|
-
var Events = class {
|
|
2363
|
-
#kalas;
|
|
2364
|
-
constructor(kalas) {
|
|
2365
|
-
this.#kalas = kalas;
|
|
2366
|
-
}
|
|
2367
|
-
/**
|
|
2368
|
-
* Subscribe to an event with a callback
|
|
2369
|
-
* @param event Event name
|
|
2370
|
-
* @param callback Callback function
|
|
2371
|
-
* @returns Unsubscriber function
|
|
2372
|
-
*/
|
|
2373
|
-
subscribe(event, callback) {
|
|
2374
|
-
return this.#kalas.subscribe(event, callback);
|
|
2375
|
-
}
|
|
2376
|
-
/**
|
|
2377
|
-
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
2378
|
-
* @param event Event name
|
|
2379
|
-
* @param callback Callback function
|
|
2380
|
-
* @returns Unsubscriber function
|
|
2381
|
-
*/
|
|
2382
|
-
unsubscribe(event, callback) {
|
|
2383
|
-
return this.#kalas.unsubscribe(event, callback);
|
|
2384
|
-
}
|
|
2385
|
-
};
|
|
2386
|
-
var Kalas = class {
|
|
2387
|
-
#names;
|
|
2388
|
-
#subscribers = /* @__PURE__ */ new Map();
|
|
2389
|
-
constructor(names) {
|
|
2390
|
-
this.#names = new Set(names);
|
|
2391
|
-
Object.defineProperty(this, "events", { value: new Events(this) });
|
|
2392
|
-
}
|
|
2393
|
-
/**
|
|
2394
|
-
* Remove all event subscribers
|
|
2395
|
-
*/
|
|
2396
|
-
clear() {
|
|
2397
|
-
this.#subscribers.clear();
|
|
2398
|
-
}
|
|
2399
|
-
/**
|
|
2400
|
-
* Emit an event with parameters
|
|
2401
|
-
* @param event Event name
|
|
2402
|
-
* @param parameters Event parameters
|
|
2403
|
-
*/
|
|
2404
|
-
emit(event, ...parameters) {
|
|
2405
|
-
const subscribers = this.#subscribers.get(event);
|
|
2406
|
-
if (subscribers == null) return;
|
|
2407
|
-
for (const callback of subscribers) callback(...parameters);
|
|
2408
|
-
}
|
|
2409
|
-
/**
|
|
2410
|
-
* Subscribe to an event with a callback
|
|
2411
|
-
* @param event Event name
|
|
2412
|
-
* @param callback Callback function
|
|
2413
|
-
* @returns Unsubscriber function
|
|
2414
|
-
*/
|
|
2415
|
-
subscribe(event, callback) {
|
|
2416
|
-
if (!this.#names.has(event) || typeof callback !== "function") return noop;
|
|
2417
|
-
let subscribers = this.#subscribers.get(event);
|
|
2418
|
-
if (subscribers == null) {
|
|
2419
|
-
subscribers = /* @__PURE__ */ new Set();
|
|
2420
|
-
this.#subscribers.set(event, subscribers);
|
|
2421
|
-
}
|
|
2422
|
-
subscribers.add(callback);
|
|
2423
|
-
return () => {
|
|
2424
|
-
subscribers?.delete(callback);
|
|
2425
|
-
};
|
|
2426
|
-
}
|
|
2427
|
-
/**
|
|
2428
|
-
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
2429
|
-
* @param event Event name
|
|
2430
|
-
* @param callback Callback function
|
|
2431
|
-
*/
|
|
2432
|
-
unsubscribe(event, callback) {
|
|
2433
|
-
if (!this.#names.has(event) || (callback != null ? typeof callback !== "function" : false)) return;
|
|
2434
|
-
const subscribers = this.#subscribers.get(event);
|
|
2435
|
-
if (subscribers == null) return;
|
|
2436
|
-
if (callback == null) subscribers.clear();
|
|
2437
|
-
else subscribers.delete(callback);
|
|
2438
|
-
if (callback == null || subscribers.size === 0) this.#subscribers.delete(event);
|
|
2439
|
-
}
|
|
2440
|
-
};
|
|
2441
|
-
/**
|
|
2442
|
-
* Create a Kalas _(party)_ for named events
|
|
2443
|
-
* @param names Event names
|
|
2444
|
-
* @returns Kalas instance
|
|
2445
|
-
*/
|
|
2446
|
-
function kalas(names) {
|
|
2447
|
-
if (!Array.isArray(names) || names.length === 0 || !names.every((name) => typeof name === "string")) throw new Error(MESSAGE);
|
|
2448
|
-
return new Kalas(names);
|
|
2449
|
-
}
|
|
2450
|
-
const MESSAGE = "Kalas requires an array of event names.";
|
|
2451
|
-
//#endregion
|
|
2452
2548
|
//#region src/string/case.ts
|
|
2453
2549
|
/**
|
|
2454
2550
|
* Convert a string to camel case _(thisIsCamelCase)_
|
|
2551
|
+
*
|
|
2455
2552
|
* @param value String to convert
|
|
2456
2553
|
* @returns Camel-cased string
|
|
2457
2554
|
*/
|
|
@@ -2460,6 +2557,7 @@ function camelCase(value) {
|
|
|
2460
2557
|
}
|
|
2461
2558
|
/**
|
|
2462
2559
|
* Capitalize the first letter of a string _(and lowercase the rest)_
|
|
2560
|
+
*
|
|
2463
2561
|
* @param value String to capitalize
|
|
2464
2562
|
* @returns Capitalized string
|
|
2465
2563
|
*/
|
|
@@ -2470,6 +2568,7 @@ function capitalize(value) {
|
|
|
2470
2568
|
}
|
|
2471
2569
|
/**
|
|
2472
2570
|
* Convert a string to kebab case _(this-is-kebab-case)_
|
|
2571
|
+
*
|
|
2473
2572
|
* @param value String to convert
|
|
2474
2573
|
* @returns Kebab-cased string
|
|
2475
2574
|
*/
|
|
@@ -2478,6 +2577,7 @@ function kebabCase(value) {
|
|
|
2478
2577
|
}
|
|
2479
2578
|
/**
|
|
2480
2579
|
* Convert a string to lower case
|
|
2580
|
+
*
|
|
2481
2581
|
* @param value String to convert
|
|
2482
2582
|
* @returns Lower-cased string
|
|
2483
2583
|
*/
|
|
@@ -2488,6 +2588,7 @@ function lowerCase(value) {
|
|
|
2488
2588
|
}
|
|
2489
2589
|
/**
|
|
2490
2590
|
* Convert a string to pascal case _(ThisIsPascalCase)_
|
|
2591
|
+
*
|
|
2491
2592
|
* @param value String to convert
|
|
2492
2593
|
* @returns Pascal-cased string
|
|
2493
2594
|
*/
|
|
@@ -2496,6 +2597,7 @@ function pascalCase(value) {
|
|
|
2496
2597
|
}
|
|
2497
2598
|
/**
|
|
2498
2599
|
* Convert a string to snake case _(this_is_snake_case)_
|
|
2600
|
+
*
|
|
2499
2601
|
* @param value String to convert
|
|
2500
2602
|
* @returns Snake-cased string
|
|
2501
2603
|
*/
|
|
@@ -2504,6 +2606,7 @@ function snakeCase(value) {
|
|
|
2504
2606
|
}
|
|
2505
2607
|
/**
|
|
2506
2608
|
* Convert a string to title case _(Capitalizing Every Word)_
|
|
2609
|
+
*
|
|
2507
2610
|
* @param value String to convert
|
|
2508
2611
|
* @returns Title-cased string
|
|
2509
2612
|
*/
|
|
@@ -2545,6 +2648,7 @@ function toCaseCallback(value) {
|
|
|
2545
2648
|
}
|
|
2546
2649
|
/**
|
|
2547
2650
|
* Convert a string to upper case
|
|
2651
|
+
*
|
|
2548
2652
|
* @param value String to convert
|
|
2549
2653
|
* @returns Upper-cased string
|
|
2550
2654
|
*/
|
|
@@ -2579,6 +2683,7 @@ let memoizedUpperCase;
|
|
|
2579
2683
|
//#region src/is.ts
|
|
2580
2684
|
/**
|
|
2581
2685
|
* Is the value empty, or only containing `null` or `undefined` values?
|
|
2686
|
+
*
|
|
2582
2687
|
* @param value Value to check
|
|
2583
2688
|
* @returns `true` if the value is considered empty, otherwise `false`
|
|
2584
2689
|
*/
|
|
@@ -2587,11 +2692,15 @@ function isEmpty(value) {
|
|
|
2587
2692
|
if (typeof value === "string") return value.length === 0;
|
|
2588
2693
|
const values = getArray(value);
|
|
2589
2694
|
const { length } = values;
|
|
2590
|
-
for (let index = 0; index < length; index += 1)
|
|
2695
|
+
for (let index = 0; index < length; index += 1) {
|
|
2696
|
+
const item = values[index];
|
|
2697
|
+
if (Array.isArray(item) ? item[1] != null : item != null) return false;
|
|
2698
|
+
}
|
|
2591
2699
|
return true;
|
|
2592
2700
|
}
|
|
2593
2701
|
/**
|
|
2594
2702
|
* Is the value not empty, or holding non-empty values?
|
|
2703
|
+
*
|
|
2595
2704
|
* @param value Value to check
|
|
2596
2705
|
* @returns `true` if the value is not considered empty, otherwise `false`
|
|
2597
2706
|
*/
|
|
@@ -2600,6 +2709,7 @@ function isNonEmpty(value) {
|
|
|
2600
2709
|
}
|
|
2601
2710
|
/**
|
|
2602
2711
|
* Is the value not `undefined` or `null`?
|
|
2712
|
+
*
|
|
2603
2713
|
* @param value Value to check
|
|
2604
2714
|
* @returns `true` if the value is not `undefined` or `null`, otherwise `false`
|
|
2605
2715
|
*/
|
|
@@ -2608,6 +2718,7 @@ function isNonNullable(value) {
|
|
|
2608
2718
|
}
|
|
2609
2719
|
/**
|
|
2610
2720
|
* Is the value not `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
2721
|
+
*
|
|
2611
2722
|
* @param value Value to check
|
|
2612
2723
|
* @returns `true` if the value is not `undefined`, `null`, or matches an empty string, otherwise `false`
|
|
2613
2724
|
*/
|
|
@@ -2616,6 +2727,7 @@ function isNonNullableOrEmpty(value) {
|
|
|
2616
2727
|
}
|
|
2617
2728
|
/**
|
|
2618
2729
|
* Is the value not `undefined`, `null`, or stringified as a whitespace-only string?
|
|
2730
|
+
*
|
|
2619
2731
|
* @param value Value to check
|
|
2620
2732
|
* @returns `true` if the value is not `undefined`, `null`, or matches a whitespace-only string, otherwise `false`
|
|
2621
2733
|
*/
|
|
@@ -2624,6 +2736,7 @@ function isNonNullableOrWhitespace(value) {
|
|
|
2624
2736
|
}
|
|
2625
2737
|
/**
|
|
2626
2738
|
* Is the value not a number or a number-like string?
|
|
2739
|
+
*
|
|
2627
2740
|
* @param value Value to check
|
|
2628
2741
|
* @returns `true` if the value is not a number or a number-like string, otherwise `false`
|
|
2629
2742
|
*/
|
|
@@ -2632,6 +2745,7 @@ function isNonNumerical(value) {
|
|
|
2632
2745
|
}
|
|
2633
2746
|
/**
|
|
2634
2747
|
* Is the value not an object _(or function)_?
|
|
2748
|
+
*
|
|
2635
2749
|
* @param value Value to check
|
|
2636
2750
|
* @returns `true` if the value is not an object, otherwise `false`
|
|
2637
2751
|
*/
|
|
@@ -2640,6 +2754,7 @@ function isNonObject(value) {
|
|
|
2640
2754
|
}
|
|
2641
2755
|
/**
|
|
2642
2756
|
* Is the value `undefined` or `null`?
|
|
2757
|
+
*
|
|
2643
2758
|
* @param value Value to check
|
|
2644
2759
|
* @returns `true` if the value is `undefined` or `null`, otherwise `false`
|
|
2645
2760
|
*/
|
|
@@ -2648,6 +2763,7 @@ function isNullable(value) {
|
|
|
2648
2763
|
}
|
|
2649
2764
|
/**
|
|
2650
2765
|
* Is the value `undefined`, `null`, or stringified as an empty _(no whitespace)_ string?
|
|
2766
|
+
*
|
|
2651
2767
|
* @param value Value to check
|
|
2652
2768
|
* @returns `true` if the value is nullable or matches an empty string, otherwise `false`
|
|
2653
2769
|
*/
|
|
@@ -2656,6 +2772,7 @@ function isNullableOrEmpty(value) {
|
|
|
2656
2772
|
}
|
|
2657
2773
|
/**
|
|
2658
2774
|
* Is the value `undefined`, `null`, or stringified as a whitespace-only string?
|
|
2775
|
+
*
|
|
2659
2776
|
* @param value Value to check
|
|
2660
2777
|
* @returns `true` if the value is nullable or matches a whitespace-only string, otherwise `false`
|
|
2661
2778
|
*/
|
|
@@ -2664,6 +2781,7 @@ function isNullableOrWhitespace(value) {
|
|
|
2664
2781
|
}
|
|
2665
2782
|
/**
|
|
2666
2783
|
* Is the value a number or a number-like string?
|
|
2784
|
+
*
|
|
2667
2785
|
* @param value Value to check
|
|
2668
2786
|
* @returns `true` if the value is a number or a number-like string, otherwise `false`
|
|
2669
2787
|
*/
|
|
@@ -2672,6 +2790,7 @@ function isNumerical(value) {
|
|
|
2672
2790
|
}
|
|
2673
2791
|
/**
|
|
2674
2792
|
* Is the value an object _(or function)_?
|
|
2793
|
+
*
|
|
2675
2794
|
* @param value Value to check
|
|
2676
2795
|
* @returns `true` if the value matches, otherwise `false`
|
|
2677
2796
|
*/
|
|
@@ -2683,6 +2802,7 @@ const EXPRESSION_WHITESPACE = /^\s*$/;
|
|
|
2683
2802
|
//#region src/string/match.ts
|
|
2684
2803
|
/**
|
|
2685
2804
|
* Check if a string ends with a specified substring
|
|
2805
|
+
*
|
|
2686
2806
|
* @param haystack String to look in
|
|
2687
2807
|
* @param needle String to look for
|
|
2688
2808
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
@@ -2693,6 +2813,7 @@ function endsWith(haystack, needle, ignoreCase) {
|
|
|
2693
2813
|
}
|
|
2694
2814
|
/**
|
|
2695
2815
|
* Check if a string includes a specified substring
|
|
2816
|
+
*
|
|
2696
2817
|
* @param haystack String to look in
|
|
2697
2818
|
* @param needle String to look for
|
|
2698
2819
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
@@ -2711,6 +2832,7 @@ function matchCallback(haystack, needle, ignoreCase) {
|
|
|
2711
2832
|
}
|
|
2712
2833
|
/**
|
|
2713
2834
|
* Check if a string starts with a specified substring
|
|
2835
|
+
*
|
|
2714
2836
|
* @param haystack String to look in
|
|
2715
2837
|
* @param needle String to look for
|
|
2716
2838
|
* @param ignoreCase Ignore case when matching? _(defaults to `false`)_
|
|
@@ -2732,12 +2854,16 @@ var Fuzzy = class {
|
|
|
2732
2854
|
#state;
|
|
2733
2855
|
/**
|
|
2734
2856
|
* Get items currently being searched through
|
|
2857
|
+
*
|
|
2858
|
+
* @returns Original items
|
|
2735
2859
|
*/
|
|
2736
2860
|
get items() {
|
|
2737
2861
|
return this.#state.items.slice();
|
|
2738
2862
|
}
|
|
2739
2863
|
/**
|
|
2740
2864
|
* Set new items to search through
|
|
2865
|
+
*
|
|
2866
|
+
* @param items New items to search through
|
|
2741
2867
|
*/
|
|
2742
2868
|
set items(items) {
|
|
2743
2869
|
if (Array.isArray(items)) {
|
|
@@ -2747,6 +2873,8 @@ var Fuzzy = class {
|
|
|
2747
2873
|
}
|
|
2748
2874
|
/**
|
|
2749
2875
|
* Get strings currently being searched through _(the stringified version of `items`)_
|
|
2876
|
+
*
|
|
2877
|
+
* @returns Stringified items
|
|
2750
2878
|
*/
|
|
2751
2879
|
get strings() {
|
|
2752
2880
|
return this.#state.strings.slice();
|
|
@@ -2801,6 +2929,7 @@ function fuzzy(items, configuration) {
|
|
|
2801
2929
|
fuzzy.match = fuzzyMatch;
|
|
2802
2930
|
/**
|
|
2803
2931
|
* Does the needle match the haystack in a fuzzy way?
|
|
2932
|
+
*
|
|
2804
2933
|
* @param haystack Haystack to search through
|
|
2805
2934
|
* @param needle Needle to search for
|
|
2806
2935
|
* @returns `true` if the needle matches the haystack in a fuzzy way, `false` otherwise
|
|
@@ -2926,7 +3055,8 @@ function dedent(value, ...values) {
|
|
|
2926
3055
|
return result.trim();
|
|
2927
3056
|
}
|
|
2928
3057
|
/**
|
|
2929
|
-
* Get a new UUID
|
|
3058
|
+
* Get a new UUID string _(version 4)_
|
|
3059
|
+
*
|
|
2930
3060
|
* @returns UUID string
|
|
2931
3061
|
*/
|
|
2932
3062
|
function getUuid() {
|
|
@@ -2943,14 +3073,9 @@ function getUuid() {
|
|
|
2943
3073
|
hex.substring(20, 32)
|
|
2944
3074
|
].join("-");
|
|
2945
3075
|
}
|
|
2946
|
-
function interpolate(strings, values) {
|
|
2947
|
-
const { length } = strings;
|
|
2948
|
-
let interpolated = "";
|
|
2949
|
-
for (let index = 0; index < length; index += 1) interpolated += `${strings[index]}${getString(values[index])}`;
|
|
2950
|
-
return interpolated;
|
|
2951
|
-
}
|
|
2952
3076
|
/**
|
|
2953
3077
|
* Parse a JSON string into its proper value _(or `undefined` if it fails)_
|
|
3078
|
+
*
|
|
2954
3079
|
* @param value JSON string to parse
|
|
2955
3080
|
* @param reviver Reviver function to transform the parsed values
|
|
2956
3081
|
* @returns Parsed value or `undefined` if parsing fails
|
|
@@ -2964,6 +3089,7 @@ function parse(value, reviver) {
|
|
|
2964
3089
|
}
|
|
2965
3090
|
/**
|
|
2966
3091
|
* Trim a string _(removing whitespace from both ends)_
|
|
3092
|
+
*
|
|
2967
3093
|
* @param value String to trim
|
|
2968
3094
|
* @returns Trimmed string
|
|
2969
3095
|
*/
|
|
@@ -2971,7 +3097,8 @@ function trim(value) {
|
|
|
2971
3097
|
return typeof value === "string" ? value.trim() : "";
|
|
2972
3098
|
}
|
|
2973
3099
|
/**
|
|
2974
|
-
* Truncate a string to a specified length
|
|
3100
|
+
* Truncate a string to a specified length
|
|
3101
|
+
*
|
|
2975
3102
|
* @param value String to truncate
|
|
2976
3103
|
* @param length Maximum length of the string after truncation
|
|
2977
3104
|
* @param suffix Suffix to append to the truncated string
|
|
@@ -2991,6 +3118,7 @@ const ZERO = "0";
|
|
|
2991
3118
|
//#region src/string/normalize.ts
|
|
2992
3119
|
/**
|
|
2993
3120
|
* Deburr a string, removing diacritical marks
|
|
3121
|
+
*
|
|
2994
3122
|
* @param value String to deburr
|
|
2995
3123
|
* @returns Deburred string
|
|
2996
3124
|
*/
|
|
@@ -3016,7 +3144,8 @@ function getNormalizeOptions(input) {
|
|
|
3016
3144
|
/**
|
|
3017
3145
|
* Initialize a string normalizer
|
|
3018
3146
|
*
|
|
3019
|
-
*
|
|
3147
|
+
* _Available as `initializeNormalizer` and `normalize.initialize`_
|
|
3148
|
+
*
|
|
3020
3149
|
* @param options Normalization options
|
|
3021
3150
|
* @returns Normalizer function
|
|
3022
3151
|
*/
|
|
@@ -3027,7 +3156,8 @@ function initializeNormalizer(options) {
|
|
|
3027
3156
|
/**
|
|
3028
3157
|
* Normalize a string
|
|
3029
3158
|
*
|
|
3030
|
-
*
|
|
3159
|
+
* _By default, the string will be trimmed, deburred, and then lowercased_
|
|
3160
|
+
*
|
|
3031
3161
|
* @param value String to normalize
|
|
3032
3162
|
* @param options Normalization options
|
|
3033
3163
|
* @returns Normalized string
|
|
@@ -3089,6 +3219,11 @@ const WHITESPACE_REPLACEMENT = " ";
|
|
|
3089
3219
|
let deburrMemoizer;
|
|
3090
3220
|
//#endregion
|
|
3091
3221
|
//#region src/string/template.ts
|
|
3222
|
+
function getRenderer(strings, values) {
|
|
3223
|
+
return (variables, options) => {
|
|
3224
|
+
return template(interpolate(strings, values), variables, options);
|
|
3225
|
+
};
|
|
3226
|
+
}
|
|
3092
3227
|
function getTemplateOptions(input) {
|
|
3093
3228
|
const options = isPlainObject(input) ? input : {};
|
|
3094
3229
|
return {
|
|
@@ -3098,7 +3233,7 @@ function getTemplateOptions(input) {
|
|
|
3098
3233
|
}
|
|
3099
3234
|
function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
3100
3235
|
if (typeof value !== "string") return "";
|
|
3101
|
-
if (typeof variables !== "object" || variables === null) return value;
|
|
3236
|
+
if (typeof variables !== "object" || variables === null || Object.keys(variables).length === 0) return value;
|
|
3102
3237
|
const values = {};
|
|
3103
3238
|
return value.replace(pattern, (_, key) => {
|
|
3104
3239
|
if (values[key] == null) {
|
|
@@ -3109,36 +3244,31 @@ function handleTemplate(value, pattern, ignoreCase, variables) {
|
|
|
3109
3244
|
});
|
|
3110
3245
|
}
|
|
3111
3246
|
/**
|
|
3112
|
-
* Create a
|
|
3247
|
+
* Create a _Templater_ with predefined options
|
|
3248
|
+
*
|
|
3249
|
+
* _Available as `initializeTemplater` and `template.initialize`_
|
|
3113
3250
|
*
|
|
3114
|
-
* Available as `initializeTemplater` and `template.initialize`
|
|
3115
3251
|
* @param options Templating options
|
|
3116
|
-
* @returns
|
|
3252
|
+
* @returns _Templater_ function
|
|
3117
3253
|
*/
|
|
3118
3254
|
function initializeTemplater(options) {
|
|
3119
3255
|
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
3120
|
-
return (value,
|
|
3121
|
-
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
3122
|
-
};
|
|
3256
|
+
return ((value, ...parameters) => {
|
|
3257
|
+
return isTemplateStringsArray(value) ? (variables) => handleTemplate(interpolate(value, parameters), pattern, ignoreCase, variables) : handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
3258
|
+
});
|
|
3123
3259
|
}
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
* @param options Templating options
|
|
3129
|
-
* @returns Templated string
|
|
3130
|
-
*/
|
|
3131
|
-
function template(value, variables, options) {
|
|
3132
|
-
const { ignoreCase, pattern } = getTemplateOptions(options);
|
|
3133
|
-
return handleTemplate(value, pattern, ignoreCase, variables);
|
|
3260
|
+
function template(value, ...parameters) {
|
|
3261
|
+
if (isTemplateStringsArray(value)) return getRenderer(value, parameters);
|
|
3262
|
+
const { ignoreCase, pattern } = getTemplateOptions(parameters[1]);
|
|
3263
|
+
return handleTemplate(value, pattern, ignoreCase, parameters[0]);
|
|
3134
3264
|
}
|
|
3135
3265
|
template.initialize = initializeTemplater;
|
|
3136
3266
|
const EXPRESSION_VARIABLE = /{{([\s\S]+?)}}/g;
|
|
3137
3267
|
//#endregion
|
|
3138
3268
|
//#region src/value/clone.ts
|
|
3139
3269
|
const CLONE_NAME = "clone";
|
|
3140
|
-
function clone(value) {
|
|
3141
|
-
return cloneValue(value, 0, /* @__PURE__ */ new WeakMap());
|
|
3270
|
+
function clone(value, flat) {
|
|
3271
|
+
return flat === true ? copy(value) : cloneValue(value, 0, /* @__PURE__ */ new WeakMap(), false);
|
|
3142
3272
|
}
|
|
3143
3273
|
clone.handlers = getSelfHandlers(clone, {
|
|
3144
3274
|
callback: tryStructuredClone,
|
|
@@ -3160,11 +3290,11 @@ function cloneDataView(value, depth, references) {
|
|
|
3160
3290
|
references.set(value, cloned);
|
|
3161
3291
|
return cloned;
|
|
3162
3292
|
}
|
|
3163
|
-
function cloneMap(map, depth, references) {
|
|
3293
|
+
function cloneMap(map, depth, references, flat) {
|
|
3164
3294
|
if (depth >= MAX_CLONE_DEPTH) return map;
|
|
3165
3295
|
const cloned = /* @__PURE__ */ new Map();
|
|
3166
3296
|
const entries = map.entries();
|
|
3167
|
-
for (const entry of entries) cloned.set(cloneValue(entry[0], depth + 1, references), cloneValue(entry[1], depth + 1, references));
|
|
3297
|
+
for (const entry of entries) cloned.set(flat ? entry[0] : cloneValue(entry[0], depth + 1, references, false), flat ? entry[1] : cloneValue(entry[1], depth + 1, references, false));
|
|
3168
3298
|
references.set(map, cloned);
|
|
3169
3299
|
return cloned;
|
|
3170
3300
|
}
|
|
@@ -3174,14 +3304,14 @@ function cloneNode(node, depth, references) {
|
|
|
3174
3304
|
references.set(node, cloned);
|
|
3175
3305
|
return cloned;
|
|
3176
3306
|
}
|
|
3177
|
-
function
|
|
3178
|
-
if (depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
|
|
3307
|
+
function cloneObject(value, depth, references, flat) {
|
|
3308
|
+
if (flat || depth >= MAX_CLONE_DEPTH) return Array.isArray(value) ? value.slice() : { ...value };
|
|
3179
3309
|
const cloned = Array.isArray(value) ? [] : {};
|
|
3180
3310
|
const keys = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)];
|
|
3181
3311
|
const { length } = keys;
|
|
3182
3312
|
for (let index = 0; index < length; index += 1) {
|
|
3183
3313
|
const key = keys[index];
|
|
3184
|
-
cloned[key] = cloneValue(value[key], depth + 1, references);
|
|
3314
|
+
cloned[key] = cloneValue(value[key], depth + 1, references, false);
|
|
3185
3315
|
}
|
|
3186
3316
|
references.set(value, cloned);
|
|
3187
3317
|
return cloned;
|
|
@@ -3193,12 +3323,12 @@ function cloneRegularExpression(value, depth, references) {
|
|
|
3193
3323
|
references.set(value, cloned);
|
|
3194
3324
|
return cloned;
|
|
3195
3325
|
}
|
|
3196
|
-
function cloneSet(set, depth, references) {
|
|
3326
|
+
function cloneSet(set, depth, references, flat) {
|
|
3197
3327
|
if (depth >= MAX_CLONE_DEPTH) return set;
|
|
3198
3328
|
const cloned = /* @__PURE__ */ new Set();
|
|
3199
3329
|
const values = [...set.values()];
|
|
3200
3330
|
const { length } = values;
|
|
3201
|
-
for (let index = 0; index < length; index += 1) cloned.add(cloneValue(values[index], depth + 1, references));
|
|
3331
|
+
for (let index = 0; index < length; index += 1) cloned.add(flat ? values[index] : cloneValue(values[index], depth + 1, references, false));
|
|
3202
3332
|
references.set(set, cloned);
|
|
3203
3333
|
return cloned;
|
|
3204
3334
|
}
|
|
@@ -3208,32 +3338,45 @@ function cloneTypedArray(value, depth, references) {
|
|
|
3208
3338
|
references.set(value, cloned);
|
|
3209
3339
|
return cloned;
|
|
3210
3340
|
}
|
|
3211
|
-
function cloneValue(value, depth, references) {
|
|
3341
|
+
function cloneValue(value, depth, references, flat) {
|
|
3212
3342
|
switch (true) {
|
|
3213
|
-
case value == null:
|
|
3214
|
-
case typeof value === "bigint":
|
|
3215
|
-
case typeof value === "boolean":
|
|
3343
|
+
case value == null:
|
|
3344
|
+
case typeof value === "bigint":
|
|
3345
|
+
case typeof value === "boolean":
|
|
3346
|
+
case typeof value === "number":
|
|
3347
|
+
case typeof value === "string": return value;
|
|
3216
3348
|
case typeof value === "function": return;
|
|
3217
|
-
case typeof value === "number": return Number(value);
|
|
3218
|
-
case typeof value === "string": return String(value);
|
|
3219
3349
|
case typeof value === "symbol": return Symbol(value.description);
|
|
3220
3350
|
case references.has(value): return references.get(value);
|
|
3221
3351
|
case value instanceof ArrayBuffer: return cloneArrayBuffer(value, depth, references);
|
|
3222
3352
|
case value instanceof DataView: return cloneDataView(value, depth, references);
|
|
3223
3353
|
case value instanceof Date: return new Date(value.getTime());
|
|
3224
3354
|
case value instanceof RegExp: return cloneRegularExpression(value, depth, references);
|
|
3225
|
-
case value instanceof Map: return cloneMap(value, depth, references);
|
|
3355
|
+
case value instanceof Map: return cloneMap(value, depth, references, flat);
|
|
3226
3356
|
case typeof Node !== "undefined" && value instanceof Node: return cloneNode(value, depth, references);
|
|
3227
|
-
case value instanceof Set: return cloneSet(value, depth, references);
|
|
3228
|
-
case isArrayOrPlainObject(value): return
|
|
3357
|
+
case value instanceof Set: return cloneSet(value, depth, references, flat);
|
|
3358
|
+
case isArrayOrPlainObject(value): return cloneObject(value, depth, references, flat);
|
|
3229
3359
|
case isTypedArray(value): return cloneTypedArray(value, depth, references);
|
|
3230
3360
|
default: return clone.handlers.handle(value, depth, references);
|
|
3231
3361
|
}
|
|
3232
3362
|
}
|
|
3233
3363
|
/**
|
|
3364
|
+
* Copy any kind of value
|
|
3365
|
+
*
|
|
3366
|
+
* - Clones the value shallowly, without cloning nested values
|
|
3367
|
+
* - To copy a value deeply, use `clone` instead
|
|
3368
|
+
*
|
|
3369
|
+
* @param value Value to copy
|
|
3370
|
+
* @returns Copied value
|
|
3371
|
+
*/
|
|
3372
|
+
function copy(value) {
|
|
3373
|
+
return cloneValue(value, 0, /* @__PURE__ */ new WeakMap(), true);
|
|
3374
|
+
}
|
|
3375
|
+
/**
|
|
3234
3376
|
* Deregister a clone handler for a specific class
|
|
3235
3377
|
*
|
|
3236
|
-
*
|
|
3378
|
+
* _Available as `deregisterCloner` and `template.deregister`_
|
|
3379
|
+
*
|
|
3237
3380
|
* @param constructor Class constructor
|
|
3238
3381
|
*/
|
|
3239
3382
|
function deregisterCloner(constructor) {
|
|
@@ -3242,9 +3385,10 @@ function deregisterCloner(constructor) {
|
|
|
3242
3385
|
/**
|
|
3243
3386
|
* Register a clone handler for a specific class
|
|
3244
3387
|
*
|
|
3245
|
-
*
|
|
3388
|
+
* _Available as `registerCloner` and `template.register`_
|
|
3389
|
+
*
|
|
3246
3390
|
* @param constructor Class constructor
|
|
3247
|
-
* @param handler Method name or clone function _(defaults to `clone`)_
|
|
3391
|
+
* @param handler Method name or clone function _(defaults to method name `clone`)_
|
|
3248
3392
|
*/
|
|
3249
3393
|
function registerCloner(constructor, handler) {
|
|
3250
3394
|
clone.handlers.register(constructor, handler);
|
|
@@ -3270,8 +3414,9 @@ function inMap(map, value, key) {
|
|
|
3270
3414
|
for (const [key, item] of map) if (equal(item, value)) return key;
|
|
3271
3415
|
}
|
|
3272
3416
|
/**
|
|
3273
|
-
* Does the value exist in a
|
|
3274
|
-
*
|
|
3417
|
+
* Does the value exist in a _Set_?
|
|
3418
|
+
*
|
|
3419
|
+
* @param set _Set_ to check in
|
|
3275
3420
|
* @param value Value to check for
|
|
3276
3421
|
* @returns `true` if the value exists, otherwise `false`
|
|
3277
3422
|
*/
|
|
@@ -3285,6 +3430,7 @@ function inSet(set, value) {
|
|
|
3285
3430
|
//#region src/value/diff.ts
|
|
3286
3431
|
/**
|
|
3287
3432
|
* Find the differences between two values
|
|
3433
|
+
*
|
|
3288
3434
|
* @param first First value
|
|
3289
3435
|
* @param second Second value
|
|
3290
3436
|
* @param options Comparison options
|
|
@@ -3385,40 +3531,81 @@ const DIFF_NONE = "none";
|
|
|
3385
3531
|
const DIFF_PARTIAL = "partial";
|
|
3386
3532
|
//#endregion
|
|
3387
3533
|
//#region src/value/freeze.ts
|
|
3388
|
-
function
|
|
3389
|
-
return
|
|
3534
|
+
function fakeDelete() {
|
|
3535
|
+
return false;
|
|
3390
3536
|
}
|
|
3391
|
-
function
|
|
3537
|
+
function flatFreeze(value) {
|
|
3538
|
+
return freezeValue(value, /* @__PURE__ */ new WeakSet(), true);
|
|
3539
|
+
}
|
|
3540
|
+
function freeze(value, flat) {
|
|
3541
|
+
return freezeValue(value, /* @__PURE__ */ new WeakSet(), flat === true);
|
|
3542
|
+
}
|
|
3543
|
+
freeze.flat = flatFreeze;
|
|
3544
|
+
freeze.is = isFrozen;
|
|
3545
|
+
function freezeArray(array, references, flat) {
|
|
3546
|
+
if (flat) return Object.freeze(array);
|
|
3392
3547
|
references.add(array);
|
|
3393
3548
|
const { length } = array;
|
|
3394
3549
|
for (let index = 0; index < length; index += 1) {
|
|
3395
3550
|
const value = array[index];
|
|
3396
|
-
if (!references.has(value)) array[index] = freezeValue(array[index], references);
|
|
3551
|
+
if (!references.has(value)) array[index] = freezeValue(array[index], references, false);
|
|
3397
3552
|
}
|
|
3398
3553
|
return Object.freeze(array);
|
|
3399
3554
|
}
|
|
3400
|
-
function
|
|
3401
|
-
|
|
3402
|
-
|
|
3555
|
+
function freezeMap(map, references, flat) {
|
|
3556
|
+
frozenValues.add(map);
|
|
3557
|
+
map.clear = noop;
|
|
3558
|
+
map.delete = fakeDelete;
|
|
3559
|
+
map.set = () => map;
|
|
3560
|
+
if (flat) return map;
|
|
3561
|
+
references.add(map);
|
|
3562
|
+
const entries = map.entries();
|
|
3563
|
+
for (const [key, value] of entries) if (!references.has(value)) map.set(key, freezeValue(value, references, false));
|
|
3564
|
+
return map;
|
|
3403
3565
|
}
|
|
3404
|
-
function freezeObject(object, references) {
|
|
3566
|
+
function freezeObject(object, references, flat) {
|
|
3567
|
+
if (flat) return Object.freeze(object);
|
|
3405
3568
|
references.add(object);
|
|
3406
3569
|
const keys = Object.keys(object);
|
|
3407
3570
|
const { length } = keys;
|
|
3408
3571
|
for (let index = 0; index < length; index += 1) {
|
|
3409
3572
|
const key = keys[index];
|
|
3410
|
-
if (!references.has(object[key])) object[key] = freezeValue(object[key], references);
|
|
3573
|
+
if (!references.has(object[key])) object[key] = freezeValue(object[key], references, false);
|
|
3411
3574
|
}
|
|
3412
3575
|
return Object.freeze(object);
|
|
3413
3576
|
}
|
|
3414
|
-
function
|
|
3577
|
+
function freezeSet(set, references, flat) {
|
|
3578
|
+
frozenValues.add(set);
|
|
3579
|
+
set.clear = noop;
|
|
3580
|
+
set.delete = fakeDelete;
|
|
3581
|
+
set.add = () => set;
|
|
3582
|
+
if (flat) return set;
|
|
3583
|
+
references.add(set);
|
|
3584
|
+
const values = set.values();
|
|
3585
|
+
for (const value of values) if (!references.has(value)) set.add(freezeValue(value, references, false));
|
|
3586
|
+
return set;
|
|
3587
|
+
}
|
|
3588
|
+
function freezeValue(value, references, flat) {
|
|
3415
3589
|
switch (true) {
|
|
3416
|
-
case
|
|
3417
|
-
case
|
|
3418
|
-
case
|
|
3590
|
+
case isFrozen(value): return value;
|
|
3591
|
+
case value instanceof Map: return freezeMap(value, references, flat);
|
|
3592
|
+
case value instanceof Set: return freezeSet(value, references, flat);
|
|
3593
|
+
case Array.isArray(value): return freezeArray(value, references, flat);
|
|
3594
|
+
case isPlainObject(value): return freezeObject(value, references, flat);
|
|
3419
3595
|
default: return value;
|
|
3420
3596
|
}
|
|
3421
3597
|
}
|
|
3598
|
+
/**
|
|
3599
|
+
* Is the value frozen?
|
|
3600
|
+
*
|
|
3601
|
+
* @param value Value to check
|
|
3602
|
+
* @returns `true` if the value is frozen, otherwise `false`
|
|
3603
|
+
*/
|
|
3604
|
+
function isFrozen(value) {
|
|
3605
|
+
if (value instanceof Map || value instanceof Set) return frozenValues.has(value);
|
|
3606
|
+
return typeof value === "object" && value !== null && Object.isFrozen(value);
|
|
3607
|
+
}
|
|
3608
|
+
const frozenValues = /* @__PURE__ */ new WeakSet();
|
|
3422
3609
|
//#endregion
|
|
3423
3610
|
//#region src/internal/value/partial.ts
|
|
3424
3611
|
function partial(value, providedKeys, omit) {
|
|
@@ -3438,6 +3625,7 @@ function partial(value, providedKeys, omit) {
|
|
|
3438
3625
|
//#region src/value/omit.ts
|
|
3439
3626
|
/**
|
|
3440
3627
|
* Create a new object without the specified keys
|
|
3628
|
+
*
|
|
3441
3629
|
* @param value Original object
|
|
3442
3630
|
* @param keys Keys to omit
|
|
3443
3631
|
* @returns Partial object without the specified keys
|
|
@@ -3449,6 +3637,7 @@ function omit(value, keys) {
|
|
|
3449
3637
|
//#region src/value/pick.ts
|
|
3450
3638
|
/**
|
|
3451
3639
|
* Create a new object with only the specified keys
|
|
3640
|
+
*
|
|
3452
3641
|
* @param value Original object
|
|
3453
3642
|
* @param keys Keys to use
|
|
3454
3643
|
* @returns Partial object with only the specified keys
|
|
@@ -3460,6 +3649,7 @@ function pick(value, keys) {
|
|
|
3460
3649
|
//#region src/value/shake.ts
|
|
3461
3650
|
/**
|
|
3462
3651
|
* Shake an object, removing all keys with `undefined` values
|
|
3652
|
+
*
|
|
3463
3653
|
* @param value Object to shake
|
|
3464
3654
|
* @returns Shaken object
|
|
3465
3655
|
*/
|
|
@@ -3503,6 +3693,7 @@ function flattenObject(value, depth, smushed, prefix) {
|
|
|
3503
3693
|
}
|
|
3504
3694
|
/**
|
|
3505
3695
|
* Smush an object into a flat object that uses dot notation keys
|
|
3696
|
+
*
|
|
3506
3697
|
* @param value Object to smush
|
|
3507
3698
|
* @returns Smushed object with dot notation keys
|
|
3508
3699
|
*/
|
|
@@ -3527,6 +3718,7 @@ function getKeys(value) {
|
|
|
3527
3718
|
}
|
|
3528
3719
|
/**
|
|
3529
3720
|
* Unsmush a smushed object _(turning dot notation keys into nested keys)_
|
|
3721
|
+
*
|
|
3530
3722
|
* @param value Object to unsmush
|
|
3531
3723
|
* @returns Unsmushed object with nested keys
|
|
3532
3724
|
*/
|
|
@@ -3581,7 +3773,7 @@ function getReplaceableObjects(value) {
|
|
|
3581
3773
|
/**
|
|
3582
3774
|
* Create an assigner with predefined options
|
|
3583
3775
|
*
|
|
3584
|
-
*
|
|
3776
|
+
* _Available as `initializeAssigner` and `assign.initialize`_
|
|
3585
3777
|
*
|
|
3586
3778
|
* @param options Assigning options
|
|
3587
3779
|
* @returns Assigner function
|
|
@@ -3594,7 +3786,7 @@ function initializeAssigner(options) {
|
|
|
3594
3786
|
/**
|
|
3595
3787
|
* Create a merger with predefined options
|
|
3596
3788
|
*
|
|
3597
|
-
*
|
|
3789
|
+
* _Available as `initializeMerger` and `merge.initialize`_
|
|
3598
3790
|
*
|
|
3599
3791
|
* @param options Merging options
|
|
3600
3792
|
* @returns Merger function
|
|
@@ -3724,6 +3916,7 @@ var Beacon = class {
|
|
|
3724
3916
|
}
|
|
3725
3917
|
/**
|
|
3726
3918
|
* Emit a new value
|
|
3919
|
+
*
|
|
3727
3920
|
* @param value Value to set and emit
|
|
3728
3921
|
* @param finish Finish the beacon after emitting? _(defaults to `false`)_
|
|
3729
3922
|
*/
|
|
@@ -3732,6 +3925,7 @@ var Beacon = class {
|
|
|
3732
3925
|
}
|
|
3733
3926
|
/**
|
|
3734
3927
|
* Emit an error
|
|
3928
|
+
*
|
|
3735
3929
|
* @param value Error to emit
|
|
3736
3930
|
* @param finish Finish the beacon after emitting? _(defaults to `false`)_
|
|
3737
3931
|
*/
|
|
@@ -3816,6 +4010,7 @@ var Subscription = class {
|
|
|
3816
4010
|
};
|
|
3817
4011
|
/**
|
|
3818
4012
|
* Create a new beacon
|
|
4013
|
+
*
|
|
3819
4014
|
* @param value Initial value
|
|
3820
4015
|
* @param options Beacon options
|
|
3821
4016
|
* @returns Beacon instance
|
|
@@ -3949,9 +4144,10 @@ function isBytey(value) {
|
|
|
3949
4144
|
return typeof value === "number" && between(value, 0, 255);
|
|
3950
4145
|
}
|
|
3951
4146
|
/**
|
|
3952
|
-
* Is the value a
|
|
4147
|
+
* Is the value a _Color_?
|
|
4148
|
+
*
|
|
3953
4149
|
* @param value Value to check
|
|
3954
|
-
* @returns `true` if the value is a
|
|
4150
|
+
* @returns `true` if the value is a _Color_, otherwise `false`
|
|
3955
4151
|
*/
|
|
3956
4152
|
function isColor(value) {
|
|
3957
4153
|
return typeof value === "object" && value !== null && "$color" in value && value.$color === true;
|
|
@@ -3972,9 +4168,19 @@ function isDegree(value) {
|
|
|
3972
4168
|
}
|
|
3973
4169
|
/**
|
|
3974
4170
|
* Is the value a hex color?
|
|
4171
|
+
*
|
|
3975
4172
|
* @param value Value to check
|
|
3976
|
-
* @param alpha Allow alpha channel? _(defaults to `true`)_
|
|
4173
|
+
* @param alpha Allow alpha channel _(opacity)_? _(defaults to `true`)_
|
|
3977
4174
|
* @returns `true` if the value is a hex color, otherwise `false`
|
|
4175
|
+
*
|
|
4176
|
+
* @example
|
|
4177
|
+
* ```typescript
|
|
4178
|
+
* isHexColor('ff0000'); // => true
|
|
4179
|
+
* isHexColor('#ff0000'); // => true
|
|
4180
|
+
*
|
|
4181
|
+
* isHexColor('#ff000050'); // => true
|
|
4182
|
+
* isHexColor('#ff000050', false); // => false
|
|
4183
|
+
* ```
|
|
3978
4184
|
*/
|
|
3979
4185
|
function isHexColor(value, alpha) {
|
|
3980
4186
|
if (typeof value !== "string") return false;
|
|
@@ -3983,17 +4189,19 @@ function isHexColor(value, alpha) {
|
|
|
3983
4189
|
return true;
|
|
3984
4190
|
}
|
|
3985
4191
|
/**
|
|
3986
|
-
* Is the value an
|
|
4192
|
+
* Is the value an _HSLA_ color?
|
|
4193
|
+
*
|
|
3987
4194
|
* @param value Value to check
|
|
3988
|
-
* @returns `true` if the value is an
|
|
4195
|
+
* @returns `true` if the value is an _HSLA_ color, otherwise `false`
|
|
3989
4196
|
*/
|
|
3990
4197
|
function isHslaColor(value) {
|
|
3991
4198
|
return isColorValue(value, KEYS_HSLA);
|
|
3992
4199
|
}
|
|
3993
4200
|
/**
|
|
3994
|
-
* Is the value an
|
|
4201
|
+
* Is the value an _HSL_ color?
|
|
4202
|
+
*
|
|
3995
4203
|
* @param value Value to check
|
|
3996
|
-
* @returns `true` if the value is an
|
|
4204
|
+
* @returns `true` if the value is an _HSL_ color, otherwise `false`
|
|
3997
4205
|
*/
|
|
3998
4206
|
function isHslColor(value) {
|
|
3999
4207
|
return isColorValue(value, KEYS_HSLA) || isColorValue(value, KEYS_HSL);
|
|
@@ -4002,17 +4210,19 @@ function isHslLike(value) {
|
|
|
4002
4210
|
return hasKeys(value, KEYS_HSL);
|
|
4003
4211
|
}
|
|
4004
4212
|
/**
|
|
4005
|
-
* Is the value an
|
|
4213
|
+
* Is the value an _RGBA_ color?
|
|
4214
|
+
*
|
|
4006
4215
|
* @param value Value to check
|
|
4007
|
-
* @returns `true` if the value is an
|
|
4216
|
+
* @returns `true` if the value is an _RGBA_ color, otherwise `false`
|
|
4008
4217
|
*/
|
|
4009
4218
|
function isRgbaColor(value) {
|
|
4010
4219
|
return isColorValue(value, KEYS_RGBA);
|
|
4011
4220
|
}
|
|
4012
4221
|
/**
|
|
4013
|
-
* Is the value an
|
|
4222
|
+
* Is the value an _RGB_ color?
|
|
4223
|
+
*
|
|
4014
4224
|
* @param value Value to check
|
|
4015
|
-
* @returns `true` if the value is an
|
|
4225
|
+
* @returns `true` if the value is an _RGB_ color, otherwise `false`
|
|
4016
4226
|
*/
|
|
4017
4227
|
function isRgbColor(value) {
|
|
4018
4228
|
return isColorValue(value, KEYS_RGBA) || isColorValue(value, KEYS_RGB);
|
|
@@ -4039,6 +4249,10 @@ function getClampedValue(value, minimum, maximum) {
|
|
|
4039
4249
|
}
|
|
4040
4250
|
/**
|
|
4041
4251
|
* Get a foreground color _(usually text)_ based on a background color's luminance
|
|
4252
|
+
*
|
|
4253
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4254
|
+
* - If the value cannot be parsed, a white foreground color will be returned
|
|
4255
|
+
*
|
|
4042
4256
|
* @param value Original value
|
|
4043
4257
|
* @returns Foreground color
|
|
4044
4258
|
*/
|
|
@@ -4058,9 +4272,13 @@ function getForegroundColor(value) {
|
|
|
4058
4272
|
return new Color(.2126 * values[2] + .7152 * values[1] + .0722 * values[0] > .625 ? HEX_BLACK : HEX_WHITE);
|
|
4059
4273
|
}
|
|
4060
4274
|
/**
|
|
4061
|
-
* Get the hex color _(with alpha channel)_ from any kind of value
|
|
4275
|
+
* Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value
|
|
4276
|
+
*
|
|
4277
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4278
|
+
* - If the value cannot be parsed, a black hex color with an alpha channel of `0` will be returned
|
|
4279
|
+
*
|
|
4062
4280
|
* @param value Original value
|
|
4063
|
-
* @returns Hex color
|
|
4281
|
+
* @returns Hex color string
|
|
4064
4282
|
*/
|
|
4065
4283
|
function getHexaColor(value) {
|
|
4066
4284
|
const { alpha, hex } = getColorState(value);
|
|
@@ -4068,8 +4286,12 @@ function getHexaColor(value) {
|
|
|
4068
4286
|
}
|
|
4069
4287
|
/**
|
|
4070
4288
|
* Get the hex color from any kind of value
|
|
4289
|
+
*
|
|
4290
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4291
|
+
* - If the value cannot be parsed, a black hex color will be returned
|
|
4292
|
+
*
|
|
4071
4293
|
* @param value Original value
|
|
4072
|
-
* @returns Hex color
|
|
4294
|
+
* @returns Hex color string
|
|
4073
4295
|
*/
|
|
4074
4296
|
function getHexColor(value) {
|
|
4075
4297
|
return getColorState(value).hex;
|
|
@@ -4081,9 +4303,13 @@ function getDegrees(value) {
|
|
|
4081
4303
|
return getClampedValue(value, 0, 360);
|
|
4082
4304
|
}
|
|
4083
4305
|
/**
|
|
4084
|
-
* Get the
|
|
4306
|
+
* Get the _HSLA_ color from any kind of value
|
|
4307
|
+
*
|
|
4308
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4309
|
+
* - If the value cannot be parsed, a black _HSLA_ color with an alpha channel _(opacity)_ of `0` will be returned
|
|
4310
|
+
*
|
|
4085
4311
|
* @param value Original value
|
|
4086
|
-
* @returns
|
|
4312
|
+
* @returns _HSLA_ color
|
|
4087
4313
|
*/
|
|
4088
4314
|
function getHslaColor(value) {
|
|
4089
4315
|
const { alpha, hsl } = getColorState(value);
|
|
@@ -4093,9 +4319,13 @@ function getHslaColor(value) {
|
|
|
4093
4319
|
};
|
|
4094
4320
|
}
|
|
4095
4321
|
/**
|
|
4096
|
-
* Get the
|
|
4322
|
+
* Get the _HSL_ color from any kind of value
|
|
4323
|
+
*
|
|
4324
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4325
|
+
* - If the value cannot be parsed, a black _HSL_ color will be returned
|
|
4326
|
+
*
|
|
4097
4327
|
* @param value Original value
|
|
4098
|
-
* @returns
|
|
4328
|
+
* @returns _HSL_ color
|
|
4099
4329
|
*/
|
|
4100
4330
|
function getHslColor(value) {
|
|
4101
4331
|
return getColorState(value).hsl;
|
|
@@ -4104,9 +4334,13 @@ function getPercentage(value) {
|
|
|
4104
4334
|
return getClampedValue(value, 0, 100);
|
|
4105
4335
|
}
|
|
4106
4336
|
/**
|
|
4107
|
-
* Get the
|
|
4337
|
+
* Get the _RGBA_ color from any kind of value
|
|
4338
|
+
*
|
|
4339
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4340
|
+
* - If the value cannot be parsed, a black _RGBA_ color with an alpha channel _(opacity)_ of `0` will be returned
|
|
4341
|
+
*
|
|
4108
4342
|
* @param value Original value
|
|
4109
|
-
* @returns
|
|
4343
|
+
* @returns _RGBA_ color
|
|
4110
4344
|
*/
|
|
4111
4345
|
function getRgbaColor(value) {
|
|
4112
4346
|
const { alpha, rgb } = getColorState(value);
|
|
@@ -4116,9 +4350,13 @@ function getRgbaColor(value) {
|
|
|
4116
4350
|
};
|
|
4117
4351
|
}
|
|
4118
4352
|
/**
|
|
4119
|
-
* Get the
|
|
4353
|
+
* Get the _RGB_ color from any kind of value
|
|
4354
|
+
*
|
|
4355
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4356
|
+
* - If the value cannot be parsed, a black _RGB_ color will be returned
|
|
4357
|
+
*
|
|
4120
4358
|
* @param value Original value
|
|
4121
|
-
* @returns
|
|
4359
|
+
* @returns _RGB_ color
|
|
4122
4360
|
*/
|
|
4123
4361
|
function getRgbColor(value) {
|
|
4124
4362
|
return getColorState(value).rgb;
|
|
@@ -4179,20 +4417,26 @@ function getRgbValue(value) {
|
|
|
4179
4417
|
};
|
|
4180
4418
|
}
|
|
4181
4419
|
/**
|
|
4182
|
-
* Convert an
|
|
4183
|
-
*
|
|
4184
|
-
*
|
|
4185
|
-
*
|
|
4420
|
+
* Convert an _RGB(A)_ color to a hex color _(with optional alpha channel, i.e., opacity)_
|
|
4421
|
+
*
|
|
4422
|
+
* _If the value is unable to be converted, a black hex color will be returned_
|
|
4423
|
+
*
|
|
4424
|
+
* @param rgb _RGB(A)_ color
|
|
4425
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
4426
|
+
* @returns Hex color string
|
|
4186
4427
|
*/
|
|
4187
4428
|
function rgbToHex(rgb, alpha) {
|
|
4188
4429
|
return convertRgbToHex(isRgbLike(rgb) ? getRgbValue(rgb) : { ...DEFAULT_RGB }, alpha ?? false);
|
|
4189
4430
|
}
|
|
4190
4431
|
/**
|
|
4191
|
-
* Convert an
|
|
4432
|
+
* Convert an _RGB(A)_ color to an _HSL_ color
|
|
4433
|
+
*
|
|
4434
|
+
* _If the value is unable to be converted, a black HSL color will be returned_
|
|
4435
|
+
*
|
|
4436
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
4192
4437
|
*
|
|
4193
|
-
*
|
|
4194
|
-
* @
|
|
4195
|
-
* @returns HSL color
|
|
4438
|
+
* @param rgb _RGB(A)_ color
|
|
4439
|
+
* @returns _HSL_ color
|
|
4196
4440
|
*/
|
|
4197
4441
|
function rgbToHsl(rgb) {
|
|
4198
4442
|
const { hue, lightness, saturation } = convertRgbToHsla(rgb);
|
|
@@ -4203,11 +4447,14 @@ function rgbToHsl(rgb) {
|
|
|
4203
4447
|
};
|
|
4204
4448
|
}
|
|
4205
4449
|
/**
|
|
4206
|
-
* Convert an
|
|
4450
|
+
* Convert an _RGB(A)_ color to an _HSLA_ color
|
|
4207
4451
|
*
|
|
4208
|
-
*
|
|
4209
|
-
*
|
|
4210
|
-
*
|
|
4452
|
+
* _If the value is unable to be converted, a black _HSLA_ color with an alpha channel (opacity) of `0` will be returned_
|
|
4453
|
+
*
|
|
4454
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L26_
|
|
4455
|
+
*
|
|
4456
|
+
* @param rgb _RGB(A)_ color
|
|
4457
|
+
* @returns _HSLA_ color
|
|
4211
4458
|
*/
|
|
4212
4459
|
function rgbToHsla(rgb) {
|
|
4213
4460
|
return convertRgbToHsla(rgb);
|
|
@@ -4229,9 +4476,12 @@ function convertHexToRgba(value) {
|
|
|
4229
4476
|
}
|
|
4230
4477
|
/**
|
|
4231
4478
|
* Get the normalized hex color from a value
|
|
4479
|
+
*
|
|
4480
|
+
* _If the value is unable to be parsed or normalized, a hex color of `000000` will be returned, with the alpha channel _(opacity)_ value `0` included, if specified_
|
|
4481
|
+
*
|
|
4232
4482
|
* @param value Value to normalize
|
|
4233
|
-
* @param alpha Include alpha channel? _(defaults to `false`)_
|
|
4234
|
-
* @returns Normalized hex color
|
|
4483
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
4484
|
+
* @returns Normalized hex color
|
|
4235
4485
|
*/
|
|
4236
4486
|
function getNormalizedHex(value, alpha) {
|
|
4237
4487
|
const includeAlpha = alpha ?? false;
|
|
@@ -4252,9 +4502,12 @@ function hexToHsla(value) {
|
|
|
4252
4502
|
return convertRgbToHsla(convertHexToRgba(value));
|
|
4253
4503
|
}
|
|
4254
4504
|
/**
|
|
4255
|
-
* Convert a hex color to an
|
|
4505
|
+
* Convert a hex color to an _RGB_ color
|
|
4506
|
+
*
|
|
4507
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
4508
|
+
*
|
|
4256
4509
|
* @param value Original value
|
|
4257
|
-
* @returns
|
|
4510
|
+
* @returns _RGB_ color
|
|
4258
4511
|
*/
|
|
4259
4512
|
function hexToRgb(value) {
|
|
4260
4513
|
const { blue, green, red } = convertHexToRgba(value);
|
|
@@ -4265,9 +4518,12 @@ function hexToRgb(value) {
|
|
|
4265
4518
|
};
|
|
4266
4519
|
}
|
|
4267
4520
|
/**
|
|
4268
|
-
* Convert a hex color to an
|
|
4521
|
+
* Convert a hex color to an _RGBA_ color
|
|
4522
|
+
*
|
|
4523
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opacity) of `0` will be returned_
|
|
4524
|
+
*
|
|
4269
4525
|
* @param value Original value
|
|
4270
|
-
* @returns
|
|
4526
|
+
* @returns _RGBA_ color
|
|
4271
4527
|
*/
|
|
4272
4528
|
function hexToRgba(value) {
|
|
4273
4529
|
return convertHexToRgba(value);
|
|
@@ -4301,9 +4557,12 @@ function hslToHex(hsl, alpha) {
|
|
|
4301
4557
|
return convertRgbToHex(convertHslToRgba(hsl), alpha ?? false);
|
|
4302
4558
|
}
|
|
4303
4559
|
/**
|
|
4304
|
-
* Convert an
|
|
4560
|
+
* Convert an _HSL(A)_ color to an _RGB_ color
|
|
4561
|
+
*
|
|
4562
|
+
* _If the value is unable to be converted, a black RGB color will be returned_
|
|
4563
|
+
*
|
|
4564
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
|
|
4305
4565
|
*
|
|
4306
|
-
* Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
|
|
4307
4566
|
* @param hsl HSL(A) color
|
|
4308
4567
|
* @returns RGB color
|
|
4309
4568
|
*/
|
|
@@ -4316,9 +4575,12 @@ function hslToRgb(hsl) {
|
|
|
4316
4575
|
};
|
|
4317
4576
|
}
|
|
4318
4577
|
/**
|
|
4319
|
-
* Convert an
|
|
4578
|
+
* Convert an _HSL(A)_ color to an _RGBA_ color
|
|
4579
|
+
*
|
|
4580
|
+
* _If the value is unable to be converted, a black RGBA color with an alpha channel (opactiy) of `0` will be returned_
|
|
4581
|
+
*
|
|
4582
|
+
* _Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61_
|
|
4320
4583
|
*
|
|
4321
|
-
* Thanks, https://github.com/color-js/color.js/blob/main/src/spaces/hsl.js#L61
|
|
4322
4584
|
* @param hsl HSL(A) color
|
|
4323
4585
|
* @returns RGBA color
|
|
4324
4586
|
*/
|
|
@@ -4362,7 +4624,7 @@ function getColorState(value) {
|
|
|
4362
4624
|
}
|
|
4363
4625
|
}
|
|
4364
4626
|
state.alpha ??= getAlpha(1);
|
|
4365
|
-
state.hex ??=
|
|
4627
|
+
state.hex ??= HEX_BLACK;
|
|
4366
4628
|
state.hsl ??= { ...DEFAULT_HSL };
|
|
4367
4629
|
state.rgb ??= { ...DEFAULT_RGB };
|
|
4368
4630
|
return state;
|
|
@@ -4410,55 +4672,86 @@ function setRGBColor(state, value, alpha) {
|
|
|
4410
4672
|
var Color = class {
|
|
4411
4673
|
#state;
|
|
4412
4674
|
/**
|
|
4413
|
-
* Get the alpha channel
|
|
4675
|
+
* Get the alpha channel _(opacity)_ of the color
|
|
4676
|
+
*
|
|
4677
|
+
* @returns Current alpha channel value between `0` and `1`
|
|
4414
4678
|
*/
|
|
4415
4679
|
get alpha() {
|
|
4416
4680
|
return this.#state.alpha.value;
|
|
4417
4681
|
}
|
|
4418
4682
|
/**
|
|
4419
|
-
* Set the alpha channel
|
|
4683
|
+
* Set the alpha channel _(opacity)_ of the color, as:
|
|
4684
|
+
*
|
|
4685
|
+
* - A number between `0` and `1`, where `0` is fully transparent and `1` is fully opaque
|
|
4686
|
+
* - A number between `0` and `100`, where `0` is fully transparent and `100` is fully opaque
|
|
4687
|
+
*
|
|
4688
|
+
* @param value New alpha channel value
|
|
4420
4689
|
*/
|
|
4421
4690
|
set alpha(value) {
|
|
4422
4691
|
if (typeof value === "number" && !Number.isNaN(value)) this.#state.alpha = getAlpha(value);
|
|
4423
4692
|
}
|
|
4424
4693
|
/**
|
|
4425
|
-
* Get the color as a hex color
|
|
4694
|
+
* Get the color as a hex color string
|
|
4695
|
+
*
|
|
4696
|
+
* _Hex color string is returned with no `#`-prefix or alpha channel (opacity)_
|
|
4697
|
+
*
|
|
4698
|
+
* @returns Current color as a hex color string
|
|
4426
4699
|
*/
|
|
4427
4700
|
get hex() {
|
|
4428
4701
|
return this.#state.hex;
|
|
4429
4702
|
}
|
|
4430
4703
|
/**
|
|
4431
|
-
* Set
|
|
4704
|
+
* Set the color from a hex color string
|
|
4705
|
+
*
|
|
4706
|
+
* - `#`-prefix is optional
|
|
4707
|
+
* - Alpha channel _(opacity)_ will be ignored
|
|
4708
|
+
*
|
|
4709
|
+
* @param value New hex color string
|
|
4432
4710
|
*/
|
|
4433
4711
|
set hex(value) {
|
|
4434
4712
|
setHexColor(this.#state, value, false);
|
|
4435
4713
|
}
|
|
4436
4714
|
/**
|
|
4437
|
-
* Get the color as a hex color with an alpha channel
|
|
4715
|
+
* Get the color as a hex color with an alpha channel _(opacity)_
|
|
4716
|
+
*
|
|
4717
|
+
* _Hex color string is returned with alpha channel (opacity), but without `#`-prefix_
|
|
4718
|
+
*
|
|
4719
|
+
* @returns Current color as a hex color string
|
|
4438
4720
|
*/
|
|
4439
4721
|
get hexa() {
|
|
4440
4722
|
return `${this.#state.hex}${this.#state.alpha.hex}`;
|
|
4441
4723
|
}
|
|
4442
4724
|
/**
|
|
4443
|
-
* Set
|
|
4725
|
+
* Set the color from a hex color string with an alpha channel _(opacity)_
|
|
4726
|
+
*
|
|
4727
|
+
* - `#`-prefix is optional
|
|
4728
|
+
* - Alpha channel _(opacity)_ will be respected
|
|
4729
|
+
*
|
|
4730
|
+
* @param value New hex color string
|
|
4444
4731
|
*/
|
|
4445
4732
|
set hexa(value) {
|
|
4446
4733
|
setHexColor(this.#state, value, true);
|
|
4447
4734
|
}
|
|
4448
4735
|
/**
|
|
4449
|
-
* Get the color as an
|
|
4736
|
+
* Get the color as an _HSL_ color
|
|
4737
|
+
*
|
|
4738
|
+
* @returns Current color as an _HSL_ color
|
|
4450
4739
|
*/
|
|
4451
4740
|
get hsl() {
|
|
4452
4741
|
return this.#state.hsl;
|
|
4453
4742
|
}
|
|
4454
4743
|
/**
|
|
4455
|
-
* Set colors from an
|
|
4744
|
+
* Set colors from an _HSL_ color
|
|
4745
|
+
*
|
|
4746
|
+
* @param value New _HSL_ color
|
|
4456
4747
|
*/
|
|
4457
4748
|
set hsl(value) {
|
|
4458
4749
|
setHSLColor(this.#state, value, false);
|
|
4459
4750
|
}
|
|
4460
4751
|
/**
|
|
4461
|
-
* Get the color as an
|
|
4752
|
+
* Get the color as an _HSLA_ color
|
|
4753
|
+
*
|
|
4754
|
+
* @returns Current color as an _HSLA_ color
|
|
4462
4755
|
*/
|
|
4463
4756
|
get hsla() {
|
|
4464
4757
|
return {
|
|
@@ -4467,25 +4760,33 @@ var Color = class {
|
|
|
4467
4760
|
};
|
|
4468
4761
|
}
|
|
4469
4762
|
/**
|
|
4470
|
-
* Set colors and alpha from an
|
|
4763
|
+
* Set colors and alpha from an _HSLA_ color
|
|
4764
|
+
*
|
|
4765
|
+
* @param value New _HSLA_ color
|
|
4471
4766
|
*/
|
|
4472
4767
|
set hsla(value) {
|
|
4473
4768
|
setHSLColor(this.#state, value, true);
|
|
4474
4769
|
}
|
|
4475
4770
|
/**
|
|
4476
|
-
* Get the color as an
|
|
4771
|
+
* Get the color as an _RGB_ color
|
|
4772
|
+
*
|
|
4773
|
+
* @returns Current color as an _RGB_ color
|
|
4477
4774
|
*/
|
|
4478
4775
|
get rgb() {
|
|
4479
4776
|
return this.#state.rgb;
|
|
4480
4777
|
}
|
|
4481
4778
|
/**
|
|
4482
|
-
* Set colors from an
|
|
4779
|
+
* Set colors from an _RGB_ color
|
|
4780
|
+
*
|
|
4781
|
+
* @param value New _RGB_ color
|
|
4483
4782
|
*/
|
|
4484
4783
|
set rgb(value) {
|
|
4485
4784
|
setRGBColor(this.#state, value, false);
|
|
4486
4785
|
}
|
|
4487
4786
|
/**
|
|
4488
|
-
* Get the color as an
|
|
4787
|
+
* Get the color as an _RGBA_ color
|
|
4788
|
+
*
|
|
4789
|
+
* @returns Current color as an _RGBA_ color
|
|
4489
4790
|
*/
|
|
4490
4791
|
get rgba() {
|
|
4491
4792
|
return {
|
|
@@ -4494,7 +4795,9 @@ var Color = class {
|
|
|
4494
4795
|
};
|
|
4495
4796
|
}
|
|
4496
4797
|
/**
|
|
4497
|
-
* Set colors and alpha from an
|
|
4798
|
+
* Set colors and alpha from an _RGBA_ color
|
|
4799
|
+
*
|
|
4800
|
+
* @param value New _RGBA_ color
|
|
4498
4801
|
*/
|
|
4499
4802
|
set rgba(value) {
|
|
4500
4803
|
setRGBColor(this.#state, value, true);
|
|
@@ -4503,15 +4806,38 @@ var Color = class {
|
|
|
4503
4806
|
this.#state = getColorState(value);
|
|
4504
4807
|
Object.defineProperty(this, "$color", { value: true });
|
|
4505
4808
|
}
|
|
4809
|
+
/**
|
|
4810
|
+
* Get the color as a hex string
|
|
4811
|
+
*
|
|
4812
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
4813
|
+
* @returns Hex color string
|
|
4814
|
+
*/
|
|
4506
4815
|
toHexString(alpha) {
|
|
4507
4816
|
return `#${alpha === true ? this.hexa : this.hex}`;
|
|
4508
4817
|
}
|
|
4818
|
+
/**
|
|
4819
|
+
* Get the color as an _HSL(A)_ string
|
|
4820
|
+
*
|
|
4821
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
4822
|
+
* @returns _HSL(A)_ color string
|
|
4823
|
+
*/
|
|
4509
4824
|
toHslString(alpha) {
|
|
4510
4825
|
return formatColor("hsl", this, alpha === true);
|
|
4511
4826
|
}
|
|
4827
|
+
/**
|
|
4828
|
+
* Get the color as an _RGB(A)_ string
|
|
4829
|
+
*
|
|
4830
|
+
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
4831
|
+
* @returns _RGB(A)_ color string
|
|
4832
|
+
*/
|
|
4512
4833
|
toRgbString(alpha) {
|
|
4513
4834
|
return formatColor("rgb", this, alpha === true);
|
|
4514
4835
|
}
|
|
4836
|
+
/**
|
|
4837
|
+
* Get the color as a hex color string
|
|
4838
|
+
*
|
|
4839
|
+
* @returns Hex color string
|
|
4840
|
+
*/
|
|
4515
4841
|
toString() {
|
|
4516
4842
|
return this.toHexString();
|
|
4517
4843
|
}
|
|
@@ -4519,9 +4845,13 @@ var Color = class {
|
|
|
4519
4845
|
//#endregion
|
|
4520
4846
|
//#region src/color/index.ts
|
|
4521
4847
|
/**
|
|
4522
|
-
* Get a
|
|
4848
|
+
* Get a _Color_ from any kind of value
|
|
4849
|
+
*
|
|
4850
|
+
* - Values that can be parsed are: hex(a) color strings, _HSL(A)_ color objects, and _RGB(A)_ color objects
|
|
4851
|
+
* - If the value is unable to be parsed, a black _Color_ will be returned
|
|
4852
|
+
*
|
|
4523
4853
|
* @param value Original value
|
|
4524
|
-
* @returns
|
|
4854
|
+
* @returns _Color_ instance
|
|
4525
4855
|
*/
|
|
4526
4856
|
function getColor(value) {
|
|
4527
4857
|
return isColor(value) ? value : new Color(value);
|
|
@@ -4595,18 +4925,19 @@ var Logger = class {
|
|
|
4595
4925
|
return enabled ? console.warn : noop;
|
|
4596
4926
|
}
|
|
4597
4927
|
/**
|
|
4598
|
-
* Start a
|
|
4599
|
-
*
|
|
4600
|
-
* @
|
|
4928
|
+
* Start a timed logger with a label
|
|
4929
|
+
*
|
|
4930
|
+
* @param label Label for the logger
|
|
4931
|
+
* @returns _Timed_ instance
|
|
4601
4932
|
*/
|
|
4602
4933
|
time(label) {
|
|
4603
|
-
return new
|
|
4934
|
+
return new Timed(label);
|
|
4604
4935
|
}
|
|
4605
4936
|
};
|
|
4606
4937
|
/**
|
|
4607
4938
|
* A named timer that can be used to log durations to the console
|
|
4608
4939
|
*/
|
|
4609
|
-
var
|
|
4940
|
+
var Timed = class {
|
|
4610
4941
|
#logger;
|
|
4611
4942
|
#stopper;
|
|
4612
4943
|
#state;
|
|
@@ -4658,9 +4989,10 @@ function average(array, key) {
|
|
|
4658
4989
|
}
|
|
4659
4990
|
/**
|
|
4660
4991
|
* Round a number up
|
|
4992
|
+
*
|
|
4661
4993
|
* @param value Number to round up
|
|
4662
4994
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
4663
|
-
* @returns Rounded number, or `NaN` if the value if unable to be rounded
|
|
4995
|
+
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
4664
4996
|
*/
|
|
4665
4997
|
function ceil(value, decimals) {
|
|
4666
4998
|
return roundNumber(Math.ceil, value, decimals);
|
|
@@ -4679,9 +5011,10 @@ function count(array, key, value) {
|
|
|
4679
5011
|
}
|
|
4680
5012
|
/**
|
|
4681
5013
|
* Round a number down
|
|
5014
|
+
*
|
|
4682
5015
|
* @param value Number to round down
|
|
4683
5016
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
4684
|
-
* @returns Rounded number, or `NaN` if the value if unable to be rounded
|
|
5017
|
+
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
4685
5018
|
*/
|
|
4686
5019
|
function floor(value, decimals) {
|
|
4687
5020
|
return roundNumber(Math.floor, value, decimals);
|
|
@@ -4707,9 +5040,10 @@ function min(array, key) {
|
|
|
4707
5040
|
}
|
|
4708
5041
|
/**
|
|
4709
5042
|
* Round a number
|
|
5043
|
+
*
|
|
4710
5044
|
* @param value Number to round
|
|
4711
5045
|
* @param decimals Number of decimal places to round to _(defaults to `0`)_
|
|
4712
|
-
* @returns Rounded number, or `NaN` if the value if unable to be rounded
|
|
5046
|
+
* @returns Rounded number, or `Number.NaN` if the value if unable to be rounded
|
|
4713
5047
|
*/
|
|
4714
5048
|
function round(value, decimals) {
|
|
4715
5049
|
return roundNumber(Math.round, value, decimals);
|
|
@@ -4726,7 +5060,7 @@ function sum(array, key) {
|
|
|
4726
5060
|
//#endregion
|
|
4727
5061
|
//#region src/promise/models.ts
|
|
4728
5062
|
/**
|
|
4729
|
-
* A
|
|
5063
|
+
* A _Promise_ that can be canceled
|
|
4730
5064
|
*/
|
|
4731
5065
|
var CancelablePromise = class extends Promise {
|
|
4732
5066
|
#rejector;
|
|
@@ -4739,8 +5073,9 @@ var CancelablePromise = class extends Promise {
|
|
|
4739
5073
|
this.#rejector = rejector;
|
|
4740
5074
|
}
|
|
4741
5075
|
/**
|
|
4742
|
-
* Cancel the
|
|
4743
|
-
*
|
|
5076
|
+
* Cancel the _Promise_, rejecting it with an optional reason
|
|
5077
|
+
*
|
|
5078
|
+
* @param reason Optional reason for canceling the _Promise_
|
|
4744
5079
|
*/
|
|
4745
5080
|
cancel(reason) {
|
|
4746
5081
|
this.#rejector(reason);
|
|
@@ -4799,17 +5134,19 @@ function getStrategyOrDefault(value) {
|
|
|
4799
5134
|
return PROMISE_STRATEGY_ALL.has(value) ? value : PROMISE_STRATEGY_DEFAULT;
|
|
4800
5135
|
}
|
|
4801
5136
|
/**
|
|
4802
|
-
* Is the value a fulfilled
|
|
5137
|
+
* Is the value a fulfilled _Promise_ result?
|
|
5138
|
+
*
|
|
4803
5139
|
* @param value Value to check
|
|
4804
|
-
* @returns `true` if the value is a fulfilled
|
|
5140
|
+
* @returns `true` if the value is a fulfilled _Promise_ result, `false` otherwise
|
|
4805
5141
|
*/
|
|
4806
5142
|
function isFulfilled(value) {
|
|
4807
5143
|
return isType(value, PROMISE_TYPE_FULFILLED);
|
|
4808
5144
|
}
|
|
4809
5145
|
/**
|
|
4810
|
-
* Is the value a rejected
|
|
5146
|
+
* Is the value a rejected _Promise_ result?
|
|
5147
|
+
*
|
|
4811
5148
|
* @param value Value to check
|
|
4812
|
-
* @returns `true` if the value is a rejected
|
|
5149
|
+
* @returns `true` if the value is a rejected _Promise_ result, `false` otherwise
|
|
4813
5150
|
*/
|
|
4814
5151
|
function isRejected(value) {
|
|
4815
5152
|
return isType(value, PROMISE_TYPE_REJECTED);
|
|
@@ -4820,9 +5157,10 @@ function isType(value, type) {
|
|
|
4820
5157
|
//#endregion
|
|
4821
5158
|
//#region src/promise/misc.ts
|
|
4822
5159
|
/**
|
|
4823
|
-
* Create a cancelable
|
|
4824
|
-
*
|
|
4825
|
-
* @
|
|
5160
|
+
* Create a cancelable _Promise_
|
|
5161
|
+
*
|
|
5162
|
+
* @param executor Executor function for the _Promise_
|
|
5163
|
+
* @returns Cancelable _Promise_
|
|
4826
5164
|
*/
|
|
4827
5165
|
function cancelable(executor) {
|
|
4828
5166
|
return new CancelablePromise(executor);
|
|
@@ -4978,18 +5316,32 @@ async function resultPromises(items, signal) {
|
|
|
4978
5316
|
//#region src/query.ts
|
|
4979
5317
|
/**
|
|
4980
5318
|
* Convert a query string to a plain _(nested)_ object
|
|
5319
|
+
*
|
|
4981
5320
|
* @param query Query string to convert
|
|
4982
5321
|
* @returns Plain object representation of the query string
|
|
4983
5322
|
*/
|
|
4984
5323
|
function fromQuery(query) {
|
|
4985
5324
|
if (typeof query !== "string" || query.trim().length === 0) return {};
|
|
4986
|
-
const parts = query.split(AMPERSAND);
|
|
5325
|
+
const parts = query.split(AMPERSAND).map((part) => part.split(EQUAL).map(tryDecode)).sort(([first], [second]) => first.localeCompare(second));
|
|
4987
5326
|
const { length } = parts;
|
|
4988
5327
|
const parameters = {};
|
|
5328
|
+
let position = 0;
|
|
5329
|
+
let array;
|
|
4989
5330
|
for (let index = 0; index < length; index += 1) {
|
|
4990
|
-
const
|
|
4991
|
-
|
|
4992
|
-
|
|
5331
|
+
const [key, value] = parts[index];
|
|
5332
|
+
if (EXPRESSION_ARRAY_SUFFIX.test(key)) {
|
|
5333
|
+
const named = key.replace(EXPRESSION_ARRAY_SUFFIX, "");
|
|
5334
|
+
if (named !== array) {
|
|
5335
|
+
array = named;
|
|
5336
|
+
position = 0;
|
|
5337
|
+
}
|
|
5338
|
+
} else {
|
|
5339
|
+
array = void 0;
|
|
5340
|
+
position = 0;
|
|
5341
|
+
}
|
|
5342
|
+
const full = array == null ? key : `${array}.${position}`;
|
|
5343
|
+
if (!ignoreKey(full)) setValue(parameters, full, getQueryValue(value));
|
|
5344
|
+
position += 1;
|
|
4993
5345
|
}
|
|
4994
5346
|
return parameters;
|
|
4995
5347
|
}
|
|
@@ -5000,11 +5352,13 @@ function getParts(value, fromArray, prefix) {
|
|
|
5000
5352
|
for (let index = 0; index < length; index += 1) {
|
|
5001
5353
|
const key = keys[index];
|
|
5002
5354
|
const val = value[key];
|
|
5003
|
-
const
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
else if (val
|
|
5355
|
+
const fullKey = join([prefix, fromArray ? void 0 : key], DOT);
|
|
5356
|
+
const encodedKey = getString(tryEncode(fullKey));
|
|
5357
|
+
const prefixedKey = fromArray ? join([encodedKey, index], DOT) : encodedKey;
|
|
5358
|
+
if (Array.isArray(val)) parts.push(...getParts(val, true, fullKey));
|
|
5359
|
+
else if (isPlainObject(val)) parts.push(...getParts(val, false, fullKey));
|
|
5360
|
+
else if (isDecodable(val)) parts.push(`${prefixedKey}=${getString(tryEncode(val))}`);
|
|
5361
|
+
else if (val instanceof Date) parts.push(`${prefixedKey}=${val.toJSON()}`);
|
|
5008
5362
|
}
|
|
5009
5363
|
return parts;
|
|
5010
5364
|
}
|
|
@@ -5020,15 +5374,9 @@ function getQueryValue(value) {
|
|
|
5020
5374
|
function isDecodable(value) {
|
|
5021
5375
|
return TYPES.has(typeof value);
|
|
5022
5376
|
}
|
|
5023
|
-
function setQueryValue(parameters, key, value) {
|
|
5024
|
-
if (EXPRESSION_DOT.test(key)) setValue(parameters, key, getQueryValue(value));
|
|
5025
|
-
else if (key in parameters) {
|
|
5026
|
-
if (!Array.isArray(parameters[key])) parameters[key] = [parameters[key]];
|
|
5027
|
-
parameters[key].push(getQueryValue(value));
|
|
5028
|
-
} else parameters[key] = getQueryValue(value);
|
|
5029
|
-
}
|
|
5030
5377
|
/**
|
|
5031
5378
|
* Convert a plain _(nested)_ object to a query string
|
|
5379
|
+
*
|
|
5032
5380
|
* @param parameters Plain object to convert
|
|
5033
5381
|
* @returns Query string representation of the object
|
|
5034
5382
|
*/
|
|
@@ -5036,10 +5384,10 @@ function toQuery(parameters) {
|
|
|
5036
5384
|
return isPlainObject(parameters) ? join(getParts(parameters, false).filter((part) => part.length > 0), AMPERSAND) : "";
|
|
5037
5385
|
}
|
|
5038
5386
|
const AMPERSAND = "&";
|
|
5387
|
+
const DOT = ".";
|
|
5039
5388
|
const EQUAL = "=";
|
|
5040
5389
|
const EXPRESSION_ARRAY_SUFFIX = /\[\]$/;
|
|
5041
5390
|
const EXPRESSION_BOOLEAN = /^(false|true)$/;
|
|
5042
|
-
const EXPRESSION_DOT = /\./g;
|
|
5043
5391
|
const TRUE = "true";
|
|
5044
5392
|
const TYPES = new Set([
|
|
5045
5393
|
"boolean",
|
|
@@ -5056,7 +5404,7 @@ var KeyedQueue = class {
|
|
|
5056
5404
|
#options;
|
|
5057
5405
|
#queues = /* @__PURE__ */ new Map();
|
|
5058
5406
|
/**
|
|
5059
|
-
*
|
|
5407
|
+
* Get keys of all active queues
|
|
5060
5408
|
*/
|
|
5061
5409
|
get active() {
|
|
5062
5410
|
return this.#getStatus(STATUS_ACTIVE);
|
|
@@ -5074,13 +5422,13 @@ var KeyedQueue = class {
|
|
|
5074
5422
|
return this.#options.concurrency;
|
|
5075
5423
|
}
|
|
5076
5424
|
/**
|
|
5077
|
-
*
|
|
5425
|
+
* Get keys of all empty queues
|
|
5078
5426
|
*/
|
|
5079
5427
|
get empty() {
|
|
5080
5428
|
return this.#getStatus(STATUS_EMPTY);
|
|
5081
5429
|
}
|
|
5082
5430
|
/**
|
|
5083
|
-
*
|
|
5431
|
+
* Get keys of all full queues
|
|
5084
5432
|
*/
|
|
5085
5433
|
get full() {
|
|
5086
5434
|
return this.#getStatus(STATUS_FULL);
|
|
@@ -5124,6 +5472,7 @@ var KeyedQueue = class {
|
|
|
5124
5472
|
}
|
|
5125
5473
|
/**
|
|
5126
5474
|
* Queue an item for a specific key
|
|
5475
|
+
*
|
|
5127
5476
|
* @param key Key to queue the item for
|
|
5128
5477
|
* @param parameters Parameters to use when item runs
|
|
5129
5478
|
* @param signal Optional signal to abort the item
|
|
@@ -5134,6 +5483,7 @@ var KeyedQueue = class {
|
|
|
5134
5483
|
}
|
|
5135
5484
|
/**
|
|
5136
5485
|
* Clear all items for a specific key _(or all items for all keys, if no key is provided)_
|
|
5486
|
+
*
|
|
5137
5487
|
* @param key Optional key to clear the queue for
|
|
5138
5488
|
*/
|
|
5139
5489
|
clear(key) {
|
|
@@ -5141,6 +5491,7 @@ var KeyedQueue = class {
|
|
|
5141
5491
|
}
|
|
5142
5492
|
/**
|
|
5143
5493
|
* Get the queue for a specific key
|
|
5494
|
+
*
|
|
5144
5495
|
* @param key Key to get the queue for
|
|
5145
5496
|
* @returns Queue for the key, or `undefined` if it doesn't exist
|
|
5146
5497
|
*/
|
|
@@ -5149,6 +5500,7 @@ var KeyedQueue = class {
|
|
|
5149
5500
|
}
|
|
5150
5501
|
/**
|
|
5151
5502
|
* Pause the queue for a specific key _(or all queues, if no key is provided)_
|
|
5503
|
+
*
|
|
5152
5504
|
* @param key Optional key to pause the queue for
|
|
5153
5505
|
*/
|
|
5154
5506
|
pause(key) {
|
|
@@ -5171,6 +5523,7 @@ var KeyedQueue = class {
|
|
|
5171
5523
|
}
|
|
5172
5524
|
/**
|
|
5173
5525
|
* Resume the queue for a specific key _(or all queues, if no key is provided)_
|
|
5526
|
+
*
|
|
5174
5527
|
* @param key Optional key to resume the queue for
|
|
5175
5528
|
*/
|
|
5176
5529
|
resume(key) {
|
|
@@ -5268,6 +5621,7 @@ var Queue = class {
|
|
|
5268
5621
|
}
|
|
5269
5622
|
/**
|
|
5270
5623
|
* Add an item to the queue
|
|
5624
|
+
*
|
|
5271
5625
|
* @param parameters Parameters to use when item runs
|
|
5272
5626
|
* @param signal Optional signal to abort the item
|
|
5273
5627
|
* @returns Queued item
|
|
@@ -5324,6 +5678,7 @@ var Queue = class {
|
|
|
5324
5678
|
}
|
|
5325
5679
|
/**
|
|
5326
5680
|
* Remove and reject a specific item in the queue
|
|
5681
|
+
*
|
|
5327
5682
|
* @param id ID of queued item
|
|
5328
5683
|
*/
|
|
5329
5684
|
remove(id) {
|
|
@@ -5437,6 +5792,7 @@ const STATUS_PAUSED = "paused";
|
|
|
5437
5792
|
//#region src/random.ts
|
|
5438
5793
|
/**
|
|
5439
5794
|
* Get a random boolean
|
|
5795
|
+
*
|
|
5440
5796
|
* @returns Random boolean
|
|
5441
5797
|
*/
|
|
5442
5798
|
function getRandomBoolean() {
|
|
@@ -5444,6 +5800,7 @@ function getRandomBoolean() {
|
|
|
5444
5800
|
}
|
|
5445
5801
|
/**
|
|
5446
5802
|
* Get a random string of characters with a specified length
|
|
5803
|
+
*
|
|
5447
5804
|
* @param length Length of random string
|
|
5448
5805
|
* @param selection String of characters to select from _(defaults to lowercase English alphabet)_
|
|
5449
5806
|
* @returns Random string of characters
|
|
@@ -5457,6 +5814,7 @@ function getRandomCharacters(length, selection) {
|
|
|
5457
5814
|
}
|
|
5458
5815
|
/**
|
|
5459
5816
|
* Get a random hexadecimal color
|
|
5817
|
+
*
|
|
5460
5818
|
* @param prefix Prefix the color with `#`? _(defaults to `false`)_
|
|
5461
5819
|
* @returns Random hexadecimal color string in the format `(#)RRGGBB`
|
|
5462
5820
|
*/
|
|
@@ -5465,6 +5823,7 @@ function getRandomColor(prefix) {
|
|
|
5465
5823
|
}
|
|
5466
5824
|
/**
|
|
5467
5825
|
* Get a random hexadecimal character
|
|
5826
|
+
*
|
|
5468
5827
|
* @returns Random hexadecimal character from `0-9` and `A-F`
|
|
5469
5828
|
*/
|
|
5470
5829
|
function getRandomHex() {
|
|
@@ -5472,6 +5831,7 @@ function getRandomHex() {
|
|
|
5472
5831
|
}
|
|
5473
5832
|
/**
|
|
5474
5833
|
* Get a random item from an array
|
|
5834
|
+
*
|
|
5475
5835
|
* @param array Array to get a random item from
|
|
5476
5836
|
* @returns Random item from the array, or `undefined` if unable to retrieve one
|
|
5477
5837
|
*/
|
|
@@ -5578,17 +5938,17 @@ attemptPipe.async = attemptAsyncPipe;
|
|
|
5578
5938
|
//#endregion
|
|
5579
5939
|
//#region src/sized/set.ts
|
|
5580
5940
|
/**
|
|
5581
|
-
* A
|
|
5941
|
+
* A _Set_ with a maximum size
|
|
5582
5942
|
*
|
|
5583
|
-
* Behavior is similar to a _LRU_
|
|
5943
|
+
* Behavior is similar to a _LRU_ cache, where the oldest values are removed
|
|
5584
5944
|
*/
|
|
5585
5945
|
var SizedSet = class extends Set {
|
|
5586
5946
|
/**
|
|
5587
|
-
* The maximum size of the
|
|
5947
|
+
* The maximum size of the _Set_
|
|
5588
5948
|
*/
|
|
5589
5949
|
#maximumSize;
|
|
5590
5950
|
/**
|
|
5591
|
-
* Is the
|
|
5951
|
+
* Is the _Set_ full?
|
|
5592
5952
|
*/
|
|
5593
5953
|
get full() {
|
|
5594
5954
|
return this.size >= this.#maximumSize;
|
|
@@ -5615,9 +5975,10 @@ var SizedSet = class extends Set {
|
|
|
5615
5975
|
return super.add(value);
|
|
5616
5976
|
}
|
|
5617
5977
|
/**
|
|
5618
|
-
* Get a value from the
|
|
5619
|
-
*
|
|
5620
|
-
* @param
|
|
5978
|
+
* Get a value from the _SizedSet_, if it exists _(and optionally move it to the end)_
|
|
5979
|
+
*
|
|
5980
|
+
* @param value Value to get from the _SizedSet_
|
|
5981
|
+
* @param update Update the value's position in the _SizedSet_? _(defaults to `false`)_
|
|
5621
5982
|
* @returns Found value if it exists, otherwise `undefined`
|
|
5622
5983
|
*/
|
|
5623
5984
|
get(value, update) {
|
|
@@ -5631,4 +5992,4 @@ var SizedSet = class extends Set {
|
|
|
5631
5992
|
}
|
|
5632
5993
|
};
|
|
5633
5994
|
//#endregion
|
|
5634
|
-
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, 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, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, hexToHsl, hexToHsla, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join,
|
|
5995
|
+
export { CancelablePromise, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, 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, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, 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, hexToRgb, hexToRgba, hslToHex, hslToRgb, hslToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, logger, 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, rgbToHex, rgbToHsl, rgbToHsla, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, 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 };
|