@andrew_l/toolkit 0.2.13 → 0.2.15

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/index.mjs CHANGED
@@ -346,6 +346,90 @@ function shuffle(arr) {
346
346
  return result;
347
347
  }
348
348
 
349
+ class SortedArray extends Array {
350
+ #compareFn;
351
+ /**
352
+ * Creates a new SortedArray instance.
353
+ *
354
+ * @param compareFn The comparison function to determine the sort order
355
+ * @param items Optional initial items to add to the array (will be sorted immediately)
356
+ */
357
+ constructor(compareFn, items = []) {
358
+ super();
359
+ this.#compareFn = compareFn;
360
+ if (items.length > 0) {
361
+ super.push.apply(this, items.toSorted(this.#compareFn));
362
+ }
363
+ }
364
+ /**
365
+ * Inserts multiple items while maintaining sort order
366
+ * @param items The items to insert
367
+ * @returns The new length of the array
368
+ */
369
+ push(...items) {
370
+ var newItems = items.toSorted(this.#compareFn);
371
+ var newItemsLen = newItems.length;
372
+ var originalLen = this.length;
373
+ var result = new Array(originalLen + newItemsLen);
374
+ var i = 0, j = 0, k = 0;
375
+ while (i < originalLen && j < newItemsLen) {
376
+ if (this.#compareFn(this[i], newItems[j]) <= 0) {
377
+ result[k++] = this[i++];
378
+ } else {
379
+ result[k++] = newItems[j++];
380
+ }
381
+ }
382
+ while (i < originalLen) {
383
+ result[k++] = this[i++];
384
+ }
385
+ while (j < newItemsLen) {
386
+ result[k++] = newItems[j++];
387
+ }
388
+ this.length = 0;
389
+ super.push.apply(this, result);
390
+ return this.length;
391
+ }
392
+ /**
393
+ * Override Array methods that would break the sorted order
394
+ */
395
+ unshift(...items) {
396
+ return this.push(...items);
397
+ }
398
+ /**
399
+ * Creates a new SortedArray with the same comparison function
400
+ * @returns A new SortedArray instance
401
+ */
402
+ slice(start, end) {
403
+ var result = new SortedArray(this.#compareFn);
404
+ var sliced = super.slice(start, end);
405
+ super.push.apply(result, sliced);
406
+ return result;
407
+ }
408
+ /**
409
+ * Concatenates arrays or values while maintaining sort order
410
+ * @param items Arrays or values to concatenate
411
+ * @returns A new SortedArray with the concatenated elements
412
+ */
413
+ concat(...items) {
414
+ var result = new SortedArray(this.#compareFn, this);
415
+ for (const item of items) {
416
+ if (Array.isArray(item)) {
417
+ result.push.apply(result, item);
418
+ } else {
419
+ result.push(item);
420
+ }
421
+ }
422
+ return result;
423
+ }
424
+ }
425
+ ["map", "filter", "flatMap", "flat", "reverse", "sort"].forEach((key) => {
426
+ SortedArray.prototype[key] = function() {
427
+ const arr = Array.prototype[key].apply(this, arguments);
428
+ Object.setPrototypeOf(arr, Array.prototype);
429
+ return arr;
430
+ };
431
+ });
432
+
349
433
  const sum = (values) => {
350
434
  return values.reduce((a, b) => a + (isNumber(b) ? b : 0), 0);
351
435
  };
@@ -2485,46 +2569,274 @@ const ColorParser = {
2485
2569
  HEX: parseHEX
2486
2570
  };
2487
2571
 
2488
- const T0 = signed_crc_table();
2489
- function signed_crc_table() {
2490
- var c = 0, table = new Array(256);
2491
- for (var n = 0; n != 256; ++n) {
2492
- c = n;
2493
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2494
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2495
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2496
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2497
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2498
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2499
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2500
- c = c & 1 ? -2097792136 ^ c >>> 1 : c >>> 1;
2501
- table[n] = c;
2502
- }
2503
- return Int32Array ? new Int32Array(table) : table;
2504
- }
2505
- function crc32(str, seed = 0) {
2506
- var C = seed ^ -1;
2507
- for (var i = 0, L = str.length, c = 0, d = 0; i < L; ) {
2508
- c = str.charCodeAt(i++);
2509
- if (c < 128) {
2510
- C = C >>> 8 ^ T0[(C ^ c) & 255];
2511
- } else if (c < 2048) {
2512
- C = C >>> 8 ^ T0[(C ^ (192 | c >> 6 & 31)) & 255];
2513
- C = C >>> 8 ^ T0[(C ^ (128 | c & 63)) & 255];
2514
- } else if (c >= 55296 && c < 57344) {
2515
- c = (c & 1023) + 64;
2516
- d = str.charCodeAt(i++) & 1023;
2517
- C = C >>> 8 ^ T0[(C ^ (240 | c >> 8 & 7)) & 255];
2518
- C = C >>> 8 ^ T0[(C ^ (128 | c >> 2 & 63)) & 255];
2519
- C = C >>> 8 ^ T0[(C ^ (128 | d >> 6 & 15 | (c & 3) << 4)) & 255];
2520
- C = C >>> 8 ^ T0[(C ^ (128 | d & 63)) & 255];
2521
- } else {
2522
- C = C >>> 8 ^ T0[(C ^ (224 | c >> 12 & 15)) & 255];
2523
- C = C >>> 8 ^ T0[(C ^ (128 | c >> 6 & 63)) & 255];
2524
- C = C >>> 8 ^ T0[(C ^ (128 | c & 63)) & 255];
2525
- }
2572
+ var encoder = new TextEncoder();
2573
+ var TABLE = new Int32Array([
2574
+ 0,
2575
+ 1996959894,
2576
+ 3993919788,
2577
+ 2567524794,
2578
+ 124634137,
2579
+ 1886057615,
2580
+ 3915621685,
2581
+ 2657392035,
2582
+ 249268274,
2583
+ 2044508324,
2584
+ 3772115230,
2585
+ 2547177864,
2586
+ 162941995,
2587
+ 2125561021,
2588
+ 3887607047,
2589
+ 2428444049,
2590
+ 498536548,
2591
+ 1789927666,
2592
+ 4089016648,
2593
+ 2227061214,
2594
+ 450548861,
2595
+ 1843258603,
2596
+ 4107580753,
2597
+ 2211677639,
2598
+ 325883990,
2599
+ 1684777152,
2600
+ 4251122042,
2601
+ 2321926636,
2602
+ 335633487,
2603
+ 1661365465,
2604
+ 4195302755,
2605
+ 2366115317,
2606
+ 997073096,
2607
+ 1281953886,
2608
+ 3579855332,
2609
+ 2724688242,
2610
+ 1006888145,
2611
+ 1258607687,
2612
+ 3524101629,
2613
+ 2768942443,
2614
+ 901097722,
2615
+ 1119000684,
2616
+ 3686517206,
2617
+ 2898065728,
2618
+ 853044451,
2619
+ 1172266101,
2620
+ 3705015759,
2621
+ 2882616665,
2622
+ 651767980,
2623
+ 1373503546,
2624
+ 3369554304,
2625
+ 3218104598,
2626
+ 565507253,
2627
+ 1454621731,
2628
+ 3485111705,
2629
+ 3099436303,
2630
+ 671266974,
2631
+ 1594198024,
2632
+ 3322730930,
2633
+ 2970347812,
2634
+ 795835527,
2635
+ 1483230225,
2636
+ 3244367275,
2637
+ 3060149565,
2638
+ 1994146192,
2639
+ 31158534,
2640
+ 2563907772,
2641
+ 4023717930,
2642
+ 1907459465,
2643
+ 112637215,
2644
+ 2680153253,
2645
+ 3904427059,
2646
+ 2013776290,
2647
+ 251722036,
2648
+ 2517215374,
2649
+ 3775830040,
2650
+ 2137656763,
2651
+ 141376813,
2652
+ 2439277719,
2653
+ 3865271297,
2654
+ 1802195444,
2655
+ 476864866,
2656
+ 2238001368,
2657
+ 4066508878,
2658
+ 1812370925,
2659
+ 453092731,
2660
+ 2181625025,
2661
+ 4111451223,
2662
+ 1706088902,
2663
+ 314042704,
2664
+ 2344532202,
2665
+ 4240017532,
2666
+ 1658658271,
2667
+ 366619977,
2668
+ 2362670323,
2669
+ 4224994405,
2670
+ 1303535960,
2671
+ 984961486,
2672
+ 2747007092,
2673
+ 3569037538,
2674
+ 1256170817,
2675
+ 1037604311,
2676
+ 2765210733,
2677
+ 3554079995,
2678
+ 1131014506,
2679
+ 879679996,
2680
+ 2909243462,
2681
+ 3663771856,
2682
+ 1141124467,
2683
+ 855842277,
2684
+ 2852801631,
2685
+ 3708648649,
2686
+ 1342533948,
2687
+ 654459306,
2688
+ 3188396048,
2689
+ 3373015174,
2690
+ 1466479909,
2691
+ 544179635,
2692
+ 3110523913,
2693
+ 3462522015,
2694
+ 1591671054,
2695
+ 702138776,
2696
+ 2966460450,
2697
+ 3352799412,
2698
+ 1504918807,
2699
+ 783551873,
2700
+ 3082640443,
2701
+ 3233442989,
2702
+ 3988292384,
2703
+ 2596254646,
2704
+ 62317068,
2705
+ 1957810842,
2706
+ 3939845945,
2707
+ 2647816111,
2708
+ 81470997,
2709
+ 1943803523,
2710
+ 3814918930,
2711
+ 2489596804,
2712
+ 225274430,
2713
+ 2053790376,
2714
+ 3826175755,
2715
+ 2466906013,
2716
+ 167816743,
2717
+ 2097651377,
2718
+ 4027552580,
2719
+ 2265490386,
2720
+ 503444072,
2721
+ 1762050814,
2722
+ 4150417245,
2723
+ 2154129355,
2724
+ 426522225,
2725
+ 1852507879,
2726
+ 4275313526,
2727
+ 2312317920,
2728
+ 282753626,
2729
+ 1742555852,
2730
+ 4189708143,
2731
+ 2394877945,
2732
+ 397917763,
2733
+ 1622183637,
2734
+ 3604390888,
2735
+ 2714866558,
2736
+ 953729732,
2737
+ 1340076626,
2738
+ 3518719985,
2739
+ 2797360999,
2740
+ 1068828381,
2741
+ 1219638859,
2742
+ 3624741850,
2743
+ 2936675148,
2744
+ 906185462,
2745
+ 1090812512,
2746
+ 3747672003,
2747
+ 2825379669,
2748
+ 829329135,
2749
+ 1181335161,
2750
+ 3412177804,
2751
+ 3160834842,
2752
+ 628085408,
2753
+ 1382605366,
2754
+ 3423369109,
2755
+ 3138078467,
2756
+ 570562233,
2757
+ 1426400815,
2758
+ 3317316542,
2759
+ 2998733608,
2760
+ 733239954,
2761
+ 1555261956,
2762
+ 3268935591,
2763
+ 3050360625,
2764
+ 752459403,
2765
+ 1541320221,
2766
+ 2607071920,
2767
+ 3965973030,
2768
+ 1969922972,
2769
+ 40735498,
2770
+ 2617837225,
2771
+ 3943577151,
2772
+ 1913087877,
2773
+ 83908371,
2774
+ 2512341634,
2775
+ 3803740692,
2776
+ 2075208622,
2777
+ 213261112,
2778
+ 2463272603,
2779
+ 3855990285,
2780
+ 2094854071,
2781
+ 198958881,
2782
+ 2262029012,
2783
+ 4057260610,
2784
+ 1759359992,
2785
+ 534414190,
2786
+ 2176718541,
2787
+ 4139329115,
2788
+ 1873836001,
2789
+ 414664567,
2790
+ 2282248934,
2791
+ 4279200368,
2792
+ 1711684554,
2793
+ 285281116,
2794
+ 2405801727,
2795
+ 4167216745,
2796
+ 1634467795,
2797
+ 376229701,
2798
+ 2685067896,
2799
+ 3608007406,
2800
+ 1308918612,
2801
+ 956543938,
2802
+ 2808555105,
2803
+ 3495958263,
2804
+ 1231636301,
2805
+ 1047427035,
2806
+ 2932959818,
2807
+ 3654703836,
2808
+ 1088359270,
2809
+ 936918e3,
2810
+ 2847714899,
2811
+ 3736837829,
2812
+ 1202900863,
2813
+ 817233897,
2814
+ 3183342108,
2815
+ 3401237130,
2816
+ 1404277552,
2817
+ 615818150,
2818
+ 3134207493,
2819
+ 3453421203,
2820
+ 1423857449,
2821
+ 601450431,
2822
+ 3009837614,
2823
+ 3294710456,
2824
+ 1567103746,
2825
+ 711928724,
2826
+ 3020668471,
2827
+ 3272380065,
2828
+ 1510334235,
2829
+ 755167117
2830
+ ]);
2831
+ function crc32(current, seed) {
2832
+ if (isString(current)) {
2833
+ return crc32(encoder.encode(current), seed);
2834
+ }
2835
+ var crc = seed === 0 ? 0 : ~~seed ^ -1;
2836
+ for (var index = 0; index < current.length; index++) {
2837
+ crc = TABLE[(crc ^ current[index]) & 255] ^ crc >>> 8;
2526
2838
  }
2527
- return ~C;
2839
+ return crc ^ -1;
2528
2840
  }
2529
2841
 
2530
2842
  function isDateObject(value) {
@@ -4069,7 +4381,7 @@ class SimpleEventEmitter {
4069
4381
  if (!set) return false;
4070
4382
  set.forEach((fn) => {
4071
4383
  try {
4072
- const result = fn();
4384
+ const result = fn(...args);
4073
4385
  if (isPromise(result)) {
4074
4386
  result.catch((err) => {
4075
4387
  this.emit("error", err);
@@ -4568,5 +4880,5 @@ function wrapText(value, maxLength = 30) {
4568
4880
  return value;
4569
4881
  }
4570
4882
 
4571
- export { AppError, AsyncIterableQueue, BrowserAssertionError, CancellablePromise, ColorParser, instance as EJSON, EJSONStream, FindMean, FixedMap, FixedWeakMap, LruCache, Queue, SimpleEventEmitter, TWEMOJI_REGEX, TimeBucket, TimeSpan, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, avgCircular, base64ToBytes, bigIntBytes, bigIntFromBytes, blendColors, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createRandomizer, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dateInDays, dateInSeconds, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getMostSpecificPaths, getRandomInt, getRandomTime, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, interpolateColor, intersection, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDef, isEmpty, isEqual, isError, isFunction, isInfinity, isMap, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, loggerSetLevel, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, secondsToHm, set, shuffle, snakeCase, sprintf, startCase, strAssign, sum, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, uint16ToUint8, uint32ToUint8, uint8ToUint16, uint8ToUint32, unflatten, union, uniq, uniqBy, unset, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, wrapText };
4883
+ export { AppError, AsyncIterableQueue, BrowserAssertionError, CancellablePromise, ColorParser, instance as EJSON, EJSON as EJSONInstance, EJSONStream, FindMean, FixedMap, FixedWeakMap, LruCache, Queue, SimpleEventEmitter, SortedArray, TWEMOJI_REGEX, TimeBucket, TimeSpan, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, avgCircular, base64ToBytes, bigIntBytes, bigIntFromBytes, blendColors, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createRandomizer, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dateInDays, dateInSeconds, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getMostSpecificPaths, getRandomInt, getRandomTime, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, interpolateColor, intersection, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDef, isEmpty, isEqual, isError, isFunction, isInfinity, isMap, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, loggerSetLevel, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, secondsToHm, set, shuffle, snakeCase, sprintf, startCase, strAssign, sum, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, uint16ToUint8, uint32ToUint8, uint8ToUint16, uint8ToUint32, unflatten, union, uniq, uniqBy, unset, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, wrapText };
4572
4884
  //# sourceMappingURL=index.mjs.map