@the-w1zard/dx 1.0.8 → 1.0.10

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,28 +1,44 @@
1
1
  {
2
- "name": "@the-w1zard/dx",
3
- "version": "1.0.8",
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": "^1.0.2"
27
- }
2
+ "name": "@the-w1zard/dx",
3
+ "version": "1.0.10",
4
+ "sideEffects": false,
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "default": "./dist/index.js",
10
+ "types": "./src/dx.d.ts"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist",
15
+ "./src/dx.d.ts"
16
+ ],
17
+ "scripts": {
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 *"
28
+ },
29
+ "devDependencies": {
30
+ "@rspack/cli": "^2.3.1",
31
+ "@rspack/core": "^2.3.1",
32
+ "@rspack/dev-server": "^2.2.2",
33
+ "@tsconfig/node-lts": "^24.0.0",
34
+ "@types/node": "^24.0.0",
35
+ "typescript": "^6.0.0",
36
+ "jsrepo": "^3.8.3"
37
+ },
38
+ "dependencies": {
39
+ "@babel/parser": "^8.1.0",
40
+ "@babel/traverse": "^8.1.0",
41
+ "@babel/types": "^8.1.0",
42
+ "@the-w1zard/alias_types": "^1.0.2"
43
+ }
28
44
  }
package/src/dx.d.ts CHANGED
@@ -29,11 +29,14 @@ declare global {
29
29
  ================================================================================== ⇦✦──⇦✦──✦──✦──← 'pew pew' 🧙 [UX/DX] */
30
30
  type MaybePromise<R = any> = R;
31
31
  var MaybePromise: MaybePromise;
32
- var B2B: typeof B2BI; // map
32
+ var B2B: typeof B2BI; // BOOLEAN BINARY
33
+
33
34
  var M2: typeof M2I; // map
34
35
  var M2B: typeof M2BI; // map
36
+
35
37
  var SET2: typeof SET2I; // set
36
38
  var SET2B: typeof SET2BI; // set
39
+
37
40
  var D2: typeof D2I; // Date
38
41
  var A2: typeof A2I; // Array
39
42
  var O2: typeof O2I; // Object
@@ -130,7 +133,9 @@ declare global {
130
133
  clone(): this;
131
134
  equals(other: Map<H, T>): B;
132
135
  }
136
+ interface M2B<H = A, T = A> extends M2<H, T> {}
133
137
  interface M2I<H = A, T = A> extends M2<H, T> {}
138
+ interface M2BI<H = A, T = A> extends M2B<H, T> {}
134
139
  interface B2B {
135
140
  set(pid: number, value: boolean): void
136
141
  true(pid: number, value: boolean)
@@ -455,13 +460,11 @@ declare global {
455
460
  interface D2 extends Date {
456
461
  clone(): D2;
457
462
  isValid(): B;
458
-
459
463
  month(): N;
460
464
  dateOfWeek(): N;
461
465
  dayOfYear(): N;
462
466
  quarter(): N;
463
467
  unix(): N;
464
-
465
468
  addMs(ms: N): D2;
466
469
  addSeconds(seconds: N): D2;
467
470
  addMinutes(minutes: N): D2;
@@ -470,11 +473,9 @@ declare global {
470
473
  addWeeks(weeks: N): D2;
471
474
  addMonths(months: N): D2;
472
475
  addYears(years: N): D2;
473
-
474
476
  subDays(days: N): D2;
475
477
  subMonths(months: N): D2;
476
478
  subYears(years: N): D2;
477
-
478
479
  startOfDay(): D2;
479
480
  endOfDay(): D2;
480
481
  startOfWeek(): D2;
@@ -485,33 +486,27 @@ declare global {
485
486
  endOfQuarter(): D2;
486
487
  startOfYear(): D2;
487
488
  endOfYear(): D2;
488
-
489
489
  daysInMonth(): N;
490
490
  daysInYear(): N;
491
491
  isLeapYear(): B;
492
492
  isWeekend(): B;
493
493
  isWeekday(): B;
494
-
495
494
  isBefore(date: D): B;
496
495
  isAfter(date: D): B;
497
496
  isEqual(date: D): B;
498
497
  isBetween(start: D, end: D): B;
499
-
500
498
  diffMs(date: D): N;
501
499
  diffSeconds(date: D): N;
502
500
  diffMinutes(date: D): N;
503
501
  diffHours(date: D): N;
504
502
  diffDays(date: D): N;
505
-
506
503
  sameDay(date: D): B;
507
504
  sameMonth(date: D): B;
508
505
  sameYear(date: D): B;
509
-
510
506
  toUnixMs(): N;
511
507
  toUnix(): N;
512
508
  toD2(): D2;
513
509
  toLocalString(format?: A): S;
514
-
515
510
  subWeeks(weeks: N): D2;
516
511
  endOfWeek(weekStartsOn?: N): D2;
517
512
  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;
@@ -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;