@the-w1zard/dx 1.0.7 → 1.0.9
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/README.html +823 -121
- package/README.md +288 -107
- package/dist/index.js +12967 -0
- package/package.json +22 -7
- package/src/dx.d.ts +2 -10
- package/src/array.js +0 -221
- package/src/array.ts +0 -301
- package/src/boolean_byte.js +0 -22
- package/src/boolean_byte.ts +0 -23
- package/src/class.js +0 -1
- package/src/class.ts +0 -0
- package/src/date.js +0 -649
- package/src/date.ts +0 -660
- package/src/error.js +0 -60
- package/src/error.ts +0 -81
- package/src/index.js +0 -18
- package/src/index.ts +0 -18
- package/src/iterator.js +0 -386
- package/src/iterator.ts +0 -407
- package/src/map.js +0 -495
- package/src/map.ts +0 -513
- package/src/map_byte.js +0 -483
- package/src/map_byte.ts +0 -422
- package/src/number.js +0 -178
- package/src/number.ts +0 -212
- package/src/object.js +0 -217
- package/src/object.ts +0 -291
- package/src/promise.js +0 -206
- package/src/promise.ts +0 -309
- package/src/reg_ex.js +0 -479
- package/src/reg_ex.ts +0 -423
- package/src/set.js +0 -227
- package/src/set.ts +0 -198
- package/src/set_byte.js +0 -261
- package/src/set_byte.ts +0 -223
- package/src/soa_codec.js +0 -28
- package/src/soa_codec.ts +0 -27
- package/src/string.js +0 -133
- package/src/string.ts +0 -175
- package/src/unit8array.js +0 -272
- package/src/unit8array.ts +0 -374
- package/src/url_search_params.js +0 -172
- package/src/url_search_params.ts +0 -187
- package/src/weak_map.js +0 -136
- package/src/weak_map.ts +0 -155
- package/src/weak_set.js +0 -92
- package/src/weak_set.ts +0 -101
package/package.json
CHANGED
|
@@ -1,28 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-w1zard/dx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"default": "./
|
|
9
|
+
"default": "./dist/index.js",
|
|
10
10
|
"types": "./src/dx.d.ts"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
|
-
"
|
|
14
|
+
"dist",
|
|
15
|
+
"./src/dx.d.ts"
|
|
15
16
|
],
|
|
16
17
|
"scripts": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
18
|
+
"1": "git add .",
|
|
19
|
+
"2": "git commit -m 'first commit'",
|
|
20
|
+
"3": "git push",
|
|
21
|
+
"4": "npm version patch",
|
|
22
|
+
"5": "git push --tags",
|
|
23
|
+
"6": "npm publish --access public",
|
|
24
|
+
"build": "rspack build",
|
|
25
|
+
"dev": "rspack serve",
|
|
26
|
+
"check": "tsc --noEmit",
|
|
27
|
+
"*": "npm run 1 && npm run 2 && npm run 3 && npm run 4 && npm run 5 && npm run 6 && npm run *"
|
|
19
28
|
},
|
|
20
29
|
"devDependencies": {
|
|
30
|
+
"@rspack/cli": "^2.3.1",
|
|
31
|
+
"@rspack/core": "^2.3.1",
|
|
32
|
+
"@rspack/dev-server": "^2.2.2",
|
|
21
33
|
"@tsconfig/node-lts": "^24.0.0",
|
|
22
34
|
"@types/node": "^24.0.0",
|
|
23
35
|
"typescript": "^6.0.0"
|
|
24
36
|
},
|
|
25
37
|
"dependencies": {
|
|
26
|
-
"@
|
|
38
|
+
"@babel/parser": "^8.1.0",
|
|
39
|
+
"@babel/traverse": "^8.1.0",
|
|
40
|
+
"@babel/types": "^8.1.0",
|
|
41
|
+
"@the-w1zard/alias_types": "^1.0.2"
|
|
27
42
|
}
|
|
28
43
|
}
|
package/src/dx.d.ts
CHANGED
|
@@ -130,7 +130,9 @@ declare global {
|
|
|
130
130
|
clone(): this;
|
|
131
131
|
equals(other: Map<H, T>): B;
|
|
132
132
|
}
|
|
133
|
+
interface M2B<H = A, T = A> extends M2<H, T> {}
|
|
133
134
|
interface M2I<H = A, T = A> extends M2<H, T> {}
|
|
135
|
+
interface M2BI<H = A, T = A> extends M2B<H, T> {}
|
|
134
136
|
interface B2B {
|
|
135
137
|
set(pid: number, value: boolean): void
|
|
136
138
|
true(pid: number, value: boolean)
|
|
@@ -455,13 +457,11 @@ declare global {
|
|
|
455
457
|
interface D2 extends Date {
|
|
456
458
|
clone(): D2;
|
|
457
459
|
isValid(): B;
|
|
458
|
-
|
|
459
460
|
month(): N;
|
|
460
461
|
dateOfWeek(): N;
|
|
461
462
|
dayOfYear(): N;
|
|
462
463
|
quarter(): N;
|
|
463
464
|
unix(): N;
|
|
464
|
-
|
|
465
465
|
addMs(ms: N): D2;
|
|
466
466
|
addSeconds(seconds: N): D2;
|
|
467
467
|
addMinutes(minutes: N): D2;
|
|
@@ -470,11 +470,9 @@ declare global {
|
|
|
470
470
|
addWeeks(weeks: N): D2;
|
|
471
471
|
addMonths(months: N): D2;
|
|
472
472
|
addYears(years: N): D2;
|
|
473
|
-
|
|
474
473
|
subDays(days: N): D2;
|
|
475
474
|
subMonths(months: N): D2;
|
|
476
475
|
subYears(years: N): D2;
|
|
477
|
-
|
|
478
476
|
startOfDay(): D2;
|
|
479
477
|
endOfDay(): D2;
|
|
480
478
|
startOfWeek(): D2;
|
|
@@ -485,33 +483,27 @@ declare global {
|
|
|
485
483
|
endOfQuarter(): D2;
|
|
486
484
|
startOfYear(): D2;
|
|
487
485
|
endOfYear(): D2;
|
|
488
|
-
|
|
489
486
|
daysInMonth(): N;
|
|
490
487
|
daysInYear(): N;
|
|
491
488
|
isLeapYear(): B;
|
|
492
489
|
isWeekend(): B;
|
|
493
490
|
isWeekday(): B;
|
|
494
|
-
|
|
495
491
|
isBefore(date: D): B;
|
|
496
492
|
isAfter(date: D): B;
|
|
497
493
|
isEqual(date: D): B;
|
|
498
494
|
isBetween(start: D, end: D): B;
|
|
499
|
-
|
|
500
495
|
diffMs(date: D): N;
|
|
501
496
|
diffSeconds(date: D): N;
|
|
502
497
|
diffMinutes(date: D): N;
|
|
503
498
|
diffHours(date: D): N;
|
|
504
499
|
diffDays(date: D): N;
|
|
505
|
-
|
|
506
500
|
sameDay(date: D): B;
|
|
507
501
|
sameMonth(date: D): B;
|
|
508
502
|
sameYear(date: D): B;
|
|
509
|
-
|
|
510
503
|
toUnixMs(): N;
|
|
511
504
|
toUnix(): N;
|
|
512
505
|
toD2(): D2;
|
|
513
506
|
toLocalString(format?: A): S;
|
|
514
|
-
|
|
515
507
|
subWeeks(weeks: N): D2;
|
|
516
508
|
endOfWeek(weekStartsOn?: N): D2;
|
|
517
509
|
at(hour: N, minute?: N, second?: N, ms?: N): D2;
|
package/src/array.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
export class A2I extends Array {
|
|
2
|
-
constructor(...items) {
|
|
3
|
-
super(...items);
|
|
4
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
-
}
|
|
6
|
-
static get [Symbol.species]() {
|
|
7
|
-
return Array;
|
|
8
|
-
}
|
|
9
|
-
static from(arrayLike) {
|
|
10
|
-
return new A2I(...Array.from(arrayLike));
|
|
11
|
-
}
|
|
12
|
-
static of(...items) {
|
|
13
|
-
return new A2I(...items);
|
|
14
|
-
}
|
|
15
|
-
first() {
|
|
16
|
-
return this[0];
|
|
17
|
-
}
|
|
18
|
-
last() {
|
|
19
|
-
return this[this.length - 1];
|
|
20
|
-
}
|
|
21
|
-
isEmpty() {
|
|
22
|
-
return this.length === 0;
|
|
23
|
-
}
|
|
24
|
-
isNotEmpty() {
|
|
25
|
-
return this.length !== 0;
|
|
26
|
-
}
|
|
27
|
-
clear() {
|
|
28
|
-
this.length = 0;
|
|
29
|
-
return this;
|
|
30
|
-
}
|
|
31
|
-
clone() {
|
|
32
|
-
return new A2I(...this);
|
|
33
|
-
}
|
|
34
|
-
unique() {
|
|
35
|
-
return new A2I(...new Set(this));
|
|
36
|
-
}
|
|
37
|
-
compact() {
|
|
38
|
-
return new A2(...this.filter((value) => value != null));
|
|
39
|
-
}
|
|
40
|
-
take(count) {
|
|
41
|
-
return new A2I(...this.slice(0, Math.max(0, count)));
|
|
42
|
-
}
|
|
43
|
-
takeLast(count) {
|
|
44
|
-
return new A2I(...this.slice(Math.max(0, this.length - Math.max(0, count))));
|
|
45
|
-
}
|
|
46
|
-
drop(count) {
|
|
47
|
-
return new A2I(...this.slice(Math.max(0, count)));
|
|
48
|
-
}
|
|
49
|
-
dropLast(count) {
|
|
50
|
-
return new A2I(...this.slice(0, Math.max(0, this.length - Math.max(0, count))));
|
|
51
|
-
}
|
|
52
|
-
chunk(size) {
|
|
53
|
-
if (!Number.isInteger(size) || size < 1) {
|
|
54
|
-
throw new RangeError("Chunk size must be a positive integer.");
|
|
55
|
-
}
|
|
56
|
-
const result = new A2();
|
|
57
|
-
for (let i = 0; i < this.length; i += size) {
|
|
58
|
-
result.push(new A2I(...this.slice(i, i + size)));
|
|
59
|
-
}
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
flatten(depth = Infinity) {
|
|
63
|
-
return new A2(...this.flat(depth));
|
|
64
|
-
}
|
|
65
|
-
flatMap(callback) {
|
|
66
|
-
return new A2(...this.flatMap((value, index) => callback(value, index, this)));
|
|
67
|
-
}
|
|
68
|
-
distinctBy(callback) {
|
|
69
|
-
const seen = new Set();
|
|
70
|
-
const result = new A2I();
|
|
71
|
-
this.forEach((value, index) => {
|
|
72
|
-
const key = callback(value, index);
|
|
73
|
-
if (!seen.has(key)) {
|
|
74
|
-
seen.add(key);
|
|
75
|
-
result.push(value);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
groupBy(callback) {
|
|
81
|
-
const result = new Map();
|
|
82
|
-
this.forEach((value, index) => {
|
|
83
|
-
const key = callback(value, index);
|
|
84
|
-
let group = result.get(key);
|
|
85
|
-
if (!group) {
|
|
86
|
-
group = new A2I();
|
|
87
|
-
result.set(key, group);
|
|
88
|
-
}
|
|
89
|
-
group.push(value);
|
|
90
|
-
});
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
partition(callback) {
|
|
94
|
-
const yes = new A2I();
|
|
95
|
-
const no = new A2I();
|
|
96
|
-
this.forEach((value, index) => {
|
|
97
|
-
(callback(value, index) ? yes : no).push(value);
|
|
98
|
-
});
|
|
99
|
-
return [yes, no];
|
|
100
|
-
}
|
|
101
|
-
insert(index, ...items) {
|
|
102
|
-
this.splice(index, 0, ...items);
|
|
103
|
-
return this;
|
|
104
|
-
}
|
|
105
|
-
removeAt(index) {
|
|
106
|
-
const normalized = index < 0 ? this.length + index : index;
|
|
107
|
-
if (normalized < 0 || normalized >= this.length) {
|
|
108
|
-
return undefined;
|
|
109
|
-
}
|
|
110
|
-
return this.splice(normalized, 1)[0];
|
|
111
|
-
}
|
|
112
|
-
remove(value) {
|
|
113
|
-
const index = this.indexOf(value);
|
|
114
|
-
if (index === -1) {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
this.splice(index, 1);
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
removeAll(value) {
|
|
121
|
-
let removed = 0;
|
|
122
|
-
for (let i = this.length - 1; i >= 0; i--) {
|
|
123
|
-
if (Object.is(this[i], value)) {
|
|
124
|
-
this.splice(i, 1);
|
|
125
|
-
removed++;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return removed;
|
|
129
|
-
}
|
|
130
|
-
replaceAt(index, value) {
|
|
131
|
-
const normalized = index < 0 ? this.length + index : index;
|
|
132
|
-
if (normalized < 0 || normalized >= this.length) {
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
const previous = this[normalized];
|
|
136
|
-
this[normalized] = value;
|
|
137
|
-
return previous;
|
|
138
|
-
}
|
|
139
|
-
move(from, to) {
|
|
140
|
-
const source = from < 0 ? this.length + from : from;
|
|
141
|
-
const target = to < 0 ? this.length + to : to;
|
|
142
|
-
if (source < 0 || source >= this.length ||
|
|
143
|
-
target < 0 || target >= this.length ||
|
|
144
|
-
source === target) {
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
const [item] = this.splice(source, 1);
|
|
148
|
-
this.splice(target, 0, item);
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
swap(first, second) {
|
|
152
|
-
const a = first < 0 ? this.length + first : first;
|
|
153
|
-
const b = second < 0 ? this.length + second : second;
|
|
154
|
-
if (a < 0 || a >= this.length ||
|
|
155
|
-
b < 0 || b >= this.length) {
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
[this[a], this[b]] = [this[b], this[a]];
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
sample() {
|
|
162
|
-
if (this.length === 0) {
|
|
163
|
-
return undefined;
|
|
164
|
-
}
|
|
165
|
-
return this[Math.floor(Math.random() * this.length)];
|
|
166
|
-
}
|
|
167
|
-
shuffle() {
|
|
168
|
-
for (let i = this.length - 1; i > 0; i--) {
|
|
169
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
170
|
-
[this[i], this[j]] = [this[j], this[i]];
|
|
171
|
-
}
|
|
172
|
-
return this;
|
|
173
|
-
}
|
|
174
|
-
countBy(callback) {
|
|
175
|
-
let count = 0;
|
|
176
|
-
this.forEach((value, index) => {
|
|
177
|
-
if (callback(value, index))
|
|
178
|
-
count++;
|
|
179
|
-
});
|
|
180
|
-
return count;
|
|
181
|
-
}
|
|
182
|
-
sum(callback) {
|
|
183
|
-
let total = 0;
|
|
184
|
-
this.forEach((value, index) => {
|
|
185
|
-
total += callback ? callback(value, index) : Number(value);
|
|
186
|
-
});
|
|
187
|
-
return total;
|
|
188
|
-
}
|
|
189
|
-
average(callback) {
|
|
190
|
-
return (this.length === 0 ? NaN : this.sum(callback) / this.length);
|
|
191
|
-
}
|
|
192
|
-
min(callback) {
|
|
193
|
-
if (this.length === 0)
|
|
194
|
-
return undefined;
|
|
195
|
-
return this.reduce((best, value, index) => {
|
|
196
|
-
const current = callback ? callback(value, index) : Number(value);
|
|
197
|
-
const bestValue = callback ? callback(best, this.indexOf(best)) : Number(best);
|
|
198
|
-
return current < bestValue ? value : best;
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
max(callback) {
|
|
202
|
-
if (this.length === 0)
|
|
203
|
-
return undefined;
|
|
204
|
-
return this.reduce((best, value, index) => {
|
|
205
|
-
const current = callback ? callback(value, index) : Number(value);
|
|
206
|
-
const bestValue = callback ? callback(best, this.indexOf(best)) : Number(best);
|
|
207
|
-
return current > bestValue ? value : best;
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
equals(array) {
|
|
211
|
-
return this.length === array.length &&
|
|
212
|
-
this.every((value, index) => Object.is(value, array[index]));
|
|
213
|
-
}
|
|
214
|
-
includesAll(values) {
|
|
215
|
-
return values.every(value => this.includes(value));
|
|
216
|
-
}
|
|
217
|
-
intersects(values) {
|
|
218
|
-
return values.some(value => this.includes(value));
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
globalThis.A2 = A2I;
|
package/src/array.ts
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
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;
|
package/src/boolean_byte.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
export class B2BI {
|
|
6
|
-
flags;
|
|
7
|
-
constructor(maxParticles = 8192) {
|
|
8
|
-
this.flags = new Uint8Array(maxParticles);
|
|
9
|
-
} /** Set a boolean flag for a PID. O(1) time complexity. */
|
|
10
|
-
set(pid, value) { this.flags[pid] = value ? 1 : 0; }
|
|
11
|
-
true(pid, value) { this.flags[pid] = 1; }
|
|
12
|
-
false(pid, value) { this.flags[pid] = 0; }
|
|
13
|
-
/** Get the boolean state for a PID. O(1) time complexity. */
|
|
14
|
-
get(pid) { return this.flags[pid] === 1; }
|
|
15
|
-
/** Toggle the boolean state for a PID. O(1) time complexity. */
|
|
16
|
-
toggle(pid) {
|
|
17
|
-
this.flags[pid] = this.flags[pid] === 1 ? 0 : 1;
|
|
18
|
-
return this.flags[pid] === 1;
|
|
19
|
-
} /** Clear all flags instantly without reallocating memory. */
|
|
20
|
-
clear() { this.flags.fill(0); }
|
|
21
|
-
}
|
|
22
|
-
globalThis.B2B = B2BI;
|
package/src/boolean_byte.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/src/class.ts
DELETED
|
File without changes
|