@tspro/ts-utils-lib 1.16.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 +11 -0
- package/dist/index.d.mts +386 -115
- package/dist/index.d.ts +386 -115
- package/dist/index.js +637 -195
- package/dist/index.mjs +635 -195
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.17.0] - 2025-10-21
|
|
4
|
+
### Added
|
|
5
|
+
- Vec class.
|
|
6
|
+
- DivRect class.
|
|
7
|
+
- Map1, Map2 and Map3 into own files.
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
- Map1, Map2 and Map3.reduce without init value.
|
|
11
|
+
- Improved filter functions.
|
|
12
|
+
|
|
13
|
+
|
|
3
14
|
## [1.16.0] - 2025-10-20
|
|
4
15
|
### Added
|
|
5
16
|
- Add isEmpty() to interface and containers.
|
package/dist/index.d.mts
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,150 +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;
|
|
455
669
|
isEmpty(): boolean;
|
|
456
670
|
has(...keys: K): boolean;
|
|
457
|
-
get(...keys: K):
|
|
458
|
-
getOrDefault(...keysAndDefault: [...K,
|
|
459
|
-
getOrCreate(...keysAndCreator: [...K,
|
|
460
|
-
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;
|
|
461
675
|
delete(...keys: K): boolean;
|
|
462
676
|
clear?(): void;
|
|
463
677
|
toString(): string;
|
|
464
|
-
kvValues(): IterableIterator<
|
|
678
|
+
kvValues(): IterableIterator<VALUE>;
|
|
465
679
|
kvKeys(): IterableIterator<K>;
|
|
466
|
-
kvEntries(): IterableIterator<[K,
|
|
680
|
+
kvEntries(): IterableIterator<[K, VALUE]>;
|
|
467
681
|
}
|
|
468
682
|
|
|
469
683
|
/**
|
|
470
684
|
* An array-like structure for non-negative indexes.
|
|
471
685
|
*/
|
|
472
|
-
declare class IndexArray<
|
|
473
|
-
private static toNegIndex;
|
|
686
|
+
declare class IndexArray<VALUE> implements KVComponent<[number], VALUE> {
|
|
474
687
|
private static validateIndex;
|
|
475
|
-
private
|
|
688
|
+
private posVal;
|
|
476
689
|
private hasPos;
|
|
477
|
-
private
|
|
690
|
+
private valCount;
|
|
478
691
|
constructor();
|
|
479
|
-
constructor(arr: IndexArray<
|
|
480
|
-
constructor(entries: Iterable<[number,
|
|
692
|
+
constructor(arr: IndexArray<VALUE>);
|
|
693
|
+
constructor(entries: Iterable<[number, VALUE]>);
|
|
481
694
|
private get posLen();
|
|
482
695
|
get size(): number;
|
|
483
696
|
isEmpty(): boolean;
|
|
484
697
|
has(id: number): boolean;
|
|
485
|
-
set(id: number,
|
|
486
|
-
get(id: number):
|
|
487
|
-
getOrDefault(id: number, defaultValue:
|
|
488
|
-
getOrCreate(id: number, value:
|
|
489
|
-
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;
|
|
490
703
|
delete(id: number): boolean;
|
|
491
704
|
clear(): void;
|
|
492
|
-
forEach(callbackfn: (
|
|
705
|
+
forEach(callbackfn: (value: VALUE, id: number, arr: IndexArray<VALUE>) => void, thisArg?: any): void;
|
|
493
706
|
indices(): IterableIterator<number>;
|
|
494
|
-
values(): IterableIterator<
|
|
495
|
-
entries(): IterableIterator<[number,
|
|
707
|
+
values(): IterableIterator<VALUE>;
|
|
708
|
+
entries(): IterableIterator<[number, VALUE]>;
|
|
496
709
|
indicesArray(): number[];
|
|
497
|
-
valuesArray():
|
|
498
|
-
entriesArray(): [number,
|
|
710
|
+
valuesArray(): VALUE[];
|
|
711
|
+
entriesArray(): [number, VALUE][];
|
|
499
712
|
kvKeys(): IterableIterator<[number]>;
|
|
500
|
-
kvValues(): IterableIterator<
|
|
501
|
-
kvEntries(): IterableIterator<[[number],
|
|
502
|
-
[Symbol.iterator](): Generator<[number,
|
|
503
|
-
clone(): IndexArray<
|
|
504
|
-
merge(other: IndexArray<
|
|
505
|
-
some(fn: (
|
|
506
|
-
every(fn: (value:
|
|
507
|
-
filter(
|
|
508
|
-
|
|
509
|
-
reduce
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
equals(other: IndexArray<
|
|
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;
|
|
514
728
|
toString(): string;
|
|
515
729
|
}
|
|
516
730
|
|
|
517
731
|
/**
|
|
518
732
|
* An array-like structure for signed indexes, including negatives.
|
|
519
733
|
*/
|
|
520
|
-
declare class SignedIndexArray<
|
|
734
|
+
declare class SignedIndexArray<VALUE> implements KVComponent<[number], VALUE> {
|
|
521
735
|
private static toNegIndex;
|
|
522
736
|
private static validateIndex;
|
|
523
|
-
private
|
|
737
|
+
private posVal;
|
|
524
738
|
private hasPos;
|
|
525
|
-
private
|
|
739
|
+
private negVal;
|
|
526
740
|
private hasNeg;
|
|
527
|
-
private
|
|
741
|
+
private valCount;
|
|
528
742
|
constructor();
|
|
529
|
-
constructor(arr: SignedIndexArray<
|
|
530
|
-
constructor(entries: Iterable<[number,
|
|
743
|
+
constructor(arr: SignedIndexArray<VALUE>);
|
|
744
|
+
constructor(entries: Iterable<[number, VALUE]>);
|
|
531
745
|
get size(): number;
|
|
532
746
|
isEmpty(): boolean;
|
|
533
747
|
private get posLen();
|
|
534
748
|
private get negLen();
|
|
535
749
|
has(id: number): boolean;
|
|
536
|
-
set(id: number,
|
|
537
|
-
get(id: number):
|
|
538
|
-
getOrDefault(id: number, defaultValue:
|
|
539
|
-
getOrCreate(id: number, value:
|
|
540
|
-
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;
|
|
541
755
|
delete(id: number): boolean;
|
|
542
756
|
clear(): void;
|
|
543
|
-
forEach(callbackfn: (
|
|
757
|
+
forEach(callbackfn: (value: VALUE, id: number, arr: SignedIndexArray<VALUE>) => void, thisArg?: any): void;
|
|
544
758
|
indices(): IterableIterator<number>;
|
|
545
|
-
values(): IterableIterator<
|
|
546
|
-
entries(): IterableIterator<[number,
|
|
759
|
+
values(): IterableIterator<VALUE>;
|
|
760
|
+
entries(): IterableIterator<[number, VALUE]>;
|
|
547
761
|
indicesArray(): number[];
|
|
548
|
-
valuesArray():
|
|
549
|
-
entriesArray(): [number,
|
|
762
|
+
valuesArray(): VALUE[];
|
|
763
|
+
entriesArray(): [number, VALUE][];
|
|
550
764
|
kvKeys(): IterableIterator<[number]>;
|
|
551
|
-
kvValues(): IterableIterator<
|
|
552
|
-
kvEntries(): IterableIterator<[[number],
|
|
553
|
-
[Symbol.iterator](): Generator<[number,
|
|
554
|
-
clone(): SignedIndexArray<
|
|
555
|
-
merge(other: SignedIndexArray<
|
|
556
|
-
some(fn: (
|
|
557
|
-
every(fn: (value:
|
|
558
|
-
filter(
|
|
559
|
-
|
|
560
|
-
reduce
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
equals(other: SignedIndexArray<
|
|
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;
|
|
565
780
|
toString(): string;
|
|
566
781
|
}
|
|
567
782
|
|
|
@@ -595,13 +810,16 @@ declare class Map1<KEY1, VALUE> implements KVComponent<[KEY1], VALUE> {
|
|
|
595
810
|
merge(other: Map1<KEY1, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1) => VALUE): this;
|
|
596
811
|
some(fn: (value: VALUE, key1: KEY1) => boolean): boolean;
|
|
597
812
|
every(fn: (value: VALUE, key1: KEY1) => boolean): boolean;
|
|
598
|
-
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;
|
|
599
816
|
reduce<R>(fn: (acc: R, value: VALUE, key1: KEY1) => R, init: R): R;
|
|
600
817
|
mapEntries<R>(fn: (value: VALUE, key1: KEY1) => R): R[];
|
|
601
818
|
mapValues<R = VALUE>(fn: (value: VALUE, key1: KEY1) => R): Map1<KEY1, R>;
|
|
602
819
|
toMap(): Map<KEY1, VALUE>;
|
|
603
820
|
toString(): string;
|
|
604
821
|
}
|
|
822
|
+
|
|
605
823
|
declare class Map2<KEY1, KEY2, VALUE> implements KVComponent<[KEY1, KEY2], VALUE> {
|
|
606
824
|
private map1;
|
|
607
825
|
constructor();
|
|
@@ -633,13 +851,16 @@ declare class Map2<KEY1, KEY2, VALUE> implements KVComponent<[KEY1, KEY2], VALUE
|
|
|
633
851
|
merge(other: Map2<KEY1, KEY2, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2) => VALUE): this;
|
|
634
852
|
some(fn: (value: VALUE, key1: KEY1, key2: KEY2) => boolean): boolean;
|
|
635
853
|
every(fn: (value: VALUE, key1: KEY1, key2: KEY2) => boolean): boolean;
|
|
636
|
-
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;
|
|
637
857
|
reduce<R>(fn: (acc: R, value: VALUE, key1: KEY1, key2: KEY2) => R, init: R): R;
|
|
638
858
|
mapEntries<R>(fn: (value: VALUE, key1: KEY1, key2: KEY2) => R): R[];
|
|
639
859
|
mapValues<R = VALUE>(fn: (value: VALUE, key1: KEY1, key2: KEY2) => R): Map2<KEY1, KEY2, R>;
|
|
640
860
|
toMap(): Map<[KEY1, KEY2], VALUE>;
|
|
641
861
|
toString(): string;
|
|
642
862
|
}
|
|
863
|
+
|
|
643
864
|
declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2, KEY3], VALUE> {
|
|
644
865
|
private map1;
|
|
645
866
|
constructor();
|
|
@@ -672,7 +893,9 @@ declare class Map3<KEY1, KEY2, KEY3, VALUE> implements KVComponent<[KEY1, KEY2,
|
|
|
672
893
|
merge(other: Map3<KEY1, KEY2, KEY3, VALUE>, conflictResolver?: (oldValue: VALUE, newValue: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => VALUE): this;
|
|
673
894
|
some(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => boolean): boolean;
|
|
674
895
|
every(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => boolean): boolean;
|
|
675
|
-
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;
|
|
676
899
|
reduce<R>(fn: (acc: R, value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => R, init: R): R;
|
|
677
900
|
mapEntries<R>(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => R): R[];
|
|
678
901
|
mapValues<R = VALUE>(fn: (value: VALUE, key1: KEY1, key2: KEY2, key3: KEY3) => R): Map3<KEY1, KEY2, KEY3, R>;
|
|
@@ -704,6 +927,54 @@ declare class MultiContainer<K extends any[], V> {
|
|
|
704
927
|
* @param base
|
|
705
928
|
* @returns
|
|
706
929
|
*/
|
|
707
|
-
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
|
+
}
|
|
708
979
|
|
|
709
|
-
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 };
|