@the-w1zard/dx 1.0.11 → 1.0.13
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/index.js +4 -3
- package/package.json +2 -2
- 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 +7 -1
- package/src/error.ts +81 -0
- package/src/index.ts +45 -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 +27 -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/index.js
CHANGED
|
@@ -861,7 +861,7 @@ function date_wrap_native_super(Class) {
|
|
|
861
861
|
return date_wrap_native_super(Class);
|
|
862
862
|
}
|
|
863
863
|
var DATE_TAG = 0x4432; // "D2"
|
|
864
|
-
var D2_CODEC = {
|
|
864
|
+
var D2_CODEC = (/* unused pure expression or super */ null && ({
|
|
865
865
|
tag: DATE_TAG,
|
|
866
866
|
test: function test(v) {
|
|
867
867
|
return date_instanceof1(v, Date);
|
|
@@ -872,7 +872,7 @@ var D2_CODEC = {
|
|
|
872
872
|
dec: function dec(ms) {
|
|
873
873
|
return new date_D2I(ms);
|
|
874
874
|
}
|
|
875
|
-
};
|
|
875
|
+
}));
|
|
876
876
|
var FORMAT = {
|
|
877
877
|
full: {
|
|
878
878
|
weekday: "short",
|
|
@@ -14166,4 +14166,5 @@ globalThis.WS2 = weak_set_WS2I;
|
|
|
14166
14166
|
|
|
14167
14167
|
|
|
14168
14168
|
|
|
14169
|
-
|
|
14169
|
+
|
|
14170
|
+
export { RECC2 as RECC, array_A2I as A2, boolean_byte_B2BI as B2B, date_D2I as D2, date_R2I as R2, date_R2II as R2I, error_ER2I as ER2, iterator_I2I as I2, map_M2I as M2, map_byte_M2BI as M2B, number_N2I as N2, object_O2I as O2, promise_P2I as P2, reg_ex_REC2 as REC, set_SET2I as SET2, set_byte_SET2BI as SET2B, soa_codec_SOA_CODEC as SOA_CODEC, string_S2I as S2, unit8array_U82I as U82, url_search_params_USP2I as USP2, weak_map_WM2I as WM2, weak_set_WS2I as WS2 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@the-w1zard/dx",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
15
|
-
"
|
|
15
|
+
"src"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"1": "git add .",
|
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
|