@the-w1zard/dx 1.0.8 → 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/src/error.js DELETED
@@ -1,60 +0,0 @@
1
- export class ER2I extends Error {
2
- constructor(message = "", options) {
3
- super(message, options);
4
- this.name = new.target.name;
5
- Object.setPrototypeOf(this, new.target.prototype);
6
- }
7
- clone() {
8
- const error = new ER2I(this.message, { cause: this.cause });
9
- error.name = this.name;
10
- error.stack = this.stack;
11
- return error;
12
- }
13
- toJSON() {
14
- return {
15
- name: this.name,
16
- message: this.message,
17
- stack: this.stack,
18
- cause: this.cause,
19
- };
20
- }
21
- toString() {
22
- return `${this.name}: ${this.message}`;
23
- }
24
- static is(value) {
25
- return value instanceof Error;
26
- }
27
- static isER2(value) {
28
- return value instanceof ER2I;
29
- }
30
- static from(value, fallback = "An unknown error occurred") {
31
- if (value instanceof ER2I)
32
- return value;
33
- if (value instanceof Error) {
34
- const error = new ER2I(value.message, { cause: value });
35
- error.name = value.name;
36
- error.stack = value.stack;
37
- return error;
38
- }
39
- if (typeof value === "string") {
40
- return new ER2I(value);
41
- }
42
- if (value === null || value === undefined) {
43
- return new ER2I(fallback);
44
- }
45
- try {
46
- return new ER2I(String(value));
47
- }
48
- catch {
49
- return new ER2I(fallback);
50
- }
51
- }
52
- static wrap(value, message) {
53
- const cause = ER2I.from(value);
54
- return new ER2I(message ?? cause.message, { cause });
55
- }
56
- static aggregate(errors, message = "Multiple errors occurred") {
57
- return new AggregateError(Array.from(errors, error => ER2I.from(error)), message);
58
- }
59
- }
60
- globalThis.ER2 = ER2I;
package/src/error.ts DELETED
@@ -1,81 +0,0 @@
1
-
2
-
3
- export class ER2I extends Error implements ER2 {
4
- constructor(message = "", options?: ErrorOptions) {
5
- super(message, options);
6
- this.name = new.target.name;
7
- Object.setPrototypeOf(this, new.target.prototype);
8
- }
9
-
10
- clone(): ER2I {
11
- const error = new ER2I(this.message, { cause: this.cause });
12
- error.name = this.name;
13
- error.stack = this.stack;
14
- return error;
15
- }
16
-
17
- toJSON(): {
18
- name: string;
19
- message: string;
20
- stack?: string;
21
- cause?: unknown;
22
- } {
23
- return {
24
- name: this.name,
25
- message: this.message,
26
- stack: this.stack,
27
- cause: this.cause,
28
- };
29
- }
30
-
31
- override toString(): string {
32
- return `${this.name}: ${this.message}`;
33
- }
34
-
35
- static is(value: unknown): value is Error {
36
- return value instanceof Error;
37
- }
38
-
39
- static isER2(value: unknown): value is ER2I {
40
- return value instanceof ER2I;
41
- }
42
-
43
- static from(value: unknown, fallback = "An unknown error occurred"): ER2I {
44
- if (value instanceof ER2I) return value;
45
-
46
- if (value instanceof Error) {
47
- const error = new ER2I(value.message, { cause: value });
48
- error.name = value.name;
49
- error.stack = value.stack;
50
- return error;
51
- }
52
-
53
- if (typeof value === "string") {
54
- return new ER2I(value);
55
- }
56
-
57
- if (value === null || value === undefined) {
58
- return new ER2I(fallback);
59
- }
60
-
61
- try {
62
- return new ER2I(String(value));
63
- } catch {
64
- return new ER2I(fallback);
65
- }
66
- }
67
-
68
- static wrap(value: unknown, message?: string): ER2I {
69
- const cause = ER2I.from(value);
70
- return new ER2I(message ?? cause.message, { cause });
71
- }
72
-
73
- static aggregate(errors: Iterable<unknown>, message = "Multiple errors occurred"): AggregateError {
74
- return new AggregateError(
75
- Array.from(errors, error => ER2I.from(error)),
76
- message,
77
- );
78
- }
79
- }
80
-
81
- globalThis.ER2 = ER2I
package/src/index.js DELETED
@@ -1,18 +0,0 @@
1
- export * from './array';
2
- export * from './boolean_byte';
3
- export * from './date';
4
- export * from './error';
5
- export * from './iterator';
6
- export * from './map_byte';
7
- export * from './map';
8
- export * from './number';
9
- export * from './object';
10
- export * from './promise';
11
- export * from './reg_ex';
12
- export * from './set';
13
- export * from './soa_codec';
14
- export * from './string';
15
- export * from './unit8array';
16
- export * from './url_search_params';
17
- export * from './weak_map';
18
- export * from './weak_set';
package/src/index.ts DELETED
@@ -1,18 +0,0 @@
1
- export * from './array'
2
- export * from './boolean_byte'
3
- export * from './date'
4
- export * from './error'
5
- export * from './iterator'
6
- export * from './map_byte'
7
- export * from './map'
8
- export * from './number'
9
- export * from './object'
10
- export * from './promise'
11
- export * from './reg_ex'
12
- export * from './set'
13
- export * from './soa_codec'
14
- export * from './string'
15
- export * from './unit8array'
16
- export * from './url_search_params'
17
- export * from './weak_map'
18
- export * from './weak_set'
package/src/iterator.js DELETED
@@ -1,386 +0,0 @@
1
- export class I2I {
2
- source;
3
- index = 0;
4
- buffer = [];
5
- done = false;
6
- constructor(source) {
7
- this.source = Symbol.iterator in Object(source)
8
- ? source[Symbol.iterator]()
9
- : source;
10
- }
11
- n = this.next;
12
- r = this.return;
13
- f = this.throw;
14
- next() {
15
- if (this.buffer.length) {
16
- this.index++;
17
- return { done: false, value: this.buffer.shift() };
18
- }
19
- if (this.done)
20
- return { done: true, value: undefined };
21
- const result = this.source.next();
22
- if (result.done)
23
- this.done = true;
24
- else
25
- this.index++;
26
- return result;
27
- }
28
- return(value) {
29
- this.done = true;
30
- this.buffer.length = 0;
31
- return this.source.return
32
- ? this.source.return(value)
33
- : { done: true, value: value };
34
- }
35
- throw(error) {
36
- this.done = true;
37
- this.buffer.length = 0;
38
- if (this.source.throw)
39
- return this.source.throw(error);
40
- throw error;
41
- }
42
- [Symbol.iterator]() {
43
- return this;
44
- }
45
- toArray() {
46
- return Array.from(this);
47
- }
48
- first() {
49
- return this.next().value;
50
- }
51
- last() {
52
- let result;
53
- for (const value of this)
54
- result = value;
55
- return result;
56
- }
57
- at(index) {
58
- if (index < 0) {
59
- const values = this.toArray();
60
- return values[values.length + index];
61
- }
62
- let i = 0;
63
- for (const value of this) {
64
- if (i++ === index)
65
- return value;
66
- }
67
- return undefined;
68
- }
69
- peek() {
70
- if (!this.buffer.length && !this.done) {
71
- const result = this.source.next();
72
- if (result.done)
73
- this.done = true;
74
- else
75
- this.buffer.push(result.value);
76
- }
77
- return this.buffer[0];
78
- }
79
- nextValue() {
80
- return this.next().value;
81
- }
82
- nextOr(value) {
83
- const result = this.next();
84
- return result.done ? value : result.value;
85
- }
86
- nextOrM(make) {
87
- const result = this.next();
88
- return result.done ? make() : result.value;
89
- }
90
- nextOrThrow(error = new Error("Iterator exhausted")) {
91
- const result = this.next();
92
- if (result.done)
93
- throw error;
94
- return result.value;
95
- }
96
- map(fn) {
97
- const source = this;
98
- let index = 0;
99
- return new I2I({
100
- next() {
101
- const result = source.next();
102
- return result.done ? result : { done: false, value: fn(result.value, index++) };
103
- },
104
- return: (value) => {
105
- source.return?.();
106
- return { done: true, value: value };
107
- },
108
- });
109
- }
110
- filter(pred) {
111
- const source = this;
112
- let index = 0;
113
- return new I2I({
114
- next() {
115
- let result;
116
- while (!(result = source.next()).done) {
117
- if (pred(result.value, index++))
118
- return result;
119
- }
120
- return result;
121
- },
122
- return: (value) => source.return(value),
123
- });
124
- }
125
- flatMap(fn) {
126
- const source = this;
127
- let index = 0;
128
- let inner;
129
- return new I2I({
130
- next() {
131
- while (true) {
132
- if (inner) {
133
- const result = inner.next();
134
- if (!result.done)
135
- return result;
136
- inner = undefined;
137
- }
138
- const outer = source.next();
139
- if (outer.done)
140
- return { done: true, value: undefined };
141
- const mapped = fn(outer.value, index++);
142
- inner = Symbol.iterator in Object(mapped)
143
- ? mapped[Symbol.iterator]()
144
- : mapped;
145
- }
146
- },
147
- return: (value) => {
148
- source.return?.();
149
- return { done: true, value: value };
150
- },
151
- });
152
- }
153
- flat() {
154
- return this.flatMap(value => value);
155
- }
156
- take(limit) {
157
- const source = this;
158
- let count = 0;
159
- return new I2I({
160
- next() {
161
- if (count >= limit)
162
- return { done: true, value: undefined };
163
- const result = source.next();
164
- if (!result.done)
165
- count++;
166
- return result;
167
- },
168
- return: (value) => source.return(value),
169
- });
170
- }
171
- drop(limit) {
172
- const source = this;
173
- let dropped = false;
174
- return new I2I({
175
- next() {
176
- if (!dropped) {
177
- for (let i = 0; i < limit; i++) {
178
- if (source.next().done)
179
- return { done: true, value: undefined };
180
- }
181
- dropped = true;
182
- }
183
- return source.next();
184
- },
185
- return: (value) => source.return(value),
186
- });
187
- }
188
- unique(fn) {
189
- const source = this;
190
- const seen = new Set();
191
- let index = 0;
192
- return new I2I({
193
- next() {
194
- let result;
195
- while (!(result = source.next()).done) {
196
- const key = fn ? fn(result.value, index++) : result.value;
197
- if (!seen.has(key)) {
198
- seen.add(key);
199
- return result;
200
- }
201
- }
202
- return result;
203
- },
204
- return: (value) => source.return(value),
205
- });
206
- }
207
- chunk(size) {
208
- if (!Number.isInteger(size) || size < 1)
209
- throw new RangeError("Chunk size must be a positive integer");
210
- const source = this;
211
- return new I2I({
212
- next() {
213
- const chunk = [];
214
- while (chunk.length < size) {
215
- const result = source.next();
216
- if (result.done)
217
- break;
218
- chunk.push(result.value);
219
- }
220
- return chunk.length ? { done: false, value: chunk } : { done: true, value: undefined };
221
- },
222
- return: (value) => {
223
- source.return?.();
224
- return { done: true, value: value };
225
- },
226
- });
227
- }
228
- zip(other) {
229
- const left = this;
230
- const right = new I2I(other);
231
- return new I2I({
232
- next() {
233
- const a = left.next();
234
- const b = right.next();
235
- if (a.done || b.done) {
236
- left.return();
237
- right.return();
238
- return { done: true, value: undefined };
239
- }
240
- return { done: false, value: [a.value, b.value] };
241
- },
242
- return: (value) => {
243
- left.return();
244
- right.return();
245
- return { done: true, value: value };
246
- },
247
- });
248
- }
249
- concat(...others) {
250
- const source = this;
251
- let current = source;
252
- let index = 0;
253
- return new I2I({
254
- next() {
255
- while (true) {
256
- const result = current.next();
257
- if (!result.done)
258
- return result;
259
- if (index >= others.length)
260
- return { done: true, value: undefined };
261
- const other = others[index++];
262
- current = Symbol.iterator in Object(other)
263
- ? other[Symbol.iterator]()
264
- : other;
265
- }
266
- },
267
- return: (value) => {
268
- current.return?.(value);
269
- return { done: true, value: value };
270
- },
271
- });
272
- }
273
- enumerate() {
274
- const source = this;
275
- let index = 0;
276
- return new I2I({
277
- next() {
278
- const result = source.next();
279
- return result.done ? result : { done: false, value: [index++, result.value] };
280
- },
281
- return: (value) => {
282
- source.return?.();
283
- return { done: true, value: value };
284
- },
285
- });
286
- }
287
- find(pred) {
288
- let index = 0;
289
- for (const value of this)
290
- if (pred(value, index++))
291
- return value;
292
- return undefined;
293
- }
294
- findIndex(pred) {
295
- let index = 0;
296
- for (const value of this) {
297
- if (pred(value, index))
298
- return index;
299
- index++;
300
- }
301
- return -1;
302
- }
303
- some(pred) {
304
- let index = 0;
305
- for (const value of this)
306
- if (pred(value, index++))
307
- return true;
308
- return false;
309
- }
310
- every(pred) {
311
- let index = 0;
312
- for (const value of this)
313
- if (!pred(value, index++))
314
- return false;
315
- return true;
316
- }
317
- reduce(fn, initial) {
318
- let acc = initial;
319
- let index = 0;
320
- for (const value of this)
321
- acc = fn(acc, value, index++);
322
- return acc;
323
- }
324
- forEach(fn) {
325
- let index = 0;
326
- for (const value of this)
327
- fn(value, index++);
328
- }
329
- count() {
330
- let count = 0;
331
- for (const _ of this)
332
- count++;
333
- return count;
334
- }
335
- sum(fn) {
336
- let sum = 0;
337
- for (const value of this)
338
- sum += fn ? fn(value) : value;
339
- return sum;
340
- }
341
- join(separator = ",") {
342
- return this.toArray().join(separator);
343
- }
344
- partition(pred) {
345
- const yes = [];
346
- const no = [];
347
- let index = 0;
348
- for (const value of this)
349
- (pred(value, index++) ? yes : no).push(value);
350
- return [yes, no];
351
- }
352
- group(fn) {
353
- const out = new Map();
354
- let index = 0;
355
- for (const value of this) {
356
- const key = fn(value, index++);
357
- let group = out.get(key);
358
- if (!group)
359
- out.set(key, group = []);
360
- group.push(value);
361
- }
362
- return out;
363
- }
364
- toSet() {
365
- return new Set(this);
366
- }
367
- toMap(keyFn, valueFn) {
368
- const out = new Map();
369
- let index = 0;
370
- for (const value of this) {
371
- out.set(keyFn(value, index), valueFn ? valueFn(value, index) : value);
372
- index++;
373
- }
374
- return out;
375
- }
376
- isEmpty() {
377
- return this.peek() === undefined;
378
- }
379
- exhaust() {
380
- for (const _ of this) { }
381
- }
382
- clone() {
383
- return new I2I(this.toArray());
384
- }
385
- }
386
- globalThis.I2 = I2I;