@the-w1zard/dx 1.0.12 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.d.ts +41 -0
- package/dist/boolean_byte.d.ts +12 -0
- package/dist/class.d.ts +0 -0
- package/dist/date.d.ts +146 -0
- package/dist/error.d.ts +16 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +5697 -3907
- package/dist/iterator.d.ts +51 -0
- package/dist/map.d.ts +69 -0
- package/dist/map_bin.d.ts +34 -0
- package/dist/map_byte.d.ts +91 -0
- package/dist/map_dense.d.ts +33 -0
- package/dist/map_rows.d.ts +33 -0
- package/dist/number.d.ts +44 -0
- package/dist/object.d.ts +35 -0
- package/dist/promise.d.ts +62 -0
- package/dist/reg_ex.d.ts +72 -0
- package/dist/set.d.ts +41 -0
- package/dist/set_byte.d.ts +55 -0
- package/dist/soa_codec.d.ts +12 -0
- package/dist/string.d.ts +39 -0
- package/dist/unit8array.d.ts +64 -0
- package/dist/url_search_params.d.ts +30 -0
- package/dist/weak_map.d.ts +32 -0
- package/dist/weak_set.d.ts +20 -0
- package/package.json +10 -8
- package/src/array.ts +301 -0
- package/src/boolean_byte.ts +23 -0
- package/src/class.ts +0 -0
- package/src/date.ts +660 -0
- package/src/dx.d.ts +31 -11
- package/src/error.ts +81 -0
- package/src/index.ts +57 -0
- package/src/iterator.ts +407 -0
- package/src/map.ts +513 -0
- package/src/map_bin.ts +179 -0
- package/src/map_byte.ts +418 -0
- package/src/map_dense.ts +167 -0
- package/src/map_rows.ts +145 -0
- package/src/number.ts +212 -0
- package/src/object.ts +291 -0
- package/src/promise.ts +309 -0
- package/src/reg_ex.ts +423 -0
- package/src/set.ts +198 -0
- package/src/set_byte.ts +223 -0
- package/src/soa_codec.ts +30 -0
- package/src/string.ts +175 -0
- package/src/unit8array.ts +374 -0
- package/src/url_search_params.ts +187 -0
- package/src/weak_map.ts +155 -0
- package/src/weak_set.ts +101 -0
package/dist/string.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare class S2I extends String implements S2 {
|
|
2
|
+
constructor(value?: A);
|
|
3
|
+
empty(): boolean;
|
|
4
|
+
notEmpty(): boolean;
|
|
5
|
+
blank(): boolean;
|
|
6
|
+
notBlank(): boolean;
|
|
7
|
+
equals(value: string): boolean;
|
|
8
|
+
equalsIgnoreCase(value: string): boolean;
|
|
9
|
+
contains(value: string): boolean;
|
|
10
|
+
starts(value: string): boolean;
|
|
11
|
+
ends(value: string): boolean;
|
|
12
|
+
first(): string;
|
|
13
|
+
last(): string;
|
|
14
|
+
reverse(): string;
|
|
15
|
+
capitalize(): string;
|
|
16
|
+
uncapitalize(): string;
|
|
17
|
+
titleCase(): string;
|
|
18
|
+
camelCase(): string;
|
|
19
|
+
kebabCase(): string;
|
|
20
|
+
snakeCase(): string;
|
|
21
|
+
pascalCase(): string;
|
|
22
|
+
words(): string[];
|
|
23
|
+
lines(): string[];
|
|
24
|
+
chars(): string[];
|
|
25
|
+
unique(): string;
|
|
26
|
+
escapeRegExp(): string;
|
|
27
|
+
stripHtml(): string;
|
|
28
|
+
stripWhitespace(): string;
|
|
29
|
+
truncate(length: N, suffix?: string): string;
|
|
30
|
+
limit(length: N, suffix?: string): string;
|
|
31
|
+
toNumber(): number;
|
|
32
|
+
toInt(radix?: N): number;
|
|
33
|
+
toFloat(): number;
|
|
34
|
+
toBoolean(): boolean;
|
|
35
|
+
toArray(): string[];
|
|
36
|
+
toJSON(): string;
|
|
37
|
+
isWellFormed(): boolean;
|
|
38
|
+
toWellFormed(): string;
|
|
39
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export declare class U82I<T = A> extends Array<T> implements U82<T> {
|
|
2
|
+
constructor(...items: T[]);
|
|
3
|
+
static get [Symbol.species](): ArrayConstructor;
|
|
4
|
+
static from<T>(arrayLike: ArrayLike<T>): U82I<T>;
|
|
5
|
+
static from<T, U>(arrayLike: ArrayLike<T>, mapFn: (value: T, index: number) => U, thisArg?: A): U82I<U>;
|
|
6
|
+
static from<T>(iterable: Iterable<T> | ArrayLike<T>): U82I<T>;
|
|
7
|
+
static of<T>(...items: T[]): U82I<T>;
|
|
8
|
+
first(): T | undefined;
|
|
9
|
+
last(): T | undefined;
|
|
10
|
+
second(): T | undefined;
|
|
11
|
+
third(): T | undefined;
|
|
12
|
+
random(): T | undefined;
|
|
13
|
+
isEmpty(): boolean;
|
|
14
|
+
isNotEmpty(): boolean;
|
|
15
|
+
isNotEmptyAndDefined(): boolean;
|
|
16
|
+
clear(): this;
|
|
17
|
+
clone(): U82I<T>;
|
|
18
|
+
unique(): U82I<T>;
|
|
19
|
+
compact(): U82I<NonNullable<T>>;
|
|
20
|
+
chunk(size: N): U82I<U82I<T>>;
|
|
21
|
+
flatten<D extends N = 1>(depth?: D): U82I<A>;
|
|
22
|
+
shuffle(): this;
|
|
23
|
+
sample(count?: N): U82I<T>;
|
|
24
|
+
count(predicate?: (value: T, index: N, array: T[]) => unknown): N;
|
|
25
|
+
sum(this: U82I<number>): number;
|
|
26
|
+
average(this: U82I<number>): number;
|
|
27
|
+
min(this: U82I<number>): number | undefined;
|
|
28
|
+
max(this: U82I<number>): number | undefined;
|
|
29
|
+
groupBy<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, U82I<T>>;
|
|
30
|
+
keyBy<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, T>;
|
|
31
|
+
partition(predicate: (value: T, index: N, array: T[]) => unknown): [U82I<T>, U82I<T>];
|
|
32
|
+
difference(other: Iterable<T>): U82I<T>;
|
|
33
|
+
intersection(other: Iterable<T>): U82I<T>;
|
|
34
|
+
union(other: Iterable<T>): U82I<T>;
|
|
35
|
+
symmetricDifference(other: Iterable<T>): U82I<T>;
|
|
36
|
+
take(count: N): U82I<T>;
|
|
37
|
+
takeLast(count: N): U82I<T>;
|
|
38
|
+
drop(count: N): U82I<T>;
|
|
39
|
+
dropLast(count: N): U82I<T>;
|
|
40
|
+
pluck<K extends keyof T>(key: K): U82I<T[K]>;
|
|
41
|
+
flattenDeep(): U82I<A>;
|
|
42
|
+
insert(index: N, ...items: T[]): this;
|
|
43
|
+
removeAt(index: N): T | undefined;
|
|
44
|
+
remove(value: T): boolean;
|
|
45
|
+
removeWhere(predicate: (value: T, index: N, array: T[]) => unknown): this;
|
|
46
|
+
replace(oldValue: T, newValue: T): boolean;
|
|
47
|
+
move(from: N, to: N): this;
|
|
48
|
+
swap(i: N, j: N): this;
|
|
49
|
+
shuffleInPlace(): this;
|
|
50
|
+
pick(count?: N): U82I<T>;
|
|
51
|
+
toSet(): Set<T>;
|
|
52
|
+
toMap<K extends PropertyKey>(keyFn: (value: T, index: N) => K): Map<K, T>;
|
|
53
|
+
equals(other: readonly T[]): boolean;
|
|
54
|
+
startsWith(other: readonly T[]): boolean;
|
|
55
|
+
endsWith(other: readonly T[]): boolean;
|
|
56
|
+
isSorted(compareFn?: (a: T, b: T) => N): boolean;
|
|
57
|
+
frequencies(): Map<T, N>;
|
|
58
|
+
findLast<S extends T>(predicate: (value: T, index: N, obj: T[]) => value is S, thisArg?: A): S | undefined;
|
|
59
|
+
findLastIndex(predicate: (value: T, index: N, obj: T[]) => unknown, thisArg?: A): N;
|
|
60
|
+
toReversed(): T[];
|
|
61
|
+
toSorted(compareFn?: (a: T, b: T) => N): T[];
|
|
62
|
+
toSpliced(start: N, deleteCount: N, ...items: T[]): T[];
|
|
63
|
+
with(index: N, value: T): T[];
|
|
64
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare class USP2I extends URLSearchParams implements USP2 {
|
|
2
|
+
constructor(init?: S | URLSearchParams | R<S, S> | S[][]);
|
|
3
|
+
get size(): N;
|
|
4
|
+
getOr(name: S, fallback: S): S;
|
|
5
|
+
getOrNull(name: S): S | NU;
|
|
6
|
+
getOrThrow(name: S, error?: A): string;
|
|
7
|
+
getNumber(name: S, fallback?: N): N | UD;
|
|
8
|
+
getInt(name: S, radix?: N): N | UD;
|
|
9
|
+
getFloat(name: S): N | UD;
|
|
10
|
+
getBoolean(name: S, fallback?: boolean): B;
|
|
11
|
+
getJSON<T = A>(name: S): T | UD;
|
|
12
|
+
getArray(name: S, separator?: string): S[];
|
|
13
|
+
getObject<T extends R<S, A> = R<S, A>>(): T;
|
|
14
|
+
setNumber(name: S, value: N): this;
|
|
15
|
+
setBoolean(name: S, value: B): this;
|
|
16
|
+
setJSON(name: S, value: A): this;
|
|
17
|
+
setArray(name: S, values: Iterable<A>, separator?: string): this;
|
|
18
|
+
setIfAbsent(name: S, value: S): this;
|
|
19
|
+
setIfPresent(name: S, value: S): this;
|
|
20
|
+
appendAll(params: URLSearchParams | R<S, A>): this;
|
|
21
|
+
merge(params: URLSearchParams | R<S, A>, overwrite?: boolean): this;
|
|
22
|
+
clone(): USP2I;
|
|
23
|
+
clear(): V;
|
|
24
|
+
isEmpty(): B;
|
|
25
|
+
isNotEmpty(): B;
|
|
26
|
+
toObject(): R<S, S | S[]>;
|
|
27
|
+
toJSON(): R<S, S | S[]>;
|
|
28
|
+
toURLSearchParams(): URLSearchParams;
|
|
29
|
+
toURL(url: S | URL): URL;
|
|
30
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare class WM2I<H extends WeakKey = A, T = A> extends WeakMap<H, T> implements WM2<H, T> {
|
|
2
|
+
g: (key: H) => T | undefined;
|
|
3
|
+
h: (key: H) => boolean;
|
|
4
|
+
d: (key: H) => boolean;
|
|
5
|
+
private _tracked?;
|
|
6
|
+
s(k: H, v: T | (() => T)): this;
|
|
7
|
+
swap(key: H, value: T): T | UD;
|
|
8
|
+
take(key: H): T | UD;
|
|
9
|
+
getAndDelete(key: H): T | UD;
|
|
10
|
+
peek(key: H): T | false;
|
|
11
|
+
getOrI(key: H, value: T): T;
|
|
12
|
+
getOrM(key: H, make: () => T): T;
|
|
13
|
+
getOr<G>(key: H, fallback: G): T | G;
|
|
14
|
+
getOrThrow(key: H, error?: Error): T;
|
|
15
|
+
getOrCreate(key: H, make: () => T): T;
|
|
16
|
+
ensure(key: H, make: () => T): T;
|
|
17
|
+
update(key: H, fn: (old: T, has: B) => T, initial: T): T;
|
|
18
|
+
setIfAbsent(key: H, value: T): B;
|
|
19
|
+
setIfPresent(key: H, value: T): B;
|
|
20
|
+
hasOrSet(key: H, value: T): B;
|
|
21
|
+
replace(key: H, value: T): B;
|
|
22
|
+
touch(key: H): B;
|
|
23
|
+
get tracked(): B;
|
|
24
|
+
get trackedSize(): N;
|
|
25
|
+
track(key: H): this;
|
|
26
|
+
untrack(key: H): B;
|
|
27
|
+
trackedKeys(): AR<H>;
|
|
28
|
+
trackedValues(): AR<T>;
|
|
29
|
+
trackedEntries(): AR<[H, T]>;
|
|
30
|
+
forEachTracked(fn: (value: T, key: H, map: this) => void): void;
|
|
31
|
+
clearTracked(): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class WS2I<T extends WeakKey = A> extends WeakSet<T> implements WS2<T> {
|
|
2
|
+
private readonly _tracked;
|
|
3
|
+
constructor(values?: readonly T[] | Iterable<T> | null);
|
|
4
|
+
add(value: T): this;
|
|
5
|
+
delete(value: T): boolean;
|
|
6
|
+
has(value: T): boolean;
|
|
7
|
+
addIfAbsent(value: T): boolean;
|
|
8
|
+
toggle(value: T): boolean;
|
|
9
|
+
deleteIfPresent(value: T): boolean;
|
|
10
|
+
hasAll(values: Iterable<T>): boolean;
|
|
11
|
+
hasAny(values: Iterable<T>): boolean;
|
|
12
|
+
addAll(values: Iterable<T>): this;
|
|
13
|
+
deleteAll(values: Iterable<T>): N;
|
|
14
|
+
replace(oldValue: T, newValue: T): boolean;
|
|
15
|
+
track(value: T): this;
|
|
16
|
+
untrack(value: T): boolean;
|
|
17
|
+
trackedKeys(): T[];
|
|
18
|
+
forEachTracked(callback: (value: T, set: this) => void, thisArg?: A): void;
|
|
19
|
+
clearTracked(): void;
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-w1zard/dx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
9
|
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
9
11
|
"default": "./dist/index.js",
|
|
10
|
-
"
|
|
12
|
+
"import": "./dist/index.js"
|
|
11
13
|
}
|
|
12
14
|
},
|
|
13
15
|
"files": [
|
|
14
16
|
"dist",
|
|
15
|
-
"
|
|
17
|
+
"src"
|
|
16
18
|
],
|
|
17
19
|
"scripts": {
|
|
18
20
|
"1": "git add .",
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
"4": "npm version patch",
|
|
22
24
|
"5": "git push --tags",
|
|
23
25
|
"6": "npm publish --access public",
|
|
24
|
-
"build": "rspack build",
|
|
26
|
+
"build": "tsc --emitDeclarationOnly && rspack build",
|
|
25
27
|
"dev": "rspack serve",
|
|
26
28
|
"check": "tsc --noEmit",
|
|
27
29
|
"*": "npm run 1 && npm run 2 && npm run 3 && npm run 4 && npm run 5 && npm run 6 && npm run *"
|
|
@@ -30,15 +32,15 @@
|
|
|
30
32
|
"@rspack/cli": "^2.3.1",
|
|
31
33
|
"@rspack/core": "^2.3.1",
|
|
32
34
|
"@rspack/dev-server": "^2.2.2",
|
|
35
|
+
"@the-w1zard/alias_types": "^1.0.3",
|
|
33
36
|
"@tsconfig/node-lts": "^24.0.0",
|
|
34
37
|
"@types/node": "^24.0.0",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
38
|
+
"jsrepo": "^3.8.3",
|
|
39
|
+
"typescript": "^6.0.0"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
39
42
|
"@babel/parser": "^8.1.0",
|
|
40
43
|
"@babel/traverse": "^8.1.0",
|
|
41
|
-
"@babel/types": "^8.1.0"
|
|
42
|
-
"@the-w1zard/alias_types": "^1.0.2"
|
|
44
|
+
"@babel/types": "^8.1.0"
|
|
43
45
|
}
|
|
44
46
|
}
|
package/src/array.ts
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export class A2I<T = A> extends Array<T> implements A2<T> {
|
|
4
|
+
constructor(...items: T[]) {
|
|
5
|
+
super(...items);
|
|
6
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static get [Symbol.species](): ArrayConstructor {
|
|
10
|
+
return Array;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static from<T>(arrayLike: ArrayLike<T> | Iterable<T>): A2<T> {
|
|
14
|
+
return new A2I<T>(...Array.from(arrayLike));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static of<T>(...items: T[]): A2<T> {
|
|
18
|
+
return new A2I<T>(...items);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
first(): T | UD {
|
|
22
|
+
return this[0];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
last(): T | UD {
|
|
26
|
+
return this[this.length - 1];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
isEmpty(): B {
|
|
30
|
+
return this.length === 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
isNotEmpty(): B {
|
|
34
|
+
return this.length !== 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
clear(): this {
|
|
38
|
+
this.length = 0;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clone(): A2<T> {
|
|
43
|
+
return new A2I<T>(...this);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
unique(): A2<T> {
|
|
47
|
+
return new A2I<T>(...new Set(this));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
compact(): A2<NonNullable<T>> {
|
|
51
|
+
return new A2<NonNullable<T>>(
|
|
52
|
+
...this.filter((value): value is NonNullable<T> => value != null)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
take(count: N): A2<T> {
|
|
57
|
+
return new A2I<T>(...this.slice(0, Math.max(0, count)));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
takeLast(count: N): A2<T> {
|
|
61
|
+
return new A2I<T>(...this.slice(Math.max(0, this.length - Math.max(0, count))));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
drop(count: N): A2<T> {
|
|
65
|
+
return new A2I<T>(...this.slice(Math.max(0, count)));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
dropLast(count: N): A2<T> {
|
|
69
|
+
return new A2I<T>(...this.slice(0, Math.max(0, this.length - Math.max(0, count))));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
chunk(size: N): A2<A2<T>> {
|
|
73
|
+
if (!Number.isInteger(size) || size < 1) {
|
|
74
|
+
throw new RangeError("Chunk size must be a positive integer.");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const result = new A2<A2<T>>();
|
|
78
|
+
|
|
79
|
+
for (let i = 0; i < this.length; i += size) {
|
|
80
|
+
result.push(new A2I<T>(...this.slice(i, i + size)));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
flatten<X>(depth: N = Infinity): A2<X> {
|
|
87
|
+
return new A2<X>(...this.flat(depth) as X[]);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
flatMap<U>(callback: (value: T, index: N, array: this) => U | readonly U[]): A2<U> {
|
|
91
|
+
return new A2<U>(
|
|
92
|
+
...this.flatMap((value, index) => callback(value, index as N, this))
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
distinctBy<K>(callback: (value: T, index: N) => K): A2<T> {
|
|
97
|
+
const seen = new Set<K>();
|
|
98
|
+
const result = new A2I<T>();
|
|
99
|
+
|
|
100
|
+
this.forEach((value, index) => {
|
|
101
|
+
const key = callback(value, index as N);
|
|
102
|
+
|
|
103
|
+
if (!seen.has(key)) {
|
|
104
|
+
seen.add(key);
|
|
105
|
+
result.push(value);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
groupBy<K extends PropertyKey>(callback: (value: T, index: N) => K): Map<K, A2<T>> {
|
|
113
|
+
const result = new Map<K, A2<T>>();
|
|
114
|
+
|
|
115
|
+
this.forEach((value, index) => {
|
|
116
|
+
const key = callback(value, index as N);
|
|
117
|
+
let group = result.get(key);
|
|
118
|
+
|
|
119
|
+
if (!group) {
|
|
120
|
+
group = new A2I<T>();
|
|
121
|
+
result.set(key, group);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
group.push(value);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
partition(callback: (value: T, index: N) => B): [A2<T>, A2<T>] {
|
|
131
|
+
const yes = new A2I<T>();
|
|
132
|
+
const no = new A2I<T>();
|
|
133
|
+
|
|
134
|
+
this.forEach((value, index) => {
|
|
135
|
+
(callback(value, index as N) ? yes : no).push(value);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return [yes, no];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
insert(index: N, ...items: T[]): this {
|
|
142
|
+
this.splice(index, 0, ...items);
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
removeAt(index: N): T | UD {
|
|
147
|
+
const normalized = index < 0 ? this.length + index : index;
|
|
148
|
+
|
|
149
|
+
if (normalized < 0 || normalized >= this.length) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return this.splice(normalized, 1)[0];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
remove(value: T): B {
|
|
157
|
+
const index = this.indexOf(value);
|
|
158
|
+
|
|
159
|
+
if (index === -1) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this.splice(index, 1);
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
removeAll(value: T): N {
|
|
168
|
+
let removed = 0;
|
|
169
|
+
|
|
170
|
+
for (let i = this.length - 1; i >= 0; i--) {
|
|
171
|
+
if (Object.is(this[i], value)) {
|
|
172
|
+
this.splice(i, 1);
|
|
173
|
+
removed++;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return removed as N;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
replaceAt(index: N, value: T): T | UD {
|
|
181
|
+
const normalized = index < 0 ? this.length + index : index;
|
|
182
|
+
|
|
183
|
+
if (normalized < 0 || normalized >= this.length) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const previous = this[normalized];
|
|
188
|
+
this[normalized] = value;
|
|
189
|
+
return previous;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
move(from: N, to: N): this {
|
|
193
|
+
const source = from < 0 ? this.length + from : from;
|
|
194
|
+
const target = to < 0 ? this.length + to : to;
|
|
195
|
+
|
|
196
|
+
if (
|
|
197
|
+
source < 0 || source >= this.length ||
|
|
198
|
+
target < 0 || target >= this.length ||
|
|
199
|
+
source === target
|
|
200
|
+
) {
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const [item] = this.splice(source, 1);
|
|
205
|
+
this.splice(target, 0, item);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
swap(first: N, second: N): this {
|
|
210
|
+
const a = first < 0 ? this.length + first : first;
|
|
211
|
+
const b = second < 0 ? this.length + second : second;
|
|
212
|
+
|
|
213
|
+
if (
|
|
214
|
+
a < 0 || a >= this.length ||
|
|
215
|
+
b < 0 || b >= this.length
|
|
216
|
+
) {
|
|
217
|
+
return this;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
[this[a], this[b]] = [this[b], this[a]];
|
|
221
|
+
return this;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
sample(): T | UD {
|
|
225
|
+
if (this.length === 0) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return this[Math.floor(Math.random() * this.length)];
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
shuffle(): this {
|
|
233
|
+
for (let i = this.length - 1; i > 0; i--) {
|
|
234
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
235
|
+
[this[i], this[j]] = [this[j], this[i]];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
countBy(callback: (value: T, index: N) => B): N {
|
|
242
|
+
let count = 0;
|
|
243
|
+
|
|
244
|
+
this.forEach((value, index) => {
|
|
245
|
+
if (callback(value, index as N)) count++;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return count as N;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
sum(callback?: (value: T, index: N) => N): N {
|
|
252
|
+
let total = 0;
|
|
253
|
+
|
|
254
|
+
this.forEach((value, index) => {
|
|
255
|
+
total += callback ? callback(value, index as N) : Number(value);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
return total as N;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
average(callback?: (value: T, index: N) => N): N {
|
|
262
|
+
return (this.length === 0 ? NaN : this.sum(callback) / this.length) as N;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
min(callback?: (value: T, index: N) => N): T | UD {
|
|
266
|
+
if (this.length === 0) return undefined;
|
|
267
|
+
|
|
268
|
+
return this.reduce((best, value, index) => {
|
|
269
|
+
const current = callback ? callback(value, index as N) : Number(value);
|
|
270
|
+
const bestValue = callback ? callback(best, this.indexOf(best) as N) : Number(best);
|
|
271
|
+
|
|
272
|
+
return current < bestValue ? value : best;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
max(callback?: (value: T, index: N) => N): T | UD {
|
|
277
|
+
if (this.length === 0) return undefined;
|
|
278
|
+
|
|
279
|
+
return this.reduce((best, value, index) => {
|
|
280
|
+
const current = callback ? callback(value, index as N) : Number(value);
|
|
281
|
+
const bestValue = callback ? callback(best, this.indexOf(best) as N) : Number(best);
|
|
282
|
+
|
|
283
|
+
return current > bestValue ? value : best;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
equals(array: readonly T[]): B {
|
|
288
|
+
return this.length === array.length &&
|
|
289
|
+
this.every((value, index) => Object.is(value, array[index]));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
includesAll(values: readonly T[]): B {
|
|
293
|
+
return values.every(value => this.includes(value));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
intersects(values: readonly T[]): B {
|
|
297
|
+
return values.some(value => this.includes(value));
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
globalThis.A2 = A2I;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* ==========================================================================================================================
|
|
2
|
+
SITH - PURE BINARY BYTE_BOOL
|
|
3
|
+
Replaces boolean properties and boolean maps with a zero-allocation, PID-indexed Uint8Array lane.
|
|
4
|
+
================================================================================================================ ⇦✦──⇦✦──✦──✦──← 'pew pew' 🧙 [BYTE_BOOL] */
|
|
5
|
+
|
|
6
|
+
export class B2BI {
|
|
7
|
+
public readonly flags: Uint8Array;
|
|
8
|
+
constructor(maxParticles: number = 8192) {
|
|
9
|
+
this.flags = new Uint8Array(maxParticles);
|
|
10
|
+
}/** Set a boolean flag for a PID. O(1) time complexity. */
|
|
11
|
+
public set(pid: number, value: boolean): void { this.flags[pid] = value ? 1 : 0; }
|
|
12
|
+
public true(pid: number, value: boolean) { this.flags[pid] = 1 }
|
|
13
|
+
public false(pid: number, value: boolean) { this.flags[pid] = 0 }
|
|
14
|
+
/** Get the boolean state for a PID. O(1) time complexity. */
|
|
15
|
+
public get(pid: number): boolean { return this.flags[pid] === 1; }
|
|
16
|
+
/** Toggle the boolean state for a PID. O(1) time complexity. */
|
|
17
|
+
public toggle(pid: number): boolean {
|
|
18
|
+
this.flags[pid] = this.flags[pid] === 1 ? 0 : 1;
|
|
19
|
+
return this.flags[pid] === 1;
|
|
20
|
+
}/** Clear all flags instantly without reallocating memory. */
|
|
21
|
+
public clear(): void { this.flags.fill(0); }
|
|
22
|
+
}
|
|
23
|
+
globalThis.B2B = B2BI;
|
package/src/class.ts
ADDED
|
File without changes
|