@tspro/ts-utils-lib 1.15.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.16.0] - 2025-10-20
4
+ ### Added
5
+ - Add isEmpty() to interface and containers.
6
+ - Add more functions and iterators to MultiContainer.
7
+
3
8
  ## [1.15.0] - 2025-10-20
4
9
  ### Added
5
10
  - SignedIndexArray.equals()
package/dist/index.d.mts CHANGED
@@ -452,6 +452,7 @@ declare class SmallIntCache<V> {
452
452
 
453
453
  interface KVComponent<K extends any[], EL> {
454
454
  get size(): number;
455
+ isEmpty(): boolean;
455
456
  has(...keys: K): boolean;
456
457
  get(...keys: K): EL | undefined;
457
458
  getOrDefault(...keysAndDefault: [...K, EL]): EL;
@@ -460,6 +461,9 @@ interface KVComponent<K extends any[], EL> {
460
461
  delete(...keys: K): boolean;
461
462
  clear?(): void;
462
463
  toString(): string;
464
+ kvValues(): IterableIterator<EL>;
465
+ kvKeys(): IterableIterator<K>;
466
+ kvEntries(): IterableIterator<[K, EL]>;
463
467
  }
464
468
 
465
469
  /**
@@ -474,8 +478,9 @@ declare class IndexArray<EL> implements KVComponent<[number], EL> {
474
478
  constructor();
475
479
  constructor(arr: IndexArray<EL>);
476
480
  constructor(entries: Iterable<[number, EL]>);
477
- get size(): number;
478
481
  private get posLen();
482
+ get size(): number;
483
+ isEmpty(): boolean;
479
484
  has(id: number): boolean;
480
485
  set(id: number, el: EL): void;
481
486
  get(id: number): EL | undefined;
@@ -486,11 +491,14 @@ declare class IndexArray<EL> implements KVComponent<[number], EL> {
486
491
  clear(): void;
487
492
  forEach(callbackfn: (el: EL, id: number, arr: IndexArray<EL>) => void, thisArg?: any): void;
488
493
  indices(): IterableIterator<number>;
489
- indicesArray(): number[];
490
494
  values(): IterableIterator<EL>;
491
- valuesArray(): EL[];
492
495
  entries(): IterableIterator<[number, EL]>;
496
+ indicesArray(): number[];
497
+ valuesArray(): EL[];
493
498
  entriesArray(): [number, EL][];
499
+ kvKeys(): IterableIterator<[number]>;
500
+ kvValues(): IterableIterator<EL>;
501
+ kvEntries(): IterableIterator<[[number], EL]>;
494
502
  [Symbol.iterator](): Generator<[number, EL], void, any>;
495
503
  clone(): IndexArray<EL>;
496
504
  merge(other: IndexArray<EL>, conflictResolver?: (oldValue: EL, newValue: EL, id: number) => EL): this;
@@ -521,6 +529,7 @@ declare class SignedIndexArray<EL> implements KVComponent<[number], EL> {
521
529
  constructor(arr: SignedIndexArray<EL>);
522
530
  constructor(entries: Iterable<[number, EL]>);
523
531
  get size(): number;
532
+ isEmpty(): boolean;
524
533
  private get posLen();
525
534
  private get negLen();
526
535
  has(id: number): boolean;
@@ -533,11 +542,14 @@ declare class SignedIndexArray<EL> implements KVComponent<[number], EL> {
533
542
  clear(): void;
534
543
  forEach(callbackfn: (el: EL, id: number, arr: SignedIndexArray<EL>) => void, thisArg?: any): void;
535
544
  indices(): IterableIterator<number>;
536
- indicesArray(): number[];
537
545
  values(): IterableIterator<EL>;
538
- valuesArray(): EL[];
539
546
  entries(): IterableIterator<[number, EL]>;
547
+ indicesArray(): number[];
548
+ valuesArray(): EL[];
540
549
  entriesArray(): [number, EL][];
550
+ kvKeys(): IterableIterator<[number]>;
551
+ kvValues(): IterableIterator<EL>;
552
+ kvEntries(): IterableIterator<[[number], EL]>;
541
553
  [Symbol.iterator](): Generator<[number, EL], void, any>;
542
554
  clone(): SignedIndexArray<EL>;
543
555
  merge(other: SignedIndexArray<EL>, conflictResolver?: (oldValue: EL, newValue: EL, id: number) => EL): this;
@@ -567,13 +579,17 @@ declare class Map1<KEY1, VALUE> implements KVComponent<[KEY1], VALUE> {
567
579
  delete(key1: KEY1): boolean;
568
580
  clear(): void;
569
581
  get size(): number;
582
+ isEmpty(): boolean;
570
583
  forEach(callbackfn: (value: VALUE, key1: KEY1, map1: Map1<KEY1, VALUE>) => void, thisArg?: any): void;
571
584
  keys(): IterableIterator<KEY1>;
572
- keysArray(): KEY1[];
573
585
  values(): IterableIterator<VALUE>;
574
- valuesArray(): VALUE[];
575
586
  entries(): IterableIterator<[KEY1, VALUE]>;
587
+ keysArray(): KEY1[];
588
+ valuesArray(): VALUE[];
576
589
  entriesArray(): [KEY1, VALUE][];
590
+ kvKeys(): IterableIterator<[KEY1]>;
591
+ kvValues(): IterableIterator<VALUE>;
592
+ kvEntries(): IterableIterator<[[KEY1], VALUE]>;
577
593
  [Symbol.iterator](): Generator<[KEY1, VALUE], void, any>;
578
594
  clone(): Map1<KEY1, VALUE>;
579
595
  merge(other: Map1<KEY1, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1) => VALUE): this;
@@ -601,13 +617,17 @@ declare class Map2<KEY1, KEY2, VALUE> implements KVComponent<[KEY1, KEY2], VALUE
601
617
  delete(key1: KEY1, key2: KEY2): boolean;
602
618
  clear(): void;
603
619
  get size(): number;
620
+ isEmpty(): boolean;
604
621
  forEach(callbackfn: (value: VALUE, key1: KEY1, key2: KEY2, map2: Map2<KEY1, KEY2, VALUE>) => void, thisArg?: any): void;
605
622
  keys(): IterableIterator<[KEY1, KEY2]>;
606
- keysArray(): [KEY1, KEY2][];
607
623
  values(): IterableIterator<VALUE>;
608
- valuesArray(): VALUE[];
609
624
  entries(): IterableIterator<[KEY1, KEY2, VALUE]>;
625
+ keysArray(): [KEY1, KEY2][];
626
+ valuesArray(): VALUE[];
610
627
  entriesArray(): [KEY1, KEY2, VALUE][];
628
+ kvKeys(): IterableIterator<[KEY1, KEY2]>;
629
+ kvValues(): IterableIterator<VALUE>;
630
+ kvEntries(): IterableIterator<[[KEY1, KEY2], VALUE]>;
611
631
  [Symbol.iterator](): Generator<[KEY1, KEY2, VALUE], void, any>;
612
632
  clone(): Map2<KEY1, KEY2, VALUE>;
613
633
  merge(other: Map2<KEY1, KEY2, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2) => VALUE): this;
@@ -636,13 +656,17 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
636
656
  delete(key1: KEY1, key2: KEY2, key3: KEY3): boolean;
637
657
  clear(): void;
638
658
  get size(): number;
659
+ isEmpty(): boolean;
639
660
  forEach(callbackfn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3, map2: Map3<KEY1, KEY2, KEY3, VALUE>) => void, thisArg?: any): void;
640
661
  keys(): IterableIterator<[KEY1, KEY2, KEY3]>;
641
- keysArray(): [KEY1, KEY2, KEY3][];
642
662
  values(): IterableIterator<VALUE>;
643
- valuesArray(): VALUE[];
644
663
  entries(): IterableIterator<[KEY1, KEY2, KEY3, VALUE]>;
664
+ keysArray(): [KEY1, KEY2, KEY3][];
665
+ valuesArray(): VALUE[];
645
666
  entriesArray(): [KEY1, KEY2, KEY3, VALUE][];
667
+ kvKeys(): IterableIterator<[KEY1, KEY2, KEY3]>;
668
+ kvValues(): IterableIterator<VALUE>;
669
+ kvEntries(): IterableIterator<[[KEY1, KEY2, KEY3], VALUE]>;
646
670
  [Symbol.iterator](): Generator<[KEY1, KEY2, KEY3, VALUE], void, any>;
647
671
  clone(): Map3<KEY1, KEY2, KEY3, VALUE>;
648
672
  merge(other: Map3<KEY1, KEY2, KEY3, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => VALUE): this;
@@ -659,11 +683,17 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
659
683
  declare class MultiContainer<K extends any[], V> {
660
684
  private readonly base;
661
685
  constructor(base: KVComponent<K, V[]>);
686
+ isEmpty(): boolean;
687
+ clear(): void;
662
688
  add(...keysAndValue: [...K, V]): V;
663
689
  remove(...keysAndValue: [...K, V]): boolean;
664
690
  getAll(...keys: K): V[];
665
691
  iterAll(...keys: K): IterableIterator<V>;
666
- clear(): void;
692
+ values(): IterableIterator<V>;
693
+ keys(): IterableIterator<K>;
694
+ entries(): IterableIterator<[K, V[]]>;
695
+ [Symbol.iterator](): IterableIterator<[K, V[]]>;
696
+ toString(): string;
667
697
  }
668
698
  /**
669
699
  * ```ts
package/dist/index.d.ts CHANGED
@@ -452,6 +452,7 @@ declare class SmallIntCache<V> {
452
452
 
453
453
  interface KVComponent<K extends any[], EL> {
454
454
  get size(): number;
455
+ isEmpty(): boolean;
455
456
  has(...keys: K): boolean;
456
457
  get(...keys: K): EL | undefined;
457
458
  getOrDefault(...keysAndDefault: [...K, EL]): EL;
@@ -460,6 +461,9 @@ interface KVComponent<K extends any[], EL> {
460
461
  delete(...keys: K): boolean;
461
462
  clear?(): void;
462
463
  toString(): string;
464
+ kvValues(): IterableIterator<EL>;
465
+ kvKeys(): IterableIterator<K>;
466
+ kvEntries(): IterableIterator<[K, EL]>;
463
467
  }
464
468
 
465
469
  /**
@@ -474,8 +478,9 @@ declare class IndexArray<EL> implements KVComponent<[number], EL> {
474
478
  constructor();
475
479
  constructor(arr: IndexArray<EL>);
476
480
  constructor(entries: Iterable<[number, EL]>);
477
- get size(): number;
478
481
  private get posLen();
482
+ get size(): number;
483
+ isEmpty(): boolean;
479
484
  has(id: number): boolean;
480
485
  set(id: number, el: EL): void;
481
486
  get(id: number): EL | undefined;
@@ -486,11 +491,14 @@ declare class IndexArray<EL> implements KVComponent<[number], EL> {
486
491
  clear(): void;
487
492
  forEach(callbackfn: (el: EL, id: number, arr: IndexArray<EL>) => void, thisArg?: any): void;
488
493
  indices(): IterableIterator<number>;
489
- indicesArray(): number[];
490
494
  values(): IterableIterator<EL>;
491
- valuesArray(): EL[];
492
495
  entries(): IterableIterator<[number, EL]>;
496
+ indicesArray(): number[];
497
+ valuesArray(): EL[];
493
498
  entriesArray(): [number, EL][];
499
+ kvKeys(): IterableIterator<[number]>;
500
+ kvValues(): IterableIterator<EL>;
501
+ kvEntries(): IterableIterator<[[number], EL]>;
494
502
  [Symbol.iterator](): Generator<[number, EL], void, any>;
495
503
  clone(): IndexArray<EL>;
496
504
  merge(other: IndexArray<EL>, conflictResolver?: (oldValue: EL, newValue: EL, id: number) => EL): this;
@@ -521,6 +529,7 @@ declare class SignedIndexArray<EL> implements KVComponent<[number], EL> {
521
529
  constructor(arr: SignedIndexArray<EL>);
522
530
  constructor(entries: Iterable<[number, EL]>);
523
531
  get size(): number;
532
+ isEmpty(): boolean;
524
533
  private get posLen();
525
534
  private get negLen();
526
535
  has(id: number): boolean;
@@ -533,11 +542,14 @@ declare class SignedIndexArray<EL> implements KVComponent<[number], EL> {
533
542
  clear(): void;
534
543
  forEach(callbackfn: (el: EL, id: number, arr: SignedIndexArray<EL>) => void, thisArg?: any): void;
535
544
  indices(): IterableIterator<number>;
536
- indicesArray(): number[];
537
545
  values(): IterableIterator<EL>;
538
- valuesArray(): EL[];
539
546
  entries(): IterableIterator<[number, EL]>;
547
+ indicesArray(): number[];
548
+ valuesArray(): EL[];
540
549
  entriesArray(): [number, EL][];
550
+ kvKeys(): IterableIterator<[number]>;
551
+ kvValues(): IterableIterator<EL>;
552
+ kvEntries(): IterableIterator<[[number], EL]>;
541
553
  [Symbol.iterator](): Generator<[number, EL], void, any>;
542
554
  clone(): SignedIndexArray<EL>;
543
555
  merge(other: SignedIndexArray<EL>, conflictResolver?: (oldValue: EL, newValue: EL, id: number) => EL): this;
@@ -567,13 +579,17 @@ declare class Map1<KEY1, VALUE> implements KVComponent<[KEY1], VALUE> {
567
579
  delete(key1: KEY1): boolean;
568
580
  clear(): void;
569
581
  get size(): number;
582
+ isEmpty(): boolean;
570
583
  forEach(callbackfn: (value: VALUE, key1: KEY1, map1: Map1<KEY1, VALUE>) => void, thisArg?: any): void;
571
584
  keys(): IterableIterator<KEY1>;
572
- keysArray(): KEY1[];
573
585
  values(): IterableIterator<VALUE>;
574
- valuesArray(): VALUE[];
575
586
  entries(): IterableIterator<[KEY1, VALUE]>;
587
+ keysArray(): KEY1[];
588
+ valuesArray(): VALUE[];
576
589
  entriesArray(): [KEY1, VALUE][];
590
+ kvKeys(): IterableIterator<[KEY1]>;
591
+ kvValues(): IterableIterator<VALUE>;
592
+ kvEntries(): IterableIterator<[[KEY1], VALUE]>;
577
593
  [Symbol.iterator](): Generator<[KEY1, VALUE], void, any>;
578
594
  clone(): Map1<KEY1, VALUE>;
579
595
  merge(other: Map1<KEY1, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1) => VALUE): this;
@@ -601,13 +617,17 @@ declare class Map2<KEY1, KEY2, VALUE> implements KVComponent<[KEY1, KEY2], VALUE
601
617
  delete(key1: KEY1, key2: KEY2): boolean;
602
618
  clear(): void;
603
619
  get size(): number;
620
+ isEmpty(): boolean;
604
621
  forEach(callbackfn: (value: VALUE, key1: KEY1, key2: KEY2, map2: Map2<KEY1, KEY2, VALUE>) => void, thisArg?: any): void;
605
622
  keys(): IterableIterator<[KEY1, KEY2]>;
606
- keysArray(): [KEY1, KEY2][];
607
623
  values(): IterableIterator<VALUE>;
608
- valuesArray(): VALUE[];
609
624
  entries(): IterableIterator<[KEY1, KEY2, VALUE]>;
625
+ keysArray(): [KEY1, KEY2][];
626
+ valuesArray(): VALUE[];
610
627
  entriesArray(): [KEY1, KEY2, VALUE][];
628
+ kvKeys(): IterableIterator<[KEY1, KEY2]>;
629
+ kvValues(): IterableIterator<VALUE>;
630
+ kvEntries(): IterableIterator<[[KEY1, KEY2], VALUE]>;
611
631
  [Symbol.iterator](): Generator<[KEY1, KEY2, VALUE], void, any>;
612
632
  clone(): Map2<KEY1, KEY2, VALUE>;
613
633
  merge(other: Map2<KEY1, KEY2, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2) => VALUE): this;
@@ -636,13 +656,17 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
636
656
  delete(key1: KEY1, key2: KEY2, key3: KEY3): boolean;
637
657
  clear(): void;
638
658
  get size(): number;
659
+ isEmpty(): boolean;
639
660
  forEach(callbackfn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3, map2: Map3<KEY1, KEY2, KEY3, VALUE>) => void, thisArg?: any): void;
640
661
  keys(): IterableIterator<[KEY1, KEY2, KEY3]>;
641
- keysArray(): [KEY1, KEY2, KEY3][];
642
662
  values(): IterableIterator<VALUE>;
643
- valuesArray(): VALUE[];
644
663
  entries(): IterableIterator<[KEY1, KEY2, KEY3, VALUE]>;
664
+ keysArray(): [KEY1, KEY2, KEY3][];
665
+ valuesArray(): VALUE[];
645
666
  entriesArray(): [KEY1, KEY2, KEY3, VALUE][];
667
+ kvKeys(): IterableIterator<[KEY1, KEY2, KEY3]>;
668
+ kvValues(): IterableIterator<VALUE>;
669
+ kvEntries(): IterableIterator<[[KEY1, KEY2, KEY3], VALUE]>;
646
670
  [Symbol.iterator](): Generator<[KEY1, KEY2, KEY3, VALUE], void, any>;
647
671
  clone(): Map3<KEY1, KEY2, KEY3, VALUE>;
648
672
  merge(other: Map3<KEY1, KEY2, KEY3, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => VALUE): this;
@@ -659,11 +683,17 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
659
683
  declare class MultiContainer<K extends any[], V> {
660
684
  private readonly base;
661
685
  constructor(base: KVComponent<K, V[]>);
686
+ isEmpty(): boolean;
687
+ clear(): void;
662
688
  add(...keysAndValue: [...K, V]): V;
663
689
  remove(...keysAndValue: [...K, V]): boolean;
664
690
  getAll(...keys: K): V[];
665
691
  iterAll(...keys: K): IterableIterator<V>;
666
- clear(): void;
692
+ values(): IterableIterator<V>;
693
+ keys(): IterableIterator<K>;
694
+ entries(): IterableIterator<[K, V[]]>;
695
+ [Symbol.iterator](): IterableIterator<[K, V[]]>;
696
+ toString(): string;
667
697
  }
668
698
  /**
669
699
  * ```ts
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.15.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.16.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
2
2
  "use strict";
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1321,11 +1321,14 @@ var IndexArray = class _IndexArray {
1321
1321
  if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
1322
1322
  return id;
1323
1323
  }
1324
+ get posLen() {
1325
+ return this.hasPos.length;
1326
+ }
1324
1327
  get size() {
1325
1328
  return this.elCount;
1326
1329
  }
1327
- get posLen() {
1328
- return this.hasPos.length;
1330
+ isEmpty() {
1331
+ return this.size === 0;
1329
1332
  }
1330
1333
  has(id) {
1331
1334
  _IndexArray.validateIndex(id);
@@ -1375,25 +1378,40 @@ var IndexArray = class _IndexArray {
1375
1378
  if (this.hasPos[id]) yield id;
1376
1379
  }
1377
1380
  }
1378
- indicesArray() {
1379
- return [...this.indices()];
1380
- }
1381
1381
  *values() {
1382
1382
  for (let id = 0; id < this.posLen; id++) {
1383
1383
  if (this.hasPos[id]) yield this.posEl[id];
1384
1384
  }
1385
1385
  }
1386
- valuesArray() {
1387
- return [...this.values()];
1388
- }
1389
1386
  *entries() {
1390
1387
  for (let id = 0; id < this.posLen; id++) {
1391
1388
  if (this.hasPos[id]) yield [id, this.posEl[id]];
1392
1389
  }
1393
1390
  }
1391
+ indicesArray() {
1392
+ return [...this.indices()];
1393
+ }
1394
+ valuesArray() {
1395
+ return [...this.values()];
1396
+ }
1394
1397
  entriesArray() {
1395
1398
  return [...this.entries()];
1396
1399
  }
1400
+ *kvKeys() {
1401
+ for (const id of this.indices()) {
1402
+ yield [id];
1403
+ }
1404
+ }
1405
+ *kvValues() {
1406
+ for (const el of this.values()) {
1407
+ yield el;
1408
+ }
1409
+ }
1410
+ *kvEntries() {
1411
+ for (const [id, el] of this.entries()) {
1412
+ yield [[id], el];
1413
+ }
1414
+ }
1397
1415
  *[Symbol.iterator]() {
1398
1416
  yield* this.entries();
1399
1417
  }
@@ -1526,6 +1544,9 @@ var SignedIndexArray = class _SignedIndexArray {
1526
1544
  get size() {
1527
1545
  return this.elCount;
1528
1546
  }
1547
+ isEmpty() {
1548
+ return this.size === 0;
1549
+ }
1529
1550
  get posLen() {
1530
1551
  return this.hasPos.length;
1531
1552
  }
@@ -1605,9 +1626,6 @@ var SignedIndexArray = class _SignedIndexArray {
1605
1626
  if (this.hasPos[id]) yield id;
1606
1627
  }
1607
1628
  }
1608
- indicesArray() {
1609
- return [...this.indices()];
1610
- }
1611
1629
  *values() {
1612
1630
  for (let id = this.negLen - 1; id >= 0; id--) {
1613
1631
  if (this.hasNeg[id]) yield this.negEl[id];
@@ -1616,9 +1634,6 @@ var SignedIndexArray = class _SignedIndexArray {
1616
1634
  if (this.hasPos[id]) yield this.posEl[id];
1617
1635
  }
1618
1636
  }
1619
- valuesArray() {
1620
- return [...this.values()];
1621
- }
1622
1637
  *entries() {
1623
1638
  for (let id = this.negLen - 1; id >= 0; id--) {
1624
1639
  if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negEl[id]];
@@ -1627,9 +1642,30 @@ var SignedIndexArray = class _SignedIndexArray {
1627
1642
  if (this.hasPos[id]) yield [id, this.posEl[id]];
1628
1643
  }
1629
1644
  }
1645
+ indicesArray() {
1646
+ return [...this.indices()];
1647
+ }
1648
+ valuesArray() {
1649
+ return [...this.values()];
1650
+ }
1630
1651
  entriesArray() {
1631
1652
  return [...this.entries()];
1632
1653
  }
1654
+ *kvKeys() {
1655
+ for (const id of this.indices()) {
1656
+ yield [id];
1657
+ }
1658
+ }
1659
+ *kvValues() {
1660
+ for (const el of this.values()) {
1661
+ yield el;
1662
+ }
1663
+ }
1664
+ *kvEntries() {
1665
+ for (const [id, el] of this.entries()) {
1666
+ yield [[id], el];
1667
+ }
1668
+ }
1633
1669
  *[Symbol.iterator]() {
1634
1670
  yield* this.entries();
1635
1671
  }
@@ -1765,28 +1801,46 @@ var Map1 = class _Map1 {
1765
1801
  get size() {
1766
1802
  return this.map1.size;
1767
1803
  }
1804
+ isEmpty() {
1805
+ return this.size === 0;
1806
+ }
1768
1807
  forEach(callbackfn, thisArg) {
1769
1808
  this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
1770
1809
  }
1771
- keys() {
1772
- return this.map1.keys();
1810
+ *keys() {
1811
+ yield* this.map1.keys();
1812
+ }
1813
+ *values() {
1814
+ yield* this.map1.values();
1815
+ }
1816
+ *entries() {
1817
+ for (const [key1, value] of this.map1)
1818
+ yield [key1, value];
1773
1819
  }
1774
1820
  keysArray() {
1775
1821
  return [...this.keys()];
1776
1822
  }
1777
- values() {
1778
- return this.map1.values();
1779
- }
1780
1823
  valuesArray() {
1781
1824
  return [...this.values()];
1782
1825
  }
1783
- *entries() {
1784
- for (const [key1, value] of this.map1)
1785
- yield [key1, value];
1786
- }
1787
1826
  entriesArray() {
1788
1827
  return [...this.entries()];
1789
1828
  }
1829
+ *kvKeys() {
1830
+ for (const key of this.keys()) {
1831
+ yield [key];
1832
+ }
1833
+ }
1834
+ *kvValues() {
1835
+ for (const el of this.values()) {
1836
+ yield el;
1837
+ }
1838
+ }
1839
+ *kvEntries() {
1840
+ for (const [key, el] of this.entries()) {
1841
+ yield [[key], el];
1842
+ }
1843
+ }
1790
1844
  *[Symbol.iterator]() {
1791
1845
  yield* this.entries();
1792
1846
  }
@@ -1902,39 +1956,48 @@ var Map2 = class _Map2 {
1902
1956
  }
1903
1957
  return count;
1904
1958
  }
1959
+ isEmpty() {
1960
+ return this.size === 0;
1961
+ }
1905
1962
  forEach(callbackfn, thisArg) {
1906
1963
  this.map1.forEach((map2, key1) => map2.forEach((value, key2) => callbackfn.call(thisArg, value, key1, key2, this)));
1907
1964
  }
1908
- keys() {
1909
- function* gen(map1) {
1910
- for (const [key1, map2] of map1)
1911
- for (const key2 of map2.keys())
1912
- yield [key1, key2];
1913
- }
1914
- return gen(this.map1);
1915
- }
1916
- keysArray() {
1917
- return [...this.keys()];
1918
- }
1919
- values() {
1920
- function* gen(map1) {
1921
- for (const map2 of map1.values())
1922
- for (const value of map2.values())
1923
- yield value;
1924
- }
1925
- return gen(this.map1);
1965
+ *keys() {
1966
+ for (const [key1, map2] of this.map1)
1967
+ for (const key2 of map2.keys())
1968
+ yield [key1, key2];
1926
1969
  }
1927
- valuesArray() {
1928
- return [...this.values()];
1970
+ *values() {
1971
+ for (const map2 of this.map1.values())
1972
+ for (const value of map2.values())
1973
+ yield value;
1929
1974
  }
1930
1975
  *entries() {
1931
1976
  for (const [key1, map2] of this.map1)
1932
1977
  for (const [key2, value] of map2)
1933
1978
  yield [key1, key2, value];
1934
1979
  }
1980
+ keysArray() {
1981
+ return [...this.keys()];
1982
+ }
1983
+ valuesArray() {
1984
+ return [...this.values()];
1985
+ }
1935
1986
  entriesArray() {
1936
1987
  return [...this.entries()];
1937
1988
  }
1989
+ *kvKeys() {
1990
+ for (const [key1, key2] of this.keys())
1991
+ yield [key1, key2];
1992
+ }
1993
+ *kvValues() {
1994
+ for (const el of this.values())
1995
+ yield el;
1996
+ }
1997
+ *kvEntries() {
1998
+ for (const [key1, key2, el] of this.entries())
1999
+ yield [[key1, key2], el];
2000
+ }
1938
2001
  *[Symbol.iterator]() {
1939
2002
  yield* this.entries();
1940
2003
  }
@@ -2088,32 +2151,23 @@ var Map3 = class _Map3 {
2088
2151
  }
2089
2152
  return count;
2090
2153
  }
2154
+ isEmpty() {
2155
+ return this.size === 0;
2156
+ }
2091
2157
  forEach(callbackfn, thisArg) {
2092
2158
  this.map1.forEach((map2, key1) => map2.forEach((map3, key2) => map3.forEach((value, key3) => callbackfn.call(thisArg, value, key1, key2, key3, this))));
2093
2159
  }
2094
- keys() {
2095
- function* gen(map1) {
2096
- for (const [key1, map2] of map1)
2097
- for (const [key2, map3] of map2)
2098
- for (const key3 of map3.keys())
2099
- yield [key1, key2, key3];
2100
- }
2101
- return gen(this.map1);
2102
- }
2103
- keysArray() {
2104
- return [...this.keys()];
2105
- }
2106
- values() {
2107
- function* gen(map1) {
2108
- for (const map2 of map1.values())
2109
- for (const map3 of map2.values())
2110
- for (const value of map3.values())
2111
- yield value;
2112
- }
2113
- return gen(this.map1);
2160
+ *keys() {
2161
+ for (const [key1, map2] of this.map1)
2162
+ for (const [key2, map3] of map2)
2163
+ for (const key3 of map3.keys())
2164
+ yield [key1, key2, key3];
2114
2165
  }
2115
- valuesArray() {
2116
- return [...this.values()];
2166
+ *values() {
2167
+ for (const map2 of this.map1.values())
2168
+ for (const map3 of map2.values())
2169
+ for (const value of map3.values())
2170
+ yield value;
2117
2171
  }
2118
2172
  *entries() {
2119
2173
  for (const [key1, map2] of this.map1)
@@ -2121,9 +2175,27 @@ var Map3 = class _Map3 {
2121
2175
  for (const [key3, value] of map3)
2122
2176
  yield [key1, key2, key3, value];
2123
2177
  }
2178
+ keysArray() {
2179
+ return [...this.keys()];
2180
+ }
2181
+ valuesArray() {
2182
+ return [...this.values()];
2183
+ }
2124
2184
  entriesArray() {
2125
2185
  return [...this.entries()];
2126
2186
  }
2187
+ *kvKeys() {
2188
+ for (const [key1, key2, key3] of this.keys())
2189
+ yield [key1, key2, key3];
2190
+ }
2191
+ *kvValues() {
2192
+ for (const el of this.values())
2193
+ yield el;
2194
+ }
2195
+ *kvEntries() {
2196
+ for (const [key1, key2, key3, el] of this.entries())
2197
+ yield [[key1, key2, key3], el];
2198
+ }
2127
2199
  *[Symbol.iterator]() {
2128
2200
  yield* this.entries();
2129
2201
  }
@@ -2232,6 +2304,12 @@ var MultiContainer = class {
2232
2304
  constructor(base) {
2233
2305
  this.base = base;
2234
2306
  }
2307
+ isEmpty() {
2308
+ return this.base.isEmpty();
2309
+ }
2310
+ clear() {
2311
+ this.base.clear?.();
2312
+ }
2235
2313
  add(...keysAndValue) {
2236
2314
  const keys = keysAndValue.slice(0, -1);
2237
2315
  const value = keysAndValue[keysAndValue.length - 1];
@@ -2254,13 +2332,36 @@ var MultiContainer = class {
2254
2332
  return this.base.get(...keys) ?? [];
2255
2333
  }
2256
2334
  *iterAll(...keys) {
2257
- const arr = this.getAll(...keys);
2258
- for (const v of arr) {
2259
- yield v;
2335
+ yield* this.getAll(...keys);
2336
+ }
2337
+ *values() {
2338
+ for (const keys of this.keys()) {
2339
+ yield* this.getAll(...keys);
2260
2340
  }
2261
2341
  }
2262
- clear() {
2263
- this.base.clear?.();
2342
+ *keys() {
2343
+ for (const keys of this.base.kvKeys()) {
2344
+ yield keys;
2345
+ }
2346
+ }
2347
+ *entries() {
2348
+ for (const keys of this.keys()) {
2349
+ const arr = this.getAll(...keys);
2350
+ if (arr.length > 0) yield [keys, arr];
2351
+ }
2352
+ }
2353
+ [Symbol.iterator]() {
2354
+ return this.entries();
2355
+ }
2356
+ toString() {
2357
+ const entries = [];
2358
+ for (const keys of this.keys()) {
2359
+ const arr = this.getAll(...keys);
2360
+ const keyStr = Array.isArray(keys) ? `[${keys.map((k) => JSON.stringify(k)).join(", ")}]` : `[${JSON.stringify(keys)}]`;
2361
+ const valuesStr = Array.isArray(arr) ? `[${arr.map((v) => JSON.stringify(v)).join(", ")}]` : "[]";
2362
+ entries.push(`${keyStr} => ${valuesStr}`);
2363
+ }
2364
+ return `MultiContainer{ ${entries.join(", ")} }`;
2264
2365
  }
2265
2366
  };
2266
2367
  function asMulti(base) {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /* TsUtilsLib v1.15.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
1
+ /* TsUtilsLib v1.16.0 | (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) => {
@@ -1287,11 +1287,14 @@ var IndexArray = class _IndexArray {
1287
1287
  if (!isIntegerGte(id, 0)) throw new Error(`Invalid index ${id} - must be an integer >= 0!`);
1288
1288
  return id;
1289
1289
  }
1290
+ get posLen() {
1291
+ return this.hasPos.length;
1292
+ }
1290
1293
  get size() {
1291
1294
  return this.elCount;
1292
1295
  }
1293
- get posLen() {
1294
- return this.hasPos.length;
1296
+ isEmpty() {
1297
+ return this.size === 0;
1295
1298
  }
1296
1299
  has(id) {
1297
1300
  _IndexArray.validateIndex(id);
@@ -1341,25 +1344,40 @@ var IndexArray = class _IndexArray {
1341
1344
  if (this.hasPos[id]) yield id;
1342
1345
  }
1343
1346
  }
1344
- indicesArray() {
1345
- return [...this.indices()];
1346
- }
1347
1347
  *values() {
1348
1348
  for (let id = 0; id < this.posLen; id++) {
1349
1349
  if (this.hasPos[id]) yield this.posEl[id];
1350
1350
  }
1351
1351
  }
1352
- valuesArray() {
1353
- return [...this.values()];
1354
- }
1355
1352
  *entries() {
1356
1353
  for (let id = 0; id < this.posLen; id++) {
1357
1354
  if (this.hasPos[id]) yield [id, this.posEl[id]];
1358
1355
  }
1359
1356
  }
1357
+ indicesArray() {
1358
+ return [...this.indices()];
1359
+ }
1360
+ valuesArray() {
1361
+ return [...this.values()];
1362
+ }
1360
1363
  entriesArray() {
1361
1364
  return [...this.entries()];
1362
1365
  }
1366
+ *kvKeys() {
1367
+ for (const id of this.indices()) {
1368
+ yield [id];
1369
+ }
1370
+ }
1371
+ *kvValues() {
1372
+ for (const el of this.values()) {
1373
+ yield el;
1374
+ }
1375
+ }
1376
+ *kvEntries() {
1377
+ for (const [id, el] of this.entries()) {
1378
+ yield [[id], el];
1379
+ }
1380
+ }
1363
1381
  *[Symbol.iterator]() {
1364
1382
  yield* this.entries();
1365
1383
  }
@@ -1492,6 +1510,9 @@ var SignedIndexArray = class _SignedIndexArray {
1492
1510
  get size() {
1493
1511
  return this.elCount;
1494
1512
  }
1513
+ isEmpty() {
1514
+ return this.size === 0;
1515
+ }
1495
1516
  get posLen() {
1496
1517
  return this.hasPos.length;
1497
1518
  }
@@ -1571,9 +1592,6 @@ var SignedIndexArray = class _SignedIndexArray {
1571
1592
  if (this.hasPos[id]) yield id;
1572
1593
  }
1573
1594
  }
1574
- indicesArray() {
1575
- return [...this.indices()];
1576
- }
1577
1595
  *values() {
1578
1596
  for (let id = this.negLen - 1; id >= 0; id--) {
1579
1597
  if (this.hasNeg[id]) yield this.negEl[id];
@@ -1582,9 +1600,6 @@ var SignedIndexArray = class _SignedIndexArray {
1582
1600
  if (this.hasPos[id]) yield this.posEl[id];
1583
1601
  }
1584
1602
  }
1585
- valuesArray() {
1586
- return [...this.values()];
1587
- }
1588
1603
  *entries() {
1589
1604
  for (let id = this.negLen - 1; id >= 0; id--) {
1590
1605
  if (this.hasNeg[id]) yield [_SignedIndexArray.toNegIndex(id), this.negEl[id]];
@@ -1593,9 +1608,30 @@ var SignedIndexArray = class _SignedIndexArray {
1593
1608
  if (this.hasPos[id]) yield [id, this.posEl[id]];
1594
1609
  }
1595
1610
  }
1611
+ indicesArray() {
1612
+ return [...this.indices()];
1613
+ }
1614
+ valuesArray() {
1615
+ return [...this.values()];
1616
+ }
1596
1617
  entriesArray() {
1597
1618
  return [...this.entries()];
1598
1619
  }
1620
+ *kvKeys() {
1621
+ for (const id of this.indices()) {
1622
+ yield [id];
1623
+ }
1624
+ }
1625
+ *kvValues() {
1626
+ for (const el of this.values()) {
1627
+ yield el;
1628
+ }
1629
+ }
1630
+ *kvEntries() {
1631
+ for (const [id, el] of this.entries()) {
1632
+ yield [[id], el];
1633
+ }
1634
+ }
1599
1635
  *[Symbol.iterator]() {
1600
1636
  yield* this.entries();
1601
1637
  }
@@ -1731,28 +1767,46 @@ var Map1 = class _Map1 {
1731
1767
  get size() {
1732
1768
  return this.map1.size;
1733
1769
  }
1770
+ isEmpty() {
1771
+ return this.size === 0;
1772
+ }
1734
1773
  forEach(callbackfn, thisArg) {
1735
1774
  this.map1.forEach((value, key1) => callbackfn.call(thisArg, value, key1, this));
1736
1775
  }
1737
- keys() {
1738
- return this.map1.keys();
1776
+ *keys() {
1777
+ yield* this.map1.keys();
1778
+ }
1779
+ *values() {
1780
+ yield* this.map1.values();
1781
+ }
1782
+ *entries() {
1783
+ for (const [key1, value] of this.map1)
1784
+ yield [key1, value];
1739
1785
  }
1740
1786
  keysArray() {
1741
1787
  return [...this.keys()];
1742
1788
  }
1743
- values() {
1744
- return this.map1.values();
1745
- }
1746
1789
  valuesArray() {
1747
1790
  return [...this.values()];
1748
1791
  }
1749
- *entries() {
1750
- for (const [key1, value] of this.map1)
1751
- yield [key1, value];
1752
- }
1753
1792
  entriesArray() {
1754
1793
  return [...this.entries()];
1755
1794
  }
1795
+ *kvKeys() {
1796
+ for (const key of this.keys()) {
1797
+ yield [key];
1798
+ }
1799
+ }
1800
+ *kvValues() {
1801
+ for (const el of this.values()) {
1802
+ yield el;
1803
+ }
1804
+ }
1805
+ *kvEntries() {
1806
+ for (const [key, el] of this.entries()) {
1807
+ yield [[key], el];
1808
+ }
1809
+ }
1756
1810
  *[Symbol.iterator]() {
1757
1811
  yield* this.entries();
1758
1812
  }
@@ -1868,39 +1922,48 @@ var Map2 = class _Map2 {
1868
1922
  }
1869
1923
  return count;
1870
1924
  }
1925
+ isEmpty() {
1926
+ return this.size === 0;
1927
+ }
1871
1928
  forEach(callbackfn, thisArg) {
1872
1929
  this.map1.forEach((map2, key1) => map2.forEach((value, key2) => callbackfn.call(thisArg, value, key1, key2, this)));
1873
1930
  }
1874
- keys() {
1875
- function* gen(map1) {
1876
- for (const [key1, map2] of map1)
1877
- for (const key2 of map2.keys())
1878
- yield [key1, key2];
1879
- }
1880
- return gen(this.map1);
1881
- }
1882
- keysArray() {
1883
- return [...this.keys()];
1884
- }
1885
- values() {
1886
- function* gen(map1) {
1887
- for (const map2 of map1.values())
1888
- for (const value of map2.values())
1889
- yield value;
1890
- }
1891
- return gen(this.map1);
1931
+ *keys() {
1932
+ for (const [key1, map2] of this.map1)
1933
+ for (const key2 of map2.keys())
1934
+ yield [key1, key2];
1892
1935
  }
1893
- valuesArray() {
1894
- return [...this.values()];
1936
+ *values() {
1937
+ for (const map2 of this.map1.values())
1938
+ for (const value of map2.values())
1939
+ yield value;
1895
1940
  }
1896
1941
  *entries() {
1897
1942
  for (const [key1, map2] of this.map1)
1898
1943
  for (const [key2, value] of map2)
1899
1944
  yield [key1, key2, value];
1900
1945
  }
1946
+ keysArray() {
1947
+ return [...this.keys()];
1948
+ }
1949
+ valuesArray() {
1950
+ return [...this.values()];
1951
+ }
1901
1952
  entriesArray() {
1902
1953
  return [...this.entries()];
1903
1954
  }
1955
+ *kvKeys() {
1956
+ for (const [key1, key2] of this.keys())
1957
+ yield [key1, key2];
1958
+ }
1959
+ *kvValues() {
1960
+ for (const el of this.values())
1961
+ yield el;
1962
+ }
1963
+ *kvEntries() {
1964
+ for (const [key1, key2, el] of this.entries())
1965
+ yield [[key1, key2], el];
1966
+ }
1904
1967
  *[Symbol.iterator]() {
1905
1968
  yield* this.entries();
1906
1969
  }
@@ -2054,32 +2117,23 @@ var Map3 = class _Map3 {
2054
2117
  }
2055
2118
  return count;
2056
2119
  }
2120
+ isEmpty() {
2121
+ return this.size === 0;
2122
+ }
2057
2123
  forEach(callbackfn, thisArg) {
2058
2124
  this.map1.forEach((map2, key1) => map2.forEach((map3, key2) => map3.forEach((value, key3) => callbackfn.call(thisArg, value, key1, key2, key3, this))));
2059
2125
  }
2060
- keys() {
2061
- function* gen(map1) {
2062
- for (const [key1, map2] of map1)
2063
- for (const [key2, map3] of map2)
2064
- for (const key3 of map3.keys())
2065
- yield [key1, key2, key3];
2066
- }
2067
- return gen(this.map1);
2068
- }
2069
- keysArray() {
2070
- return [...this.keys()];
2071
- }
2072
- values() {
2073
- function* gen(map1) {
2074
- for (const map2 of map1.values())
2075
- for (const map3 of map2.values())
2076
- for (const value of map3.values())
2077
- yield value;
2078
- }
2079
- return gen(this.map1);
2126
+ *keys() {
2127
+ for (const [key1, map2] of this.map1)
2128
+ for (const [key2, map3] of map2)
2129
+ for (const key3 of map3.keys())
2130
+ yield [key1, key2, key3];
2080
2131
  }
2081
- valuesArray() {
2082
- return [...this.values()];
2132
+ *values() {
2133
+ for (const map2 of this.map1.values())
2134
+ for (const map3 of map2.values())
2135
+ for (const value of map3.values())
2136
+ yield value;
2083
2137
  }
2084
2138
  *entries() {
2085
2139
  for (const [key1, map2] of this.map1)
@@ -2087,9 +2141,27 @@ var Map3 = class _Map3 {
2087
2141
  for (const [key3, value] of map3)
2088
2142
  yield [key1, key2, key3, value];
2089
2143
  }
2144
+ keysArray() {
2145
+ return [...this.keys()];
2146
+ }
2147
+ valuesArray() {
2148
+ return [...this.values()];
2149
+ }
2090
2150
  entriesArray() {
2091
2151
  return [...this.entries()];
2092
2152
  }
2153
+ *kvKeys() {
2154
+ for (const [key1, key2, key3] of this.keys())
2155
+ yield [key1, key2, key3];
2156
+ }
2157
+ *kvValues() {
2158
+ for (const el of this.values())
2159
+ yield el;
2160
+ }
2161
+ *kvEntries() {
2162
+ for (const [key1, key2, key3, el] of this.entries())
2163
+ yield [[key1, key2, key3], el];
2164
+ }
2093
2165
  *[Symbol.iterator]() {
2094
2166
  yield* this.entries();
2095
2167
  }
@@ -2198,6 +2270,12 @@ var MultiContainer = class {
2198
2270
  constructor(base) {
2199
2271
  this.base = base;
2200
2272
  }
2273
+ isEmpty() {
2274
+ return this.base.isEmpty();
2275
+ }
2276
+ clear() {
2277
+ this.base.clear?.();
2278
+ }
2201
2279
  add(...keysAndValue) {
2202
2280
  const keys = keysAndValue.slice(0, -1);
2203
2281
  const value = keysAndValue[keysAndValue.length - 1];
@@ -2220,13 +2298,36 @@ var MultiContainer = class {
2220
2298
  return this.base.get(...keys) ?? [];
2221
2299
  }
2222
2300
  *iterAll(...keys) {
2223
- const arr = this.getAll(...keys);
2224
- for (const v of arr) {
2225
- yield v;
2301
+ yield* this.getAll(...keys);
2302
+ }
2303
+ *values() {
2304
+ for (const keys of this.keys()) {
2305
+ yield* this.getAll(...keys);
2226
2306
  }
2227
2307
  }
2228
- clear() {
2229
- this.base.clear?.();
2308
+ *keys() {
2309
+ for (const keys of this.base.kvKeys()) {
2310
+ yield keys;
2311
+ }
2312
+ }
2313
+ *entries() {
2314
+ for (const keys of this.keys()) {
2315
+ const arr = this.getAll(...keys);
2316
+ if (arr.length > 0) yield [keys, arr];
2317
+ }
2318
+ }
2319
+ [Symbol.iterator]() {
2320
+ return this.entries();
2321
+ }
2322
+ toString() {
2323
+ const entries = [];
2324
+ for (const keys of this.keys()) {
2325
+ const arr = this.getAll(...keys);
2326
+ const keyStr = Array.isArray(keys) ? `[${keys.map((k) => JSON.stringify(k)).join(", ")}]` : `[${JSON.stringify(keys)}]`;
2327
+ const valuesStr = Array.isArray(arr) ? `[${arr.map((v) => JSON.stringify(v)).join(", ")}]` : "[]";
2328
+ entries.push(`${keyStr} => ${valuesStr}`);
2329
+ }
2330
+ return `MultiContainer{ ${entries.join(", ")} }`;
2230
2331
  }
2231
2332
  };
2232
2333
  function asMulti(base) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tspro/ts-utils-lib",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "author": "PahkaSoft",
5
5
  "license": "MIT",
6
6
  "private": false,