@tspro/ts-utils-lib 1.15.0 → 1.17.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 +16 -0
- package/dist/index.d.mts +418 -117
- package/dist/index.d.ts +418 -117
- package/dist/index.js +800 -257
- package/dist/index.mjs +798 -257
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -384,21 +384,267 @@ declare class Stack<T> {
|
|
|
384
384
|
clear(): void;
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
387
|
+
/**
|
|
388
|
+
* Vector class.
|
|
389
|
+
*
|
|
390
|
+
* ```ts
|
|
391
|
+
* // Example usage:
|
|
392
|
+
* const a = new Vec(1, 2);
|
|
393
|
+
* const b = new Vec(3, 4);
|
|
394
|
+
*
|
|
395
|
+
* console.log(a.add(b).toString()); // Vec(4, 6)
|
|
396
|
+
* console.log(a.add(3, 3).toString()); // Vec(4, 5)
|
|
397
|
+
* console.log(a.mul(2).toString()); // Vec(2, 4)
|
|
398
|
+
* console.log(a.equals(b)); // false
|
|
399
|
+
* console.log(a.clone().equals(a)); // true
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
declare class Vec {
|
|
403
|
+
readonly coords: number[];
|
|
404
|
+
constructor(...coords: number[]);
|
|
405
|
+
static vec2(x: number, y: number): Vec;
|
|
406
|
+
static vec3(x: number, y: number, z: number): Vec;
|
|
407
|
+
static zero(dim: number): Vec;
|
|
408
|
+
get length(): number;
|
|
409
|
+
get x(): number;
|
|
410
|
+
get y(): number;
|
|
411
|
+
get z(): number;
|
|
412
|
+
add(other: Vec): Vec;
|
|
413
|
+
add(...coords: number[]): Vec;
|
|
414
|
+
sub(other: Vec): Vec;
|
|
415
|
+
sub(...coords: number[]): Vec;
|
|
416
|
+
mul(scalar: number): Vec;
|
|
417
|
+
div(scalar: number): Vec;
|
|
418
|
+
dot(other: Vec): number;
|
|
419
|
+
distance(other: Vec): number;
|
|
420
|
+
normalize(): Vec;
|
|
421
|
+
equals(other: Vec): boolean;
|
|
422
|
+
clone(): Vec;
|
|
423
|
+
toObject(): {
|
|
424
|
+
x: number;
|
|
425
|
+
y: number;
|
|
426
|
+
z: number;
|
|
427
|
+
};
|
|
428
|
+
[Symbol.iterator](): ArrayIterator<number>;
|
|
429
|
+
toString(): string;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* DivRect class, left, top, right, bottom rectangle divided into four sections by centerX, centerY.
|
|
434
|
+
*/
|
|
435
|
+
declare class DivRect {
|
|
436
|
+
left: number;
|
|
437
|
+
centerX: number;
|
|
438
|
+
right: number;
|
|
439
|
+
top: number;
|
|
440
|
+
centerY: number;
|
|
441
|
+
bottom: number;
|
|
442
|
+
/**
|
|
443
|
+
* Create rectangle with all zero values.
|
|
444
|
+
*/
|
|
445
|
+
constructor();
|
|
446
|
+
/**
|
|
447
|
+
* Create rectangle with left, right, top, bottom.
|
|
448
|
+
* Properties centerX and centerY will be centered in the middle.
|
|
449
|
+
*
|
|
450
|
+
* @param left - Left coordinate.
|
|
451
|
+
* @param right - Right coordinate.
|
|
452
|
+
* @param top - Top coordinate.
|
|
453
|
+
* @param bottom - Bottom coordinate.
|
|
454
|
+
*/
|
|
455
|
+
constructor(left: number, right: number, top: number, bottom: number);
|
|
456
|
+
/**
|
|
457
|
+
* Create rectangle with full arguments.
|
|
458
|
+
*
|
|
459
|
+
* @param left - Left coordinate.
|
|
460
|
+
* @param centerX - Center x-coordinate.
|
|
461
|
+
* @param right - Right coordinate.
|
|
462
|
+
* @param top - Top coordinate.
|
|
463
|
+
* @param centerY - Center y-coordinate.
|
|
464
|
+
* @param bottom - Bottom coordinate.
|
|
465
|
+
*/
|
|
466
|
+
constructor(left: number, centerX: number, right: number, top: number, centerY: number, bottom: number);
|
|
467
|
+
/**
|
|
468
|
+
* Create rect from basic left, top, width and height arguments.
|
|
469
|
+
*
|
|
470
|
+
* @param left - Left coordinate.
|
|
471
|
+
* @param top - Top coordinate.
|
|
472
|
+
* @param width - Width.
|
|
473
|
+
* @param height - Height.
|
|
474
|
+
* @returns - DivRect.
|
|
475
|
+
*/
|
|
476
|
+
static create(left: number, top: number, width: number, height: number): DivRect;
|
|
477
|
+
/**
|
|
478
|
+
* Create rect from centerX, centerY, width, height arguments.
|
|
479
|
+
*
|
|
480
|
+
* @param centerX - Center x-coordinate.
|
|
481
|
+
* @param centerY - Center y-coordinate.
|
|
482
|
+
* @param width - Width.
|
|
483
|
+
* @param height - Height.
|
|
484
|
+
* @returns - DivRect.
|
|
485
|
+
*/
|
|
486
|
+
static createCentered(centerX: number, centerY: number, width: number, height: number): DivRect;
|
|
487
|
+
/**
|
|
488
|
+
* Create rect from sections.
|
|
489
|
+
*
|
|
490
|
+
* @param leftw - Left section width.
|
|
491
|
+
* @param rightw - Right section width.
|
|
492
|
+
* @param toph - Top section height.
|
|
493
|
+
* @param bottomh - Bottomsection height.
|
|
494
|
+
* @returns - DivRect.
|
|
495
|
+
*/
|
|
496
|
+
static createSections(leftw: number, rightw: number, toph: number, bottomh: number): DivRect;
|
|
497
|
+
/**
|
|
498
|
+
* Width getter.
|
|
499
|
+
*/
|
|
500
|
+
get width(): number;
|
|
501
|
+
/**
|
|
502
|
+
* Height getter.
|
|
503
|
+
*/
|
|
504
|
+
get height(): number;
|
|
505
|
+
/**
|
|
506
|
+
* Left section width getter.
|
|
507
|
+
*/
|
|
508
|
+
get leftw(): number;
|
|
509
|
+
/**
|
|
510
|
+
* Right section width getter.
|
|
511
|
+
*/
|
|
512
|
+
get rightw(): number;
|
|
513
|
+
/**
|
|
514
|
+
* Top section height getter.
|
|
515
|
+
*/
|
|
516
|
+
get toph(): number;
|
|
517
|
+
/**
|
|
518
|
+
* Bottom section height getter.
|
|
519
|
+
*/
|
|
520
|
+
get bottomh(): number;
|
|
521
|
+
/**
|
|
522
|
+
* Does this Rect contain given (x, y)-point?
|
|
523
|
+
*
|
|
524
|
+
* @param x - X-coordinate.
|
|
525
|
+
* @param y - Y-coordinate.
|
|
526
|
+
* @returns - True/false.
|
|
527
|
+
*/
|
|
528
|
+
contains(x: number, y: number): boolean;
|
|
529
|
+
/**
|
|
530
|
+
* Do a and b rects overlap?
|
|
531
|
+
*
|
|
532
|
+
* @param a - DivRect a.
|
|
533
|
+
* @param b - DivRect b.
|
|
534
|
+
* @returns - True/false.
|
|
535
|
+
*/
|
|
536
|
+
static overlap(a: DivRect, b: DivRect): boolean;
|
|
537
|
+
/**
|
|
538
|
+
* Do horizontal measures of a and b rects overlap?
|
|
539
|
+
*
|
|
540
|
+
* @param a - DivRect a.
|
|
541
|
+
* @param b - DivRect b.
|
|
542
|
+
* @returns - True/false.
|
|
543
|
+
*/
|
|
544
|
+
static overlapX(a: DivRect, b: DivRect): boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Check if given rects are equal.
|
|
547
|
+
* @param a - DivRect a.
|
|
548
|
+
* @param b - DivRect b.
|
|
549
|
+
* @returns - True/false.
|
|
550
|
+
*/
|
|
551
|
+
static equals(a: DivRect | null | undefined, b: DivRect | null | undefined): boolean;
|
|
552
|
+
/**
|
|
553
|
+
* Check if this rect equals with another rect.
|
|
554
|
+
* @param other - The other rect.
|
|
555
|
+
* @returns - True/false.
|
|
556
|
+
*/
|
|
557
|
+
equals(other: DivRect): boolean;
|
|
558
|
+
/**
|
|
559
|
+
* Check if edges of given rects are equal, ignoring centerX and centerY.
|
|
560
|
+
*
|
|
561
|
+
* @param a - DivRect a.
|
|
562
|
+
* @param b - DivRect b.
|
|
563
|
+
* @returns - True/false.
|
|
564
|
+
*/
|
|
565
|
+
static equalsEdges(a: DivRect | null | undefined, b: DivRect | null | undefined): boolean;
|
|
566
|
+
/**
|
|
567
|
+
* Check if edges of this Rect equals with given Rect, ignoring centerX and centerY.
|
|
568
|
+
*
|
|
569
|
+
* @param other - The other DivRect.
|
|
570
|
+
* @returns - True/false.
|
|
571
|
+
*/
|
|
572
|
+
equalsEdges(other: DivRect): boolean;
|
|
573
|
+
/**
|
|
574
|
+
* Created duplicate of this Rect.
|
|
575
|
+
*
|
|
576
|
+
* @returns - Duplicate.
|
|
577
|
+
*/
|
|
578
|
+
copy(): DivRect;
|
|
579
|
+
/**
|
|
580
|
+
* Move this rect by (dx, dy). Modifies this Rect.
|
|
581
|
+
*
|
|
582
|
+
* @param dx - Offset amount in x-direction.
|
|
583
|
+
* @param dy - Offset amount in y-direction.
|
|
584
|
+
* @returns - This DivRect instance.
|
|
585
|
+
*/
|
|
586
|
+
offsetInPlace(dx: number, dy: number): DivRect;
|
|
587
|
+
/**
|
|
588
|
+
* Move this rect by (dx, dy). Immutable, returns modified copy.
|
|
589
|
+
*
|
|
590
|
+
* @param dx - Offset amount in x-direction.
|
|
591
|
+
* @param dy - Offset amount in y-direction.
|
|
592
|
+
* @returns - DivRect copy with applied offset.
|
|
593
|
+
*/
|
|
594
|
+
offsetCopy(dx: number, dy: number): DivRect;
|
|
595
|
+
/**
|
|
596
|
+
* Expand this Rect by given Rect. Modifies this Rect.
|
|
597
|
+
*
|
|
598
|
+
* @param rect - DivRect to expand this instance with.
|
|
599
|
+
* @returns - This DivRect instance.
|
|
600
|
+
*/
|
|
601
|
+
expandInPlace(rect: DivRect): DivRect;
|
|
602
|
+
/**
|
|
603
|
+
* Expand this Rect by given Rect. Immutable, returns modified copy.
|
|
604
|
+
*
|
|
605
|
+
* @param rect - DivRect to expand this instance with.
|
|
606
|
+
* @returns - Expanded copy of this DivRect.
|
|
607
|
+
*/
|
|
608
|
+
expandCopy(rect: DivRect): DivRect;
|
|
609
|
+
/**
|
|
610
|
+
* Clip this Rect by given Rect. Mmodifies this Rect.
|
|
611
|
+
*
|
|
612
|
+
* @param clipRect - DivRect to clip this instance with.
|
|
613
|
+
* @returns - This DivRect instance.
|
|
614
|
+
*/
|
|
615
|
+
clipInPlace(clipRect: DivRect): DivRect;
|
|
616
|
+
/**
|
|
617
|
+
* Clip this Rect by given Rect. Immutable, return modified copy.
|
|
618
|
+
*
|
|
619
|
+
* @param clipRect - DivRecto to clip this instance with.
|
|
620
|
+
* @returns - Clipped DivRect copy.
|
|
621
|
+
*/
|
|
622
|
+
clipCopy(clipRect: DivRect): DivRect;
|
|
623
|
+
/**
|
|
624
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Modifies this Rect.
|
|
625
|
+
*
|
|
626
|
+
* @param scaleX - Scale x-amount.
|
|
627
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
628
|
+
* @returns This DivRect instance.
|
|
629
|
+
*/
|
|
630
|
+
scaleInPlace(scaleX: number, scaleY?: number): DivRect;
|
|
631
|
+
/**
|
|
632
|
+
* Scale Rect. Anchor pos is (centerX, centerY). Immutable, returns modified copy.
|
|
633
|
+
*
|
|
634
|
+
* @param scaleX - Scale x-amount.
|
|
635
|
+
* @param scaleY - Scale y-amount. If undefined then scale x-amount is used.
|
|
636
|
+
* @returns Scaled copy of this DivRect.
|
|
637
|
+
*/
|
|
638
|
+
scaleCopy(scaleX: number, scaleY?: number): DivRect;
|
|
639
|
+
/**
|
|
640
|
+
* Get this DivRect instance.
|
|
641
|
+
* @returns - This DivRect instance.
|
|
642
|
+
*/
|
|
643
|
+
getRect(): DivRect;
|
|
396
644
|
}
|
|
397
645
|
|
|
398
646
|
/**
|
|
399
647
|
* LRUCache class: Least Recently Used cache with a fixed capacity
|
|
400
|
-
*
|
|
401
|
-
* Provided by ChatGPT.
|
|
402
648
|
*/
|
|
403
649
|
declare class LRUCache<K extends string, V> {
|
|
404
650
|
private cache;
|
|
@@ -418,138 +664,119 @@ declare class LRUCache<K extends string, V> {
|
|
|
418
664
|
private addToTail;
|
|
419
665
|
}
|
|
420
666
|
|
|
421
|
-
|
|
422
|
-
* A cache-like structure optimized for small-range integer keys, including negatives.
|
|
423
|
-
*
|
|
424
|
-
* Internally implemented using two sparse arrays: one for non-negative keys,
|
|
425
|
-
* and one for negative keys (stored by index `-key - 1`).
|
|
426
|
-
*
|
|
427
|
-
* @remarks
|
|
428
|
-
* - Fast access for small integer keys.
|
|
429
|
-
* - Not suitable for large or sparse key ranges — memory usage may grow significantly.
|
|
430
|
-
* - Supports `get`, `set`, `delete`, `has` and `clear`
|
|
431
|
-
*
|
|
432
|
-
* @example
|
|
433
|
-
* ```ts
|
|
434
|
-
* const cache = new SmallIntCache<string>();
|
|
435
|
-
* cache.set(-2, 'A');
|
|
436
|
-
* cache.set(3, 'B');
|
|
437
|
-
* console.log(cache.get(-2)); // 'A'
|
|
438
|
-
* ```
|
|
439
|
-
*
|
|
440
|
-
* @deprecated - Same functionality an more is available now in SignedIndexArray<EL> and IndexArray<EL> containers.
|
|
441
|
-
*/
|
|
442
|
-
declare class SmallIntCache<V> {
|
|
443
|
-
private pos;
|
|
444
|
-
private neg;
|
|
445
|
-
constructor();
|
|
446
|
-
set(key: number, value: V): void;
|
|
447
|
-
get(key: number): V | undefined;
|
|
448
|
-
has(key: number): boolean;
|
|
449
|
-
delete(key: number): void;
|
|
450
|
-
clear(): void;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
interface KVComponent<K extends any[], EL> {
|
|
667
|
+
interface KVComponent<K extends any[], VALUE> {
|
|
454
668
|
get size(): number;
|
|
669
|
+
isEmpty(): boolean;
|
|
455
670
|
has(...keys: K): boolean;
|
|
456
|
-
get(...keys: K):
|
|
457
|
-
getOrDefault(...keysAndDefault: [...K,
|
|
458
|
-
getOrCreate(...keysAndCreator: [...K,
|
|
459
|
-
set(...keysAndValue: [...K,
|
|
671
|
+
get(...keys: K): VALUE | undefined;
|
|
672
|
+
getOrDefault(...keysAndDefault: [...K, VALUE]): VALUE;
|
|
673
|
+
getOrCreate(...keysAndCreator: [...K, VALUE]): VALUE;
|
|
674
|
+
set(...keysAndValue: [...K, VALUE]): void;
|
|
460
675
|
delete(...keys: K): boolean;
|
|
461
676
|
clear?(): void;
|
|
462
677
|
toString(): string;
|
|
678
|
+
kvValues(): IterableIterator<VALUE>;
|
|
679
|
+
kvKeys(): IterableIterator<K>;
|
|
680
|
+
kvEntries(): IterableIterator<[K, VALUE]>;
|
|
463
681
|
}
|
|
464
682
|
|
|
465
683
|
/**
|
|
466
684
|
* An array-like structure for non-negative indexes.
|
|
467
685
|
*/
|
|
468
|
-
declare class IndexArray<
|
|
469
|
-
private static toNegIndex;
|
|
686
|
+
declare class IndexArray<VALUE> implements KVComponent<[number], VALUE> {
|
|
470
687
|
private static validateIndex;
|
|
471
|
-
private
|
|
688
|
+
private posVal;
|
|
472
689
|
private hasPos;
|
|
473
|
-
private
|
|
690
|
+
private valCount;
|
|
474
691
|
constructor();
|
|
475
|
-
constructor(arr: IndexArray<
|
|
476
|
-
constructor(entries: Iterable<[number,
|
|
477
|
-
get size(): number;
|
|
692
|
+
constructor(arr: IndexArray<VALUE>);
|
|
693
|
+
constructor(entries: Iterable<[number, VALUE]>);
|
|
478
694
|
private get posLen();
|
|
695
|
+
get size(): number;
|
|
696
|
+
isEmpty(): boolean;
|
|
479
697
|
has(id: number): boolean;
|
|
480
|
-
set(id: number,
|
|
481
|
-
get(id: number):
|
|
482
|
-
getOrDefault(id: number, defaultValue:
|
|
483
|
-
getOrCreate(id: number, value:
|
|
484
|
-
getOrCreate(id: number, creator: () =>
|
|
698
|
+
set(id: number, value: VALUE): void;
|
|
699
|
+
get(id: number): VALUE | undefined;
|
|
700
|
+
getOrDefault(id: number, defaultValue: VALUE): VALUE;
|
|
701
|
+
getOrCreate(id: number, value: VALUE): VALUE;
|
|
702
|
+
getOrCreate(id: number, creator: () => VALUE): VALUE;
|
|
485
703
|
delete(id: number): boolean;
|
|
486
704
|
clear(): void;
|
|
487
|
-
forEach(callbackfn: (
|
|
705
|
+
forEach(callbackfn: (value: VALUE, id: number, arr: IndexArray<VALUE>) => void, thisArg?: any): void;
|
|
488
706
|
indices(): IterableIterator<number>;
|
|
707
|
+
values(): IterableIterator<VALUE>;
|
|
708
|
+
entries(): IterableIterator<[number, VALUE]>;
|
|
489
709
|
indicesArray(): number[];
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
710
|
+
valuesArray(): VALUE[];
|
|
711
|
+
entriesArray(): [number, VALUE][];
|
|
712
|
+
kvKeys(): IterableIterator<[number]>;
|
|
713
|
+
kvValues(): IterableIterator<VALUE>;
|
|
714
|
+
kvEntries(): IterableIterator<[[number], VALUE]>;
|
|
715
|
+
[Symbol.iterator](): Generator<[number, VALUE], void, any>;
|
|
716
|
+
clone(): IndexArray<VALUE>;
|
|
717
|
+
merge(other: IndexArray<VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, id: number) => VALUE): this;
|
|
718
|
+
some(fn: (value: VALUE, id: number) => boolean): boolean;
|
|
719
|
+
every(fn: (value: VALUE, key1: number) => boolean): boolean;
|
|
720
|
+
filter<S extends VALUE>(predicate: (value: VALUE, index: number, array: IndexArray<VALUE>) => value is S): IndexArray<S>;
|
|
721
|
+
filter(predicate: (value: VALUE, index: number, array: IndexArray<VALUE>) => unknown): IndexArray<VALUE>;
|
|
722
|
+
reduce(fn: (acc: VALUE, value: VALUE, id: number) => VALUE): VALUE;
|
|
723
|
+
reduce<R>(fn: (acc: R, value: VALUE, id: number) => R, init: R): R;
|
|
724
|
+
mapToArray<R>(fn: (value: VALUE, key1: number) => R): R[];
|
|
725
|
+
map<R = VALUE>(fn: (value: VALUE, key1: number) => R): IndexArray<R>;
|
|
726
|
+
equals(other: IndexArray<VALUE>): boolean;
|
|
727
|
+
equals(other: IndexArray<VALUE>, eq: (a: VALUE, b: VALUE) => boolean): boolean;
|
|
506
728
|
toString(): string;
|
|
507
729
|
}
|
|
508
730
|
|
|
509
731
|
/**
|
|
510
732
|
* An array-like structure for signed indexes, including negatives.
|
|
511
733
|
*/
|
|
512
|
-
declare class SignedIndexArray<
|
|
734
|
+
declare class SignedIndexArray<VALUE> implements KVComponent<[number], VALUE> {
|
|
513
735
|
private static toNegIndex;
|
|
514
736
|
private static validateIndex;
|
|
515
|
-
private
|
|
737
|
+
private posVal;
|
|
516
738
|
private hasPos;
|
|
517
|
-
private
|
|
739
|
+
private negVal;
|
|
518
740
|
private hasNeg;
|
|
519
|
-
private
|
|
741
|
+
private valCount;
|
|
520
742
|
constructor();
|
|
521
|
-
constructor(arr: SignedIndexArray<
|
|
522
|
-
constructor(entries: Iterable<[number,
|
|
743
|
+
constructor(arr: SignedIndexArray<VALUE>);
|
|
744
|
+
constructor(entries: Iterable<[number, VALUE]>);
|
|
523
745
|
get size(): number;
|
|
746
|
+
isEmpty(): boolean;
|
|
524
747
|
private get posLen();
|
|
525
748
|
private get negLen();
|
|
526
749
|
has(id: number): boolean;
|
|
527
|
-
set(id: number,
|
|
528
|
-
get(id: number):
|
|
529
|
-
getOrDefault(id: number, defaultValue:
|
|
530
|
-
getOrCreate(id: number, value:
|
|
531
|
-
getOrCreate(id: number, creator: () =>
|
|
750
|
+
set(id: number, value: VALUE): void;
|
|
751
|
+
get(id: number): VALUE | undefined;
|
|
752
|
+
getOrDefault(id: number, defaultValue: VALUE): VALUE;
|
|
753
|
+
getOrCreate(id: number, value: VALUE): VALUE;
|
|
754
|
+
getOrCreate(id: number, creator: () => VALUE): VALUE;
|
|
532
755
|
delete(id: number): boolean;
|
|
533
756
|
clear(): void;
|
|
534
|
-
forEach(callbackfn: (
|
|
757
|
+
forEach(callbackfn: (value: VALUE, id: number, arr: SignedIndexArray<VALUE>) => void, thisArg?: any): void;
|
|
535
758
|
indices(): IterableIterator<number>;
|
|
759
|
+
values(): IterableIterator<VALUE>;
|
|
760
|
+
entries(): IterableIterator<[number, VALUE]>;
|
|
536
761
|
indicesArray(): number[];
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
762
|
+
valuesArray(): VALUE[];
|
|
763
|
+
entriesArray(): [number, VALUE][];
|
|
764
|
+
kvKeys(): IterableIterator<[number]>;
|
|
765
|
+
kvValues(): IterableIterator<VALUE>;
|
|
766
|
+
kvEntries(): IterableIterator<[[number], VALUE]>;
|
|
767
|
+
[Symbol.iterator](): Generator<[number, VALUE], void, any>;
|
|
768
|
+
clone(): SignedIndexArray<VALUE>;
|
|
769
|
+
merge(other: SignedIndexArray<VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, id: number) => VALUE): this;
|
|
770
|
+
some(fn: (value: VALUE, id: number) => boolean): boolean;
|
|
771
|
+
every(fn: (value: VALUE, key1: number) => boolean): boolean;
|
|
772
|
+
filter<S extends VALUE>(predicate: (value: VALUE, index: number, array: SignedIndexArray<VALUE>) => value is S): SignedIndexArray<S>;
|
|
773
|
+
filter(predicate: (value: VALUE, index: number, array: SignedIndexArray<VALUE>) => unknown): SignedIndexArray<VALUE>;
|
|
774
|
+
reduce(fn: (acc: VALUE, value: VALUE, id: number) => VALUE): VALUE;
|
|
775
|
+
reduce<R>(fn: (acc: R, value: VALUE, id: number) => R, init: R): R;
|
|
776
|
+
mapToArray<R>(fn: (value: VALUE, key1: number) => R): R[];
|
|
777
|
+
map<R = VALUE>(fn: (value: VALUE, key1: number) => R): SignedIndexArray<R>;
|
|
778
|
+
equals(other: SignedIndexArray<VALUE>): boolean;
|
|
779
|
+
equals(other: SignedIndexArray<VALUE>, eq: (a: VALUE, b: VALUE) => boolean): boolean;
|
|
553
780
|
toString(): string;
|
|
554
781
|
}
|
|
555
782
|
|
|
@@ -567,25 +794,32 @@ declare class Map1<KEY1, VALUE> implements KVComponent<[KEY1], VALUE> {
|
|
|
567
794
|
delete(key1: KEY1): boolean;
|
|
568
795
|
clear(): void;
|
|
569
796
|
get size(): number;
|
|
797
|
+
isEmpty(): boolean;
|
|
570
798
|
forEach(callbackfn: (value: VALUE, key1: KEY1, map1: Map1<KEY1, VALUE>) => void, thisArg?: any): void;
|
|
571
799
|
keys(): IterableIterator<KEY1>;
|
|
572
|
-
keysArray(): KEY1[];
|
|
573
800
|
values(): IterableIterator<VALUE>;
|
|
574
|
-
valuesArray(): VALUE[];
|
|
575
801
|
entries(): IterableIterator<[KEY1, VALUE]>;
|
|
802
|
+
keysArray(): KEY1[];
|
|
803
|
+
valuesArray(): VALUE[];
|
|
576
804
|
entriesArray(): [KEY1, VALUE][];
|
|
805
|
+
kvKeys(): IterableIterator<[KEY1]>;
|
|
806
|
+
kvValues(): IterableIterator<VALUE>;
|
|
807
|
+
kvEntries(): IterableIterator<[[KEY1], VALUE]>;
|
|
577
808
|
[Symbol.iterator](): Generator<[KEY1, VALUE], void, any>;
|
|
578
809
|
clone(): Map1<KEY1, VALUE>;
|
|
579
810
|
merge(other: Map1<KEY1, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1) => VALUE): this;
|
|
580
811
|
some(fn: (value: VALUE, key1: KEY1) => boolean): boolean;
|
|
581
812
|
every(fn: (value: VALUE, key1: KEY1) => boolean): boolean;
|
|
582
|
-
filter(
|
|
813
|
+
filter<S extends VALUE>(predicate: (value: VALUE, key1: KEY1, array: Map1<KEY1, VALUE>) => value is S): Map1<KEY1, S>;
|
|
814
|
+
filter(predicate: (value: VALUE, key1: KEY1, array: Map1<KEY1, VALUE>) => unknown): Map1<KEY1, VALUE>;
|
|
815
|
+
reduce(fn: (acc: VALUE, value: VALUE, key1: KEY1) => VALUE): VALUE;
|
|
583
816
|
reduce<R>(fn: (acc: R, value: VALUE, key1: KEY1) => R, init: R): R;
|
|
584
817
|
mapEntries<R>(fn: (value: VALUE, key1: KEY1) => R): R[];
|
|
585
818
|
mapValues<R = VALUE>(fn: (value: VALUE, key1: KEY1) => R): Map1<KEY1, R>;
|
|
586
819
|
toMap(): Map<KEY1, VALUE>;
|
|
587
820
|
toString(): string;
|
|
588
821
|
}
|
|
822
|
+
|
|
589
823
|
declare class Map2<KEY1, KEY2, VALUE> implements KVComponent<[KEY1, KEY2], VALUE> {
|
|
590
824
|
private map1;
|
|
591
825
|
constructor();
|
|
@@ -601,25 +835,32 @@ declare class Map2<KEY1, KEY2, VALUE> implements KVComponent<[KEY1, KEY2], VALUE
|
|
|
601
835
|
delete(key1: KEY1, key2: KEY2): boolean;
|
|
602
836
|
clear(): void;
|
|
603
837
|
get size(): number;
|
|
838
|
+
isEmpty(): boolean;
|
|
604
839
|
forEach(callbackfn: (value: VALUE, key1: KEY1, key2: KEY2, map2: Map2<KEY1, KEY2, VALUE>) => void, thisArg?: any): void;
|
|
605
840
|
keys(): IterableIterator<[KEY1, KEY2]>;
|
|
606
|
-
keysArray(): [KEY1, KEY2][];
|
|
607
841
|
values(): IterableIterator<VALUE>;
|
|
608
|
-
valuesArray(): VALUE[];
|
|
609
842
|
entries(): IterableIterator<[KEY1, KEY2, VALUE]>;
|
|
843
|
+
keysArray(): [KEY1, KEY2][];
|
|
844
|
+
valuesArray(): VALUE[];
|
|
610
845
|
entriesArray(): [KEY1, KEY2, VALUE][];
|
|
846
|
+
kvKeys(): IterableIterator<[KEY1, KEY2]>;
|
|
847
|
+
kvValues(): IterableIterator<VALUE>;
|
|
848
|
+
kvEntries(): IterableIterator<[[KEY1, KEY2], VALUE]>;
|
|
611
849
|
[Symbol.iterator](): Generator<[KEY1, KEY2, VALUE], void, any>;
|
|
612
850
|
clone(): Map2<KEY1, KEY2, VALUE>;
|
|
613
851
|
merge(other: Map2<KEY1, KEY2, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2) => VALUE): this;
|
|
614
852
|
some(fn: (value: VALUE, key1: KEY1, key2: KEY2) => boolean): boolean;
|
|
615
853
|
every(fn: (value: VALUE, key1: KEY1, key2: KEY2) => boolean): boolean;
|
|
616
|
-
filter(
|
|
854
|
+
filter<S extends VALUE>(predicate: (value: VALUE, key1: KEY1, key2: KEY2, array: Map2<KEY1, KEY2, VALUE>) => value is S): Map2<KEY1, KEY2, S>;
|
|
855
|
+
filter(predicate: (value: VALUE, key1: KEY1, key2: KEY2, array: Map2<KEY1, KEY2, VALUE>) => unknown): Map2<KEY1, KEY2, VALUE>;
|
|
856
|
+
reduce(fn: (acc: VALUE, value: VALUE, key1: KEY1, key2: KEY2) => VALUE): VALUE;
|
|
617
857
|
reduce<R>(fn: (acc: R, value: VALUE, key1: KEY1, key2: KEY2) => R, init: R): R;
|
|
618
858
|
mapEntries<R>(fn: (value: VALUE, key1: KEY1, key2: KEY2) => R): R[];
|
|
619
859
|
mapValues<R = VALUE>(fn: (value: VALUE, key1: KEY1, key2: KEY2) => R): Map2<KEY1, KEY2, R>;
|
|
620
860
|
toMap(): Map<[KEY1, KEY2], VALUE>;
|
|
621
861
|
toString(): string;
|
|
622
862
|
}
|
|
863
|
+
|
|
623
864
|
declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2, KEY3], VALUE> {
|
|
624
865
|
private map1;
|
|
625
866
|
constructor();
|
|
@@ -636,19 +877,25 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
|
|
|
636
877
|
delete(key1: KEY1, key2: KEY2, key3: KEY3): boolean;
|
|
637
878
|
clear(): void;
|
|
638
879
|
get size(): number;
|
|
880
|
+
isEmpty(): boolean;
|
|
639
881
|
forEach(callbackfn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3, map2: Map3<KEY1, KEY2, KEY3, VALUE>) => void, thisArg?: any): void;
|
|
640
882
|
keys(): IterableIterator<[KEY1, KEY2, KEY3]>;
|
|
641
|
-
keysArray(): [KEY1, KEY2, KEY3][];
|
|
642
883
|
values(): IterableIterator<VALUE>;
|
|
643
|
-
valuesArray(): VALUE[];
|
|
644
884
|
entries(): IterableIterator<[KEY1, KEY2, KEY3, VALUE]>;
|
|
885
|
+
keysArray(): [KEY1, KEY2, KEY3][];
|
|
886
|
+
valuesArray(): VALUE[];
|
|
645
887
|
entriesArray(): [KEY1, KEY2, KEY3, VALUE][];
|
|
888
|
+
kvKeys(): IterableIterator<[KEY1, KEY2, KEY3]>;
|
|
889
|
+
kvValues(): IterableIterator<VALUE>;
|
|
890
|
+
kvEntries(): IterableIterator<[[KEY1, KEY2, KEY3], VALUE]>;
|
|
646
891
|
[Symbol.iterator](): Generator<[KEY1, KEY2, KEY3, VALUE], void, any>;
|
|
647
892
|
clone(): Map3<KEY1, KEY2, KEY3, VALUE>;
|
|
648
893
|
merge(other: Map3<KEY1, KEY2, KEY3, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => VALUE): this;
|
|
649
894
|
some(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => boolean): boolean;
|
|
650
895
|
every(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => boolean): boolean;
|
|
651
|
-
filter(
|
|
896
|
+
filter<S extends VALUE>(predicate: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3, array: Map3<KEY1, KEY2, KEY3, VALUE>) => value is S): Map3<KEY1, KEY2, KEY3, S>;
|
|
897
|
+
filter(predicate: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3, array: Map3<KEY1, KEY2, KEY3, VALUE>) => unknown): Map3<KEY1, KEY2, KEY3, VALUE>;
|
|
898
|
+
reduce(fn: (acc: VALUE, value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => VALUE): VALUE;
|
|
652
899
|
reduce<R>(fn: (acc: R, value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => R, init: R): R;
|
|
653
900
|
mapEntries<R>(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => R): R[];
|
|
654
901
|
mapValues<R = VALUE>(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => R): Map3<KEY1, KEY2, KEY3, R>;
|
|
@@ -659,11 +906,17 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
|
|
|
659
906
|
declare class MultiContainer<K extends any[], V> {
|
|
660
907
|
private readonly base;
|
|
661
908
|
constructor(base: KVComponent<K, V[]>);
|
|
909
|
+
isEmpty(): boolean;
|
|
910
|
+
clear(): void;
|
|
662
911
|
add(...keysAndValue: [...K, V]): V;
|
|
663
912
|
remove(...keysAndValue: [...K, V]): boolean;
|
|
664
913
|
getAll(...keys: K): V[];
|
|
665
914
|
iterAll(...keys: K): IterableIterator<V>;
|
|
666
|
-
|
|
915
|
+
values(): IterableIterator<V>;
|
|
916
|
+
keys(): IterableIterator<K>;
|
|
917
|
+
entries(): IterableIterator<[K, V[]]>;
|
|
918
|
+
[Symbol.iterator](): IterableIterator<[K, V[]]>;
|
|
919
|
+
toString(): string;
|
|
667
920
|
}
|
|
668
921
|
/**
|
|
669
922
|
* ```ts
|
|
@@ -674,6 +927,54 @@ declare class MultiContainer<K extends any[], V> {
|
|
|
674
927
|
* @param base
|
|
675
928
|
* @returns
|
|
676
929
|
*/
|
|
677
|
-
declare function asMulti<K extends any[],
|
|
930
|
+
declare function asMulti<K extends any[], VALUE>(base: KVComponent<K, VALUE[]>): MultiContainer<K, VALUE>;
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Vec2 class.
|
|
934
|
+
*
|
|
935
|
+
* @deprecated - Use Vec instead, has more functionality.
|
|
936
|
+
*/
|
|
937
|
+
declare class Vec2 {
|
|
938
|
+
readonly x: number;
|
|
939
|
+
readonly y: number;
|
|
940
|
+
constructor(x?: number, y?: number);
|
|
941
|
+
length(): number;
|
|
942
|
+
add(a: Vec2): Vec2;
|
|
943
|
+
sub(a: Vec2): Vec2;
|
|
944
|
+
mul(a: number): Vec2;
|
|
945
|
+
div(a: number): Vec2;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* A cache-like structure optimized for small-range integer keys, including negatives.
|
|
950
|
+
*
|
|
951
|
+
* Internally implemented using two sparse arrays: one for non-negative keys,
|
|
952
|
+
* and one for negative keys (stored by index `-key - 1`).
|
|
953
|
+
*
|
|
954
|
+
* @remarks
|
|
955
|
+
* - Fast access for small integer keys.
|
|
956
|
+
* - Not suitable for large or sparse key ranges — memory usage may grow significantly.
|
|
957
|
+
* - Supports `get`, `set`, `delete`, `has` and `clear`
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* ```ts
|
|
961
|
+
* const cache = new SmallIntCache<string>();
|
|
962
|
+
* cache.set(-2, 'A');
|
|
963
|
+
* cache.set(3, 'B');
|
|
964
|
+
* console.log(cache.get(-2)); // 'A'
|
|
965
|
+
* ```
|
|
966
|
+
*
|
|
967
|
+
* @deprecated - Same functionality an more is available now in SignedIndexArray<VALUE> and IndexArray<VALUE> containers.
|
|
968
|
+
*/
|
|
969
|
+
declare class SmallIntCache<VALUE> {
|
|
970
|
+
private pos;
|
|
971
|
+
private neg;
|
|
972
|
+
constructor();
|
|
973
|
+
set(key: number, value: VALUE): void;
|
|
974
|
+
get(key: number): VALUE | undefined;
|
|
975
|
+
has(key: number): boolean;
|
|
976
|
+
delete(key: number): void;
|
|
977
|
+
clear(): void;
|
|
978
|
+
}
|
|
678
979
|
|
|
679
|
-
export { Assert, Cookies, Device, IndexArray, type KVComponent, LRUCache, Map1, Map2, Map3, MultiContainer, SignedIndexArray, SmallIntCache, Stack, index as Utils, Vec2, asMulti };
|
|
980
|
+
export { Assert, Cookies, Device, DivRect, IndexArray, type KVComponent, LRUCache, Map1, Map2, Map3, MultiContainer, SignedIndexArray, SmallIntCache, Stack, index as Utils, Vec, Vec2, asMulti };
|