@the-w1zard/dx 0.0.0-stage → 1.0.7

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/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@the-w1zard/dx",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.7",
4
+ "sideEffects": false,
5
+ "type": "module",
6
+ "main": "./src/index.ts",
7
+ "exports": {
8
+ ".": {
9
+ "default": "./src/index.ts",
10
+ "types": "./src/dx.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "src"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "check": "tsc --noEmit"
19
+ },
20
+ "devDependencies": {
21
+ "@tsconfig/node-lts": "^24.0.0",
22
+ "@types/node": "^24.0.0",
23
+ "typescript": "^6.0.0"
24
+ },
25
+ "dependencies": {
26
+ "@the-w1zard/alias_types": "https://raw.githubusercontent.com/the-w1zard/.github/refs/heads/main/libraries/the-w1zard-alias_types-1.0.0.tgz"
27
+ }
28
+ }
package/src/array.js ADDED
@@ -0,0 +1,221 @@
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 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,22 @@
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;
@@ -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.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";
package/src/class.ts ADDED
File without changes