@tspro/ts-utils-lib 1.18.0 → 1.19.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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.18.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.19.1 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  var __defProp = Object.defineProperty;
3
3
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
4
4
  var __export = (target, all) => {
@@ -479,21 +479,6 @@ var _consent;
479
479
  var _expires;
480
480
  var str = _read(ConsentCookieName);
481
481
  _consent = str === "accept" /* Accept */ || str === "decline" /* Decline */ ? str : void 0;
482
- function setExpireDays(days) {
483
- _expires = /* @__PURE__ */ new Date();
484
- _expires.setDate(_expires.getDate() + days);
485
- }
486
- function isConsentPending() {
487
- return _consent === void 0;
488
- }
489
- function accept() {
490
- _consent = "accept" /* Accept */;
491
- _save(ConsentCookieName, _consent);
492
- }
493
- function decline() {
494
- _consent = "decline" /* Decline */;
495
- _save(ConsentCookieName, _consent);
496
- }
497
482
  function _getList() {
498
483
  let s = document.cookie;
499
484
  return s.split(";").map((c) => c.trim());
@@ -513,18 +498,31 @@ function _read(name, defaultValue) {
513
498
  function _erase(name) {
514
499
  document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC;";
515
500
  }
501
+ function setExpireDays(days) {
502
+ _expires = /* @__PURE__ */ new Date();
503
+ _expires.setDate(_expires.getDate() + days);
504
+ }
505
+ function isConsentPending() {
506
+ return _consent === void 0;
507
+ }
508
+ function accept() {
509
+ _consent = "accept" /* Accept */;
510
+ _save(ConsentCookieName, _consent);
511
+ }
512
+ function decline() {
513
+ _consent = "decline" /* Decline */;
514
+ _save(ConsentCookieName, _consent);
515
+ }
516
516
  function save(name, value) {
517
- if (_consent === "accept" /* Accept */) {
517
+ if (_consent === "accept" /* Accept */)
518
518
  _save(name, value);
519
- }
520
519
  return value;
521
520
  }
522
521
  function read(name, defaultValue) {
523
- if (_consent === "accept" /* Accept */) {
524
- return _read(name, defaultValue) || defaultValue;
525
- } else {
522
+ if (_consent === "accept" /* Accept */)
523
+ return _read(name, defaultValue) ?? defaultValue;
524
+ else
526
525
  return defaultValue;
527
- }
528
526
  }
529
527
  function readInt(name, defaultValue) {
530
528
  if (_consent === "accept" /* Accept */) {
@@ -543,9 +541,8 @@ function readBool(name, defaultValue) {
543
541
  }
544
542
  }
545
543
  function erase(name) {
546
- if (_consent === "accept" /* Accept */ || name === ConsentCookieName) {
544
+ if (_consent === "accept" /* Accept */ || name === ConsentCookieName)
547
545
  _erase(name);
548
- }
549
546
  }
550
547
  function eraseAll() {
551
548
  document.cookie.split(";").forEach((c) => erase(c.trim().split("=")[0]));
@@ -653,7 +650,7 @@ function toPx(input) {
653
650
  } else {
654
651
  value = parseFloat(input);
655
652
  }
656
- assert_exports.finite(value, "value in function toPx");
653
+ assert_exports.isFinite(value, "value in function toPx");
657
654
  switch (unit) {
658
655
  case "mm":
659
656
  return mmToPx(value);
@@ -1001,11 +998,11 @@ function toArray(a) {
1001
998
  function duplicate(a) {
1002
999
  return a === void 0 ? a : a.slice();
1003
1000
  }
1004
- function removeDuplicates(a) {
1005
- return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
1001
+ function removeDuplicates(arr, compareFn) {
1002
+ return compareFn !== void 0 ? arr.filter((a, id, self) => id === self.findIndex((b) => compareFn(a, b))) : arr.filter((a, id, self) => id === self.indexOf(a));
1006
1003
  }
1007
- function removeDuplicatesCmp(arr, cmp2) {
1008
- return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp2(t1, t2)));
1004
+ function removeDuplicatesCmp(arr, compareFn) {
1005
+ return arr.filter((a, id, self) => id === self.findIndex((b) => compareFn(a, b)));
1009
1006
  }
1010
1007
  function fillArray(fillValue, fillCount) {
1011
1008
  if (!isInteger2(fillCount) || fillCount < 0) {
@@ -1468,30 +1465,83 @@ function makeSentenceFromPascal(PascalString) {
1468
1465
  // src/utils/index.ts
1469
1466
  var Is = guard_exports;
1470
1467
 
1468
+ // src/core/format-value.ts
1469
+ function formatValue(value) {
1470
+ if (isString2(value)) {
1471
+ return `"${value}"`;
1472
+ } else if (isArray2(value)) {
1473
+ return `[ ${value.map((e) => formatValue(e)).join(", ")} ]`.replaceAll(" ", " ");
1474
+ } else if (isFunction2(value.toString)) {
1475
+ return value.toString();
1476
+ } else {
1477
+ return JSON.stringify(value);
1478
+ }
1479
+ }
1480
+
1471
1481
  // src/core/stack.ts
1472
1482
  var Stack = class {
1473
1483
  constructor() {
1474
- __publicField(this, "list", []);
1484
+ __publicField(this, "data", []);
1485
+ }
1486
+ assertId(id) {
1487
+ assert_exports.isIntegerBetween(id, 0, this.length - 1, `Stack index ${id} out of range.`);
1488
+ return id;
1475
1489
  }
1476
- push(e) {
1477
- this.list.push(e);
1478
- return e;
1490
+ get length() {
1491
+ return this.data.length;
1492
+ }
1493
+ push(el) {
1494
+ this.data.push(el);
1495
+ return el;
1479
1496
  }
1480
1497
  pop() {
1481
- assert_exports.int_gt(this.list.length, 0);
1482
- return this.list.pop();
1498
+ this.assertId(this.length - 1);
1499
+ return this.data.pop();
1500
+ }
1501
+ popOrUndef() {
1502
+ return this.data.pop();
1503
+ }
1504
+ popOr(defaultValueOrCreator) {
1505
+ return this.isEmpty() ? isFunction2(defaultValueOrCreator) ? defaultValueOrCreator() : defaultValueOrCreator : this.data.pop();
1483
1506
  }
1484
1507
  top() {
1485
- return assert_exports.array_elem(this.list, this.list.length - 1, "Stack is empty!");
1508
+ return this.data[this.assertId(this.length - 1)];
1509
+ }
1510
+ topOrUndef() {
1511
+ return this.data[this.length - 1];
1512
+ }
1513
+ topOr(defaultValueOrCreator) {
1514
+ return this.isEmpty() ? isFunction2(defaultValueOrCreator) ? defaultValueOrCreator() : defaultValueOrCreator : this.data[this.length - 1];
1515
+ }
1516
+ peek(depth = 0) {
1517
+ return this.data[this.assertId(this.data.length - 1 - depth)];
1518
+ }
1519
+ peekOrUndef(depth = 0) {
1520
+ return this.data[this.data.length - 1 - depth];
1521
+ }
1522
+ peekOr(depth = 0, defaultValueOrCreator) {
1523
+ const id = this.data.length - 1 - depth;
1524
+ const value = id < 0 ? void 0 : this.data[id];
1525
+ return value === void 0 ? isFunction2(defaultValueOrCreator) ? defaultValueOrCreator() : defaultValueOrCreator : value;
1526
+ }
1527
+ *values() {
1528
+ for (let id = this.data.length - 1; id >= 0; id--)
1529
+ yield this.data[id];
1530
+ }
1531
+ *[Symbol.iterator]() {
1532
+ yield* this.values();
1486
1533
  }
1487
1534
  toArray() {
1488
- return this.list;
1535
+ return [...this.data];
1489
1536
  }
1490
- get length() {
1491
- return this.list.length;
1537
+ isEmpty() {
1538
+ return this.length === 0;
1492
1539
  }
1493
1540
  clear() {
1494
- this.list.length = 0;
1541
+ this.data.length = 0;
1542
+ }
1543
+ toString() {
1544
+ return `Stack(${this.length})${formatValue(this.data)}`;
1495
1545
  }
1496
1546
  };
1497
1547
 
@@ -2075,6 +2125,14 @@ var IndexArray = class _IndexArray {
2075
2125
  get size() {
2076
2126
  return this.valCount;
2077
2127
  }
2128
+ get length() {
2129
+ return this.hasPos.length;
2130
+ }
2131
+ trimRight() {
2132
+ let newLength = this.length;
2133
+ while (newLength > 0 && this.hasPos[newLength - 1] !== true) newLength--;
2134
+ if (newLength < this.length) this.posVal.length = this.hasPos.length = newLength;
2135
+ }
2078
2136
  isEmpty() {
2079
2137
  return this.size === 0;
2080
2138
  }
@@ -2109,6 +2167,7 @@ var IndexArray = class _IndexArray {
2109
2167
  this.posVal[id] = void 0;
2110
2168
  this.hasPos[id] = false;
2111
2169
  this.valCount--;
2170
+ this.trimRight();
2112
2171
  return true;
2113
2172
  }
2114
2173
  clear() {
@@ -2245,10 +2304,12 @@ var IndexArray = class _IndexArray {
2245
2304
  }
2246
2305
  return true;
2247
2306
  }
2307
+ toArray() {
2308
+ return this.valuesArray();
2309
+ }
2248
2310
  toString() {
2249
- if (this.size === 0) return `IndexArray[ ]`;
2250
- const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
2251
- return `IndexArray[ ${entries} ]`;
2311
+ const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2312
+ return `IndexArray[ ${entries} ]`.replaceAll(" ", " ");
2252
2313
  }
2253
2314
  };
2254
2315
 
@@ -2506,10 +2567,215 @@ var SignedIndexArray = class _SignedIndexArray {
2506
2567
  }
2507
2568
  return true;
2508
2569
  }
2570
+ toArray() {
2571
+ return this.valuesArray();
2572
+ }
2509
2573
  toString() {
2510
- if (this.size === 0) return `SignedIndexArray[ ]`;
2511
- const entries = this.entriesArray().map(([id, value]) => `${id}: ${value}`).join(", ");
2512
- return `SignedIndexArray[ ${entries} ]`;
2574
+ const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2575
+ return `SignedIndexArray[ ${entries} ]`.replaceAll(" ", " ");
2576
+ }
2577
+ };
2578
+
2579
+ // src/core/default-array.ts
2580
+ var DefaultArray = class _DefaultArray {
2581
+ constructor(lengthOrValues, defaultValue) {
2582
+ this.defaultValue = defaultValue;
2583
+ __publicField(this, "data");
2584
+ if (typeof lengthOrValues === "number") {
2585
+ this.data = Array(lengthOrValues).fill(defaultValue);
2586
+ } else {
2587
+ this.data = Array.from(lengthOrValues).map(
2588
+ (v) => v === void 0 ? defaultValue : v
2589
+ );
2590
+ }
2591
+ }
2592
+ get size() {
2593
+ return this.data.length;
2594
+ }
2595
+ get length() {
2596
+ return this.data.length;
2597
+ }
2598
+ assertId(id) {
2599
+ if (id < 0 || id >= this.data.length)
2600
+ throw new RangeError(`DefaultArray: Index ${id} out of range`);
2601
+ return id;
2602
+ }
2603
+ isEmpty() {
2604
+ return this.size === 0;
2605
+ }
2606
+ isDefault(id) {
2607
+ return this.data[this.assertId(id)] === this.defaultValue;
2608
+ }
2609
+ isSet(id) {
2610
+ return this.data[this.assertId(id)] !== this.defaultValue;
2611
+ }
2612
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
2613
+ has(id) {
2614
+ return this.isSet(id);
2615
+ }
2616
+ set(id, value) {
2617
+ return this.data[this.assertId(id)] = value;
2618
+ }
2619
+ get(id) {
2620
+ return this.data[this.assertId(id)];
2621
+ }
2622
+ getOrDefault(id, defaultValue) {
2623
+ let value = this.get(id);
2624
+ return value === this.defaultValue ? defaultValue : value;
2625
+ }
2626
+ getOrCreate(id, creatorOrValue) {
2627
+ if (!this.has(id)) {
2628
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
2629
+ this.set(id, value);
2630
+ return value;
2631
+ }
2632
+ return this.get(id);
2633
+ }
2634
+ delete(id) {
2635
+ this.assertId(id);
2636
+ if (this.data[id] === this.defaultValue) return false;
2637
+ this.data[id] = this.defaultValue;
2638
+ return true;
2639
+ }
2640
+ clear(empty = false) {
2641
+ if (empty)
2642
+ this.data = [];
2643
+ else
2644
+ this.data.fill(this.defaultValue);
2645
+ }
2646
+ forEach(callbackfn, thisArg) {
2647
+ for (const [id, value] of this.entries()) {
2648
+ callbackfn.call(thisArg, value, id, this);
2649
+ }
2650
+ }
2651
+ *indices() {
2652
+ yield* this.data.keys();
2653
+ }
2654
+ *values() {
2655
+ yield* this.data.values();
2656
+ }
2657
+ *entries() {
2658
+ yield* this.data.entries();
2659
+ }
2660
+ indicesArray() {
2661
+ return [...this.indices()];
2662
+ }
2663
+ valuesArray() {
2664
+ return [...this.values()];
2665
+ }
2666
+ entriesArray() {
2667
+ return [...this.entries()];
2668
+ }
2669
+ *kvKeys() {
2670
+ for (const id of this.indices()) {
2671
+ yield [id];
2672
+ }
2673
+ }
2674
+ *kvValues() {
2675
+ for (const value of this.values()) {
2676
+ yield value;
2677
+ }
2678
+ }
2679
+ *kvEntries() {
2680
+ for (const [id, value] of this.entries()) {
2681
+ yield [[id], value];
2682
+ }
2683
+ }
2684
+ *[Symbol.iterator]() {
2685
+ yield* this.entries();
2686
+ }
2687
+ clone() {
2688
+ const ctor = this.constructor;
2689
+ const clone = new ctor(this.length, this.defaultValue);
2690
+ clone.data = this.data.slice();
2691
+ return clone;
2692
+ }
2693
+ merge(other, conflictResolver) {
2694
+ if (this.constructor !== other.constructor)
2695
+ throw new Error(`Cannot merge DefaultArray: different classes (${this.constructor.name} vs ${other.constructor.name})`);
2696
+ if (this.defaultValue !== other.defaultValue)
2697
+ throw new Error(`Cannot merge DefaultArray: different defaultValue (${this.defaultValue} vs ${other.defaultValue})`);
2698
+ for (const [id, value] of other.entries()) {
2699
+ if (this.isDefault(id))
2700
+ this.set(id, value);
2701
+ else if (conflictResolver)
2702
+ this.set(id, conflictResolver(this.get(id), value, id));
2703
+ else
2704
+ this.set(id, value);
2705
+ }
2706
+ return this;
2707
+ }
2708
+ some(fn) {
2709
+ for (const [id, value] of this.entries()) {
2710
+ if (fn(value, id)) return true;
2711
+ }
2712
+ return false;
2713
+ }
2714
+ every(fn) {
2715
+ for (const [id, value] of this.entries()) {
2716
+ if (!fn(value, id)) return false;
2717
+ }
2718
+ return true;
2719
+ }
2720
+ filter(predicate) {
2721
+ const result = new this.constructor(this.length, this.defaultValue);
2722
+ for (const [id, value] of this.entries()) {
2723
+ if (predicate(value, id, this)) result.set(id, value);
2724
+ }
2725
+ return result;
2726
+ }
2727
+ reduce(fn, init) {
2728
+ let iterator = this.entries();
2729
+ let first = iterator.next();
2730
+ if (first.done) {
2731
+ if (arguments.length < 2) {
2732
+ throw new TypeError("Reduce of empty DefaultArray with no initial value!");
2733
+ }
2734
+ return init;
2735
+ }
2736
+ let acc;
2737
+ let start;
2738
+ if (arguments.length < 2) {
2739
+ acc = first.value[1];
2740
+ start = iterator.next();
2741
+ } else {
2742
+ acc = init;
2743
+ start = first;
2744
+ }
2745
+ for (let current = start; !current.done; current = iterator.next()) {
2746
+ const [id, value] = current.value;
2747
+ acc = fn(acc, value, id);
2748
+ }
2749
+ return acc;
2750
+ }
2751
+ mapToArray(fn) {
2752
+ let result = [];
2753
+ for (const [id, value] of this.entries()) {
2754
+ result.push(fn(value, id));
2755
+ }
2756
+ return result;
2757
+ }
2758
+ map(fn, defaultValue) {
2759
+ let result = new _DefaultArray(this.data.length, defaultValue);
2760
+ for (let id = 0; id < this.data.length; id++) {
2761
+ result.data[id] = fn(this.data[id], id);
2762
+ }
2763
+ return result;
2764
+ }
2765
+ equals(other, eq2) {
2766
+ if (this.size !== other.size) return false;
2767
+ eq2 ?? (eq2 = (a, b) => a === b);
2768
+ for (let id = 0; id < this.data.length; ++id) {
2769
+ if (!eq2(this.data[id], other.data[id])) return false;
2770
+ }
2771
+ return true;
2772
+ }
2773
+ toArray() {
2774
+ return this.valuesArray();
2775
+ }
2776
+ toString() {
2777
+ const entries = this.entriesArray().map(([id, v]) => `${formatValue(id)}: ${formatValue(v)}`).join(", ");
2778
+ return `DefaultArray[ ${entries} ]`.replaceAll(" ", " ");
2513
2779
  }
2514
2780
  };
2515
2781
 
@@ -2666,8 +2932,8 @@ var Map1 = class _Map1 {
2666
2932
  return new Map(this.map1);
2667
2933
  }
2668
2934
  toString() {
2669
- const entries = [...this.map1].map(([k, v]) => `${k} => ${v}`).join(", ");
2670
- return entries.length === 0 ? `Map1(0){ }` : `Map1(${this.size}){ ${entries} }`;
2935
+ const entries = [...this.map1].map(([k, v]) => `${formatValue(k)} => ${formatValue(v)}`).join(", ");
2936
+ return `Map1(${this.size}){ ${entries} }`.replaceAll(" ", " ");
2671
2937
  }
2672
2938
  };
2673
2939
 
@@ -2860,10 +3126,10 @@ var Map2 = class _Map2 {
2860
3126
  toString() {
2861
3127
  const entries = [];
2862
3128
  for (const [key1, map2] of this.map1) {
2863
- const inner = [...map2].map(([key2, v]) => `${key2} => ${v}`).join(", ");
2864
- entries.push(`${key1} => { ${inner} }`);
3129
+ const inner = [...map2].map(([key2, v]) => `${formatValue(key2)} => ${formatValue(v)}`).join(", ");
3130
+ entries.push(`${formatValue(key1)} => { ${inner} }`);
2865
3131
  }
2866
- return entries.length === 0 ? `Map2(0){ }` : `Map2(${this.size}){ ${entries} }`;
3132
+ return `Map2(${this.size}){ ${entries} }`.replaceAll(" ", " ");
2867
3133
  }
2868
3134
  };
2869
3135
 
@@ -3088,11 +3354,209 @@ var Map3 = class _Map3 {
3088
3354
  const entries = [];
3089
3355
  for (const [key1, map2] of this.map1) {
3090
3356
  for (const [key2, map3] of map2) {
3091
- const inner = [...map3].map(([key3, v]) => `${key3} => ${v}`).join(", ");
3092
- entries.push(`${key1} => ${key2} => { ${inner} }`);
3357
+ const inner = [...map3].map(([key3, v]) => `${formatValue(key3)} => ${formatValue(v)}`).join(", ");
3358
+ entries.push(`${formatValue(key1)} => ${formatValue(key2)} => { ${inner} }`);
3359
+ }
3360
+ }
3361
+ return `Map3(${this.size}){ ${entries.join(", ")} }`.replaceAll(" ", " ");
3362
+ }
3363
+ };
3364
+
3365
+ // src/core/set.ts
3366
+ var SetBase = class {
3367
+ constructor(entries) {
3368
+ __publicField(this, "data");
3369
+ this.data = new Set(entries ?? []);
3370
+ }
3371
+ has(value) {
3372
+ return this.some((v) => this.valueEquals(v, value));
3373
+ }
3374
+ add(value) {
3375
+ if (!this.has(value))
3376
+ this.data.add(value);
3377
+ return value;
3378
+ }
3379
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3380
+ set(key, value) {
3381
+ if (!this.valueEquals(key, value))
3382
+ throw new TypeError("SetBase.set() requires key === value.");
3383
+ this.add(value);
3384
+ }
3385
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3386
+ get(key) {
3387
+ return this.has(key) ? key : void 0;
3388
+ }
3389
+ /** @internal - This method exists only for interface `KVComponent` compatibility.*/
3390
+ getOrDefault(key, defaultValue) {
3391
+ return this.get(key) ?? defaultValue;
3392
+ }
3393
+ getOrCreate(key, creatorOrValue) {
3394
+ if (!this.has(key)) {
3395
+ const value = isFunction2(creatorOrValue) ? creatorOrValue() : creatorOrValue;
3396
+ this.set(key, value);
3397
+ return value;
3398
+ }
3399
+ return this.get(key);
3400
+ }
3401
+ delete(value) {
3402
+ if (!this.has(value)) return false;
3403
+ for (const v of this.values()) {
3404
+ if (this.valueEquals(v, value)) {
3405
+ this.data.delete(v);
3406
+ return true;
3407
+ }
3408
+ }
3409
+ return false;
3410
+ }
3411
+ clear() {
3412
+ this.data.clear();
3413
+ }
3414
+ get size() {
3415
+ return this.data.size;
3416
+ }
3417
+ isEmpty() {
3418
+ return this.size === 0;
3419
+ }
3420
+ forEach(callbackfn, thisArg) {
3421
+ this.data.forEach((value) => callbackfn.call(thisArg, value, this));
3422
+ }
3423
+ *keys() {
3424
+ yield* this.data.keys();
3425
+ }
3426
+ *values() {
3427
+ yield* this.data.values();
3428
+ }
3429
+ *entries() {
3430
+ yield* this.data.entries();
3431
+ }
3432
+ *kvKeys() {
3433
+ for (const key of this.keys()) {
3434
+ yield [key];
3435
+ }
3436
+ }
3437
+ *kvValues() {
3438
+ for (const el of this.values()) {
3439
+ yield el;
3440
+ }
3441
+ }
3442
+ *kvEntries() {
3443
+ for (const [key, el] of this.entries()) {
3444
+ yield [[key], el];
3445
+ }
3446
+ }
3447
+ *[Symbol.iterator]() {
3448
+ yield* this.values();
3449
+ }
3450
+ clone() {
3451
+ const result = this.createEmpty();
3452
+ for (const v of this.values()) result.add(v);
3453
+ return result;
3454
+ }
3455
+ merge(other) {
3456
+ for (const value of other.values()) {
3457
+ this.add(value);
3458
+ }
3459
+ return this;
3460
+ }
3461
+ some(fn) {
3462
+ for (const value of this.data) {
3463
+ if (fn(value)) return true;
3464
+ }
3465
+ return false;
3466
+ }
3467
+ every(fn) {
3468
+ for (const value of this.data) {
3469
+ if (!fn(value)) return false;
3470
+ }
3471
+ return true;
3472
+ }
3473
+ filter(predicate) {
3474
+ const result = this.createEmpty();
3475
+ for (const value of this.data)
3476
+ if (predicate(value, this)) result.add(value);
3477
+ return result;
3478
+ }
3479
+ reduce(fn, init) {
3480
+ let iterator = this.values();
3481
+ let first = iterator.next();
3482
+ if (first.done) {
3483
+ if (arguments.length < 2) {
3484
+ throw new TypeError("Reduce of empty SetBase with no initial value!");
3093
3485
  }
3486
+ return init;
3094
3487
  }
3095
- return entries.length === 0 ? `Map3(0){ }` : `Map3(${this.size}){ ${entries.join(", ")} }`;
3488
+ let acc;
3489
+ let start;
3490
+ if (arguments.length < 2) {
3491
+ acc = first.value;
3492
+ start = iterator.next();
3493
+ } else {
3494
+ acc = init;
3495
+ start = first;
3496
+ }
3497
+ for (let current = start; !current.done; current = iterator.next()) {
3498
+ const value = current.value;
3499
+ acc = fn(acc, value);
3500
+ }
3501
+ return acc;
3502
+ }
3503
+ mapValues(fn) {
3504
+ let result = this.createEmpty();
3505
+ for (const value of this.data) {
3506
+ result.add(fn(value));
3507
+ }
3508
+ return result;
3509
+ }
3510
+ mapToArray(fn) {
3511
+ let result = [];
3512
+ for (const value of this.values()) {
3513
+ result.push(fn(value));
3514
+ }
3515
+ return result;
3516
+ }
3517
+ map(fn) {
3518
+ let result = this.createEmpty();
3519
+ for (const value of this.values()) {
3520
+ result.add(fn(value));
3521
+ }
3522
+ return result;
3523
+ }
3524
+ toSet() {
3525
+ return new Set(this.data);
3526
+ }
3527
+ toArray() {
3528
+ return [...this.values()];
3529
+ }
3530
+ toString() {
3531
+ return `${this.getName()}(${this.size})${formatValue([...this.data])}`.replaceAll(" ", " ");
3532
+ }
3533
+ };
3534
+ var Set1 = class _Set1 extends SetBase {
3535
+ constructor(entries) {
3536
+ super(entries);
3537
+ }
3538
+ createEmpty() {
3539
+ return new _Set1();
3540
+ }
3541
+ valueEquals(a, b) {
3542
+ return a === b;
3543
+ }
3544
+ getName() {
3545
+ return "Set1";
3546
+ }
3547
+ };
3548
+ var DeepSet = class _DeepSet extends SetBase {
3549
+ constructor(entries) {
3550
+ super(entries);
3551
+ }
3552
+ createEmpty() {
3553
+ return new _DeepSet();
3554
+ }
3555
+ valueEquals(a, b) {
3556
+ return isDeepEqual2(a, b);
3557
+ }
3558
+ getName() {
3559
+ return "DeepSet";
3096
3560
  }
3097
3561
  };
3098
3562
 
@@ -3154,11 +3618,11 @@ var MultiContainer = class {
3154
3618
  const entries = [];
3155
3619
  for (const keys of this.keys()) {
3156
3620
  const arr = this.getAll(...keys);
3157
- const keyStr = Array.isArray(keys) ? `[${keys.map((k) => JSON.stringify(k)).join(", ")}]` : `[${JSON.stringify(keys)}]`;
3158
- const valuesStr = Array.isArray(arr) ? `[${arr.map((v) => JSON.stringify(v)).join(", ")}]` : "[]";
3621
+ const keyStr = Array.isArray(keys) ? formatValue(keys) : "[ ]";
3622
+ const valuesStr = Array.isArray(arr) ? formatValue(arr) : "[ ]";
3159
3623
  entries.push(`${keyStr} => ${valuesStr}`);
3160
3624
  }
3161
- return `MultiContainer{ ${entries.join(", ")} }`;
3625
+ return `MultiContainer{ ${entries.join(", ")} }`.replaceAll(" ", " ");
3162
3626
  }
3163
3627
  };
3164
3628
  function asMulti(base) {
@@ -3244,6 +3708,8 @@ var SmallIntCache = class {
3244
3708
  export {
3245
3709
  assert_exports as Assert,
3246
3710
  cookies_exports as Cookies,
3711
+ DeepSet,
3712
+ DefaultArray,
3247
3713
  device_exports as Device,
3248
3714
  DivRect,
3249
3715
  guard_exports as Guard,
@@ -3253,6 +3719,8 @@ export {
3253
3719
  Map2,
3254
3720
  Map3,
3255
3721
  MultiContainer,
3722
+ Set1,
3723
+ SetBase,
3256
3724
  SignedIndexArray,
3257
3725
  SmallIntCache,
3258
3726
  Stack,