@gershy/clearing 0.0.14 → 0.0.16
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/cmp/cjs/main.d.ts +17 -0
- package/cmp/cjs/main.js +64 -59
- package/cmp/cjs/package.json +1 -0
- package/cmp/mjs/main.d.ts +17 -0
- package/cmp/mjs/main.js +23 -23
- package/cmp/mjs/package.json +1 -0
- package/cmp/sideEffects.d.ts +0 -31
- package/package.json +5 -2
package/cmp/cjs/main.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
import '../sideEffects.js';
|
|
2
|
+
type ClsCheck = {
|
|
3
|
+
(i: unknown, num: BooleanConstructor): i is boolean;
|
|
4
|
+
(i: unknown, num: NumberConstructor): i is number;
|
|
5
|
+
(i: unknown, str: StringConstructor): i is string;
|
|
6
|
+
(i: unknown, buff: BufferConstructor): i is Buffer;
|
|
7
|
+
(i: unknown, arr: ArrayConstructor): i is any[];
|
|
8
|
+
(i: unknown, obj: ObjectConstructor): i is Obj<unknown>;
|
|
9
|
+
(i: unknown, fn: FunctionConstructor): i is Fn;
|
|
10
|
+
(i: unknown, fn: SymbolConstructor): i is symbol;
|
|
11
|
+
<T>(i: unknown, prm: PromiseConstructor): i is Promise<T>;
|
|
12
|
+
<C extends abstract new (...args: any) => any>(i: unknown, cls: C): i is InstanceType<C>;
|
|
13
|
+
};
|
|
14
|
+
export declare const getClsName: (i: any) => any;
|
|
15
|
+
export declare const getCls: (i: any) => any;
|
|
16
|
+
export declare const isCls: ClsCheck;
|
|
17
|
+
export declare const inCls: ClsCheck;
|
|
18
|
+
export declare const skip: undefined;
|
|
2
19
|
declare const applyClearing: () => void;
|
|
3
20
|
export default applyClearing;
|
package/cmp/cjs/main.js
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.skip = exports.inCls = exports.isCls = exports.getCls = exports.getClsName = void 0;
|
|
4
|
+
const getClsName = i => {
|
|
5
|
+
if (i === null)
|
|
6
|
+
return 'Null';
|
|
7
|
+
if (i === undefined)
|
|
8
|
+
return 'Undef';
|
|
9
|
+
if (i !== i)
|
|
10
|
+
return 'Nan';
|
|
11
|
+
return Object.getPrototypeOf(i)?.constructor.name ?? 'Prototypeless';
|
|
12
|
+
};
|
|
13
|
+
exports.getClsName = getClsName;
|
|
14
|
+
const getCls = i => Object.getPrototypeOf(i)?.constructor ?? null;
|
|
15
|
+
exports.getCls = getCls;
|
|
16
|
+
const isCls = (i, C) => {
|
|
17
|
+
// NaN only matches against the NaN primitive (not the Number Form)
|
|
18
|
+
if (i !== i)
|
|
19
|
+
return C !== C;
|
|
20
|
+
// `null` and `undefined` only match to themselves
|
|
21
|
+
if (i == null)
|
|
22
|
+
return i === C;
|
|
23
|
+
// Otherwise strictly check the constructor
|
|
24
|
+
return Object.getPrototypeOf(i).constructor === C;
|
|
25
|
+
};
|
|
26
|
+
exports.isCls = isCls;
|
|
27
|
+
const inCls = (i, C) => i instanceof C;
|
|
28
|
+
exports.inCls = inCls;
|
|
29
|
+
exports.skip = undefined;
|
|
3
30
|
const applyClearing = (() => {
|
|
4
31
|
const global = globalThis;
|
|
5
32
|
// Prevent multiple installations...
|
|
@@ -61,42 +88,20 @@ const applyClearing = (() => {
|
|
|
61
88
|
// </SYMBOLS>
|
|
62
89
|
];
|
|
63
90
|
const syms = Object.fromEntries(symNames.map(term => [term, Symbol(`${pfx}:${term}`)]));
|
|
64
|
-
|
|
65
|
-
if (i === null)
|
|
66
|
-
return 'Null';
|
|
67
|
-
if (i === undefined)
|
|
68
|
-
return 'Undef';
|
|
69
|
-
if (i !== i)
|
|
70
|
-
return 'Nan';
|
|
71
|
-
return Object.getPrototypeOf(i)?.constructor.name ?? 'Prototypeless';
|
|
72
|
-
};
|
|
73
|
-
const getCls = i => Object.getPrototypeOf(i)?.constructor ?? null;
|
|
74
|
-
const isCls = (i, C) => {
|
|
75
|
-
// NaN only matches against the NaN primitive (not the Number Form)
|
|
76
|
-
if (i !== i)
|
|
77
|
-
return C !== C;
|
|
78
|
-
// `null` and `undefined` only match to themselves
|
|
79
|
-
if (i == null)
|
|
80
|
-
return i === C;
|
|
81
|
-
// Otherwise strictly check the constructor
|
|
82
|
-
return Object.getPrototypeOf(i).constructor === C;
|
|
83
|
-
};
|
|
84
|
-
const inCls = (i, C) => i instanceof C;
|
|
85
|
-
const skip = undefined;
|
|
86
|
-
Object.assign(global, { ...syms, clearing: { getClsName, getCls, isCls, inCls } });
|
|
91
|
+
Object.assign(global, { ...syms });
|
|
87
92
|
const protoDefs = (Cls, def) => {
|
|
88
93
|
let protoVals = [];
|
|
89
94
|
let classVals = [];
|
|
90
95
|
for (const key of Reflect.ownKeys(def)) {
|
|
91
|
-
if (key !== '$' && !isCls(key, Symbol))
|
|
92
|
-
throw Object.assign(Error('invalid proto key'), { Cls, keyClsName: getClsName(key), key });
|
|
96
|
+
if (key !== '$' && !(0, exports.isCls)(key, Symbol))
|
|
97
|
+
throw Object.assign(Error('invalid proto key'), { Cls, keyClsName: (0, exports.getClsName)(key), key });
|
|
93
98
|
if (key !== '$') {
|
|
94
99
|
protoVals.push([key, def[key]]);
|
|
95
100
|
}
|
|
96
101
|
else {
|
|
97
102
|
for (const k of Reflect.ownKeys(def[key])) {
|
|
98
|
-
if (!isCls(k, Symbol))
|
|
99
|
-
throw Object.assign(Error('invalid class key'), { Cls, keyClsName: getClsName(k), key: k });
|
|
103
|
+
if (!(0, exports.isCls)(k, Symbol))
|
|
104
|
+
throw Object.assign(Error('invalid class key'), { Cls, keyClsName: (0, exports.getClsName)(k), key: k });
|
|
100
105
|
classVals.push([k, def[key][k]]);
|
|
101
106
|
}
|
|
102
107
|
}
|
|
@@ -107,9 +112,9 @@ const applyClearing = (() => {
|
|
|
107
112
|
Object.defineProperty(target, sym, { enumerable: false, value });
|
|
108
113
|
};
|
|
109
114
|
protoDefs(Object, {
|
|
110
|
-
[at](cmps, def = skip) {
|
|
115
|
+
[at](cmps, def = exports.skip) {
|
|
111
116
|
let ptr = this;
|
|
112
|
-
if (!isCls(cmps, Array))
|
|
117
|
+
if (!(0, exports.isCls)(cmps, Array))
|
|
113
118
|
cmps = [cmps];
|
|
114
119
|
for (const c of cmps) {
|
|
115
120
|
if (ptr[has](c))
|
|
@@ -133,7 +138,7 @@ const applyClearing = (() => {
|
|
|
133
138
|
const ret = {};
|
|
134
139
|
for (const [k, v] of this) {
|
|
135
140
|
const g = fn(v, k);
|
|
136
|
-
if (g === skip)
|
|
141
|
+
if (g === exports.skip)
|
|
137
142
|
continue;
|
|
138
143
|
if (!ret[has](g))
|
|
139
144
|
ret[g] = {};
|
|
@@ -146,7 +151,7 @@ const applyClearing = (() => {
|
|
|
146
151
|
const ret = Object.assign({}, this);
|
|
147
152
|
for (const k in ret) {
|
|
148
153
|
const v = fn(ret[k], k);
|
|
149
|
-
if (v !== skip)
|
|
154
|
+
if (v !== exports.skip)
|
|
150
155
|
ret[k] = v;
|
|
151
156
|
else
|
|
152
157
|
delete ret[k];
|
|
@@ -157,7 +162,7 @@ const applyClearing = (() => {
|
|
|
157
162
|
const arr = [];
|
|
158
163
|
for (const k in this) {
|
|
159
164
|
const r = fn(this[k], k);
|
|
160
|
-
if (r !== skip)
|
|
165
|
+
if (r !== exports.skip)
|
|
161
166
|
arr.push(r);
|
|
162
167
|
}
|
|
163
168
|
return Object.fromEntries(arr);
|
|
@@ -165,17 +170,17 @@ const applyClearing = (() => {
|
|
|
165
170
|
[merge](o) {
|
|
166
171
|
for (const [k, v] of o) {
|
|
167
172
|
// `skip` can be passed to remove properties
|
|
168
|
-
if (v === skip) {
|
|
173
|
+
if (v === exports.skip) {
|
|
169
174
|
delete this[k];
|
|
170
175
|
continue;
|
|
171
176
|
}
|
|
172
177
|
// Incoming non-Object properties are simple
|
|
173
|
-
if (!isCls(v, Object)) {
|
|
178
|
+
if (!(0, exports.isCls)(v, Object)) {
|
|
174
179
|
this[k] = v;
|
|
175
180
|
continue;
|
|
176
181
|
}
|
|
177
182
|
// `v` is an Object; existing non-Object replaced with `{}`
|
|
178
|
-
if (!this[has](k) || !isCls(this[k], Object))
|
|
183
|
+
if (!this[has](k) || !(0, exports.isCls)(this[k], Object))
|
|
179
184
|
this[k] = {};
|
|
180
185
|
// And simply recurse!
|
|
181
186
|
this[k][merge](v);
|
|
@@ -191,13 +196,13 @@ const applyClearing = (() => {
|
|
|
191
196
|
[slice](p) {
|
|
192
197
|
// >> { a: 1, b: 2, c: 3, d: 4 }.slice([ 'b', 'd' ]);
|
|
193
198
|
// { b: 2, d: 4 }
|
|
194
|
-
return p[toObj](p => this[has](p) ? [p, this[p]] : skip);
|
|
199
|
+
return p[toObj](p => this[has](p) ? [p, this[p]] : exports.skip);
|
|
195
200
|
},
|
|
196
201
|
[toArr](fn) {
|
|
197
202
|
const ret = [];
|
|
198
203
|
for (const k in this) {
|
|
199
204
|
const r = fn(this[k], k);
|
|
200
|
-
if (r !== skip)
|
|
205
|
+
if (r !== exports.skip)
|
|
201
206
|
ret.push(r);
|
|
202
207
|
}
|
|
203
208
|
return ret;
|
|
@@ -226,7 +231,7 @@ const applyClearing = (() => {
|
|
|
226
231
|
const ret = {};
|
|
227
232
|
for (const elem of this) {
|
|
228
233
|
const g = fn(elem);
|
|
229
|
-
if (g === skip)
|
|
234
|
+
if (g === exports.skip)
|
|
230
235
|
continue;
|
|
231
236
|
if (!ret[has](g))
|
|
232
237
|
ret[g] = [];
|
|
@@ -240,7 +245,7 @@ const applyClearing = (() => {
|
|
|
240
245
|
const len = this.length;
|
|
241
246
|
for (let i = 0; i < len; i++) {
|
|
242
247
|
const r = it(this[i], i);
|
|
243
|
-
if (r !== skip)
|
|
248
|
+
if (r !== exports.skip)
|
|
244
249
|
ret.push(r);
|
|
245
250
|
}
|
|
246
251
|
return ret;
|
|
@@ -252,7 +257,7 @@ const applyClearing = (() => {
|
|
|
252
257
|
const len = this.length;
|
|
253
258
|
for (let i = 0; i < len; i++) {
|
|
254
259
|
const r = it(this[i], i);
|
|
255
|
-
if (r !== skip)
|
|
260
|
+
if (r !== exports.skip)
|
|
256
261
|
ret.push(r);
|
|
257
262
|
}
|
|
258
263
|
return Object.fromEntries(ret);
|
|
@@ -264,7 +269,7 @@ const applyClearing = (() => {
|
|
|
264
269
|
return str.split('\n')[map](ln => {
|
|
265
270
|
const ind = ln.indexOf(seq);
|
|
266
271
|
if (ind === -1)
|
|
267
|
-
return skip;
|
|
272
|
+
return exports.skip;
|
|
268
273
|
return ln.slice(ind + seq.length);
|
|
269
274
|
}).join('\n');
|
|
270
275
|
},
|
|
@@ -299,7 +304,7 @@ const applyClearing = (() => {
|
|
|
299
304
|
[count]() { return this.length; },
|
|
300
305
|
[cut](delim, cuts = 1) {
|
|
301
306
|
// `cuts` defines # of cuts (resulting array length is `num + 1`)
|
|
302
|
-
const split = this.split(delim, cuts < Infinity ? cuts : skip);
|
|
307
|
+
const split = this.split(delim, cuts < Infinity ? cuts : exports.skip);
|
|
303
308
|
const numDelimsSplit = split.length - 1;
|
|
304
309
|
const lenConsumed = 0
|
|
305
310
|
+ split.reduce((a, s) => a + s.length, 0)
|
|
@@ -315,7 +320,7 @@ const applyClearing = (() => {
|
|
|
315
320
|
if (!this)
|
|
316
321
|
return this; // No-op on empty String (otherwise it would transform a 0-line string to a 1-line string)
|
|
317
322
|
let indentStr;
|
|
318
|
-
if (isCls(args[0], String)) {
|
|
323
|
+
if ((0, exports.isCls)(args[0], String)) {
|
|
319
324
|
indentStr = args[0];
|
|
320
325
|
}
|
|
321
326
|
else {
|
|
@@ -328,7 +333,7 @@ const applyClearing = (() => {
|
|
|
328
333
|
[padHead]: String.prototype.padStart,
|
|
329
334
|
[padTail]: String.prototype.padEnd,
|
|
330
335
|
[toNum](cs = String[base62]) {
|
|
331
|
-
if (isCls(cs, String))
|
|
336
|
+
if ((0, exports.isCls)(cs, String))
|
|
332
337
|
cs = String[charset](cs);
|
|
333
338
|
const base = cs.size;
|
|
334
339
|
if (base === 1n)
|
|
@@ -354,7 +359,7 @@ const applyClearing = (() => {
|
|
|
354
359
|
const ret = [];
|
|
355
360
|
for (let i = 0; i < this; i++) {
|
|
356
361
|
const r = fn(i);
|
|
357
|
-
if (r !== skip)
|
|
362
|
+
if (r !== exports.skip)
|
|
358
363
|
ret.push(r);
|
|
359
364
|
}
|
|
360
365
|
return Object.fromEntries(ret);
|
|
@@ -365,7 +370,7 @@ const applyClearing = (() => {
|
|
|
365
370
|
// | (n).encodeStr(singleChr)
|
|
366
371
|
// is always equivalent to
|
|
367
372
|
// | singleChr.repeat(n - 1)
|
|
368
|
-
if (isCls(cs, String))
|
|
373
|
+
if ((0, exports.isCls)(cs, String))
|
|
369
374
|
cs = String[charset](cs);
|
|
370
375
|
const base = cs.size;
|
|
371
376
|
if (base === 1n && padLen)
|
|
@@ -409,17 +414,17 @@ const applyClearing = (() => {
|
|
|
409
414
|
seen.set(this, 'cycle(Error)');
|
|
410
415
|
const { message, stack, cause, ...props } = this;
|
|
411
416
|
return {
|
|
412
|
-
form: getClsName(this),
|
|
417
|
+
form: (0, exports.getClsName)(this),
|
|
413
418
|
msg: message,
|
|
414
|
-
trace: stack?.split('\n').slice(1)[map](v => v.trim() ?? skip) ?? [],
|
|
419
|
+
trace: stack?.split('\n').slice(1)[map](v => v.trim() ?? exports.skip) ?? [],
|
|
415
420
|
...props,
|
|
416
421
|
cause: !cause ? null : cause[limn](seen)
|
|
417
422
|
};
|
|
418
423
|
},
|
|
419
424
|
[mod](props = {} /* { cause, msg, message, ...more } */) {
|
|
420
|
-
if (isCls(props, Function))
|
|
425
|
+
if ((0, exports.isCls)(props, Function))
|
|
421
426
|
props = props(this.message, this);
|
|
422
|
-
if (isCls(props, String))
|
|
427
|
+
if ((0, exports.isCls)(props, String))
|
|
423
428
|
props = { message: props };
|
|
424
429
|
const { cause = null, msg = null, message = msg ?? this.message, ...moreProps } = props;
|
|
425
430
|
// - Assign `cause` to transfer props like fs "code" props, etc. - watch out, `cause` may be
|
|
@@ -427,12 +432,12 @@ const applyClearing = (() => {
|
|
|
427
432
|
// - Assign `moreProps` to transfer any other properties
|
|
428
433
|
// - Add `message` prop
|
|
429
434
|
// - Only add `cause` prop if `cause` is non-null
|
|
430
|
-
return Object.assign(this, inCls(cause, Error) ? cause : {}, moreProps, cause ? { message, cause } : { message });
|
|
435
|
+
return Object.assign(this, (0, exports.inCls)(cause, Error) ? cause : {}, moreProps, cause ? { message, cause } : { message });
|
|
431
436
|
},
|
|
432
437
|
[suppress]() {
|
|
433
438
|
this[Symbol.for('clearing.err.suppressed')] = true;
|
|
434
439
|
if (this.cause) {
|
|
435
|
-
const causes = inCls(this.cause, Error) ? [this.cause] : this.cause;
|
|
440
|
+
const causes = (0, exports.inCls)(this.cause, Error) ? [this.cause] : this.cause;
|
|
436
441
|
for (const err of causes)
|
|
437
442
|
err[suppress]();
|
|
438
443
|
}
|
|
@@ -448,7 +453,7 @@ const applyClearing = (() => {
|
|
|
448
453
|
return Promise.all(Object.values(obj)).then(vals => {
|
|
449
454
|
const ret = {};
|
|
450
455
|
for (const [i, k] of keys.entries())
|
|
451
|
-
if (vals[i] !== skip)
|
|
456
|
+
if (vals[i] !== exports.skip)
|
|
452
457
|
ret[k] = vals[i];
|
|
453
458
|
return ret;
|
|
454
459
|
});
|
|
@@ -473,7 +478,7 @@ const applyClearing = (() => {
|
|
|
473
478
|
let ind = 0;
|
|
474
479
|
for (const item of this) {
|
|
475
480
|
const r = fn(item, ind++);
|
|
476
|
-
if (r !== skip)
|
|
481
|
+
if (r !== exports.skip)
|
|
477
482
|
ret.push(r);
|
|
478
483
|
}
|
|
479
484
|
return ret;
|
|
@@ -484,7 +489,7 @@ const applyClearing = (() => {
|
|
|
484
489
|
let ind = 0;
|
|
485
490
|
for (const item of this) {
|
|
486
491
|
const r = fn(item, ind++);
|
|
487
|
-
if (r !== skip)
|
|
492
|
+
if (r !== exports.skip)
|
|
488
493
|
ret.push(r);
|
|
489
494
|
}
|
|
490
495
|
return ret;
|
|
@@ -493,7 +498,7 @@ const applyClearing = (() => {
|
|
|
493
498
|
const ret = [];
|
|
494
499
|
for (const item of this) {
|
|
495
500
|
const r = fn(item);
|
|
496
|
-
if (r !== skip)
|
|
501
|
+
if (r !== exports.skip)
|
|
497
502
|
ret.push(r);
|
|
498
503
|
}
|
|
499
504
|
return Object.fromEntries(ret);
|
|
@@ -513,7 +518,7 @@ const applyClearing = (() => {
|
|
|
513
518
|
const ret = [];
|
|
514
519
|
for (const [k, v] of this) {
|
|
515
520
|
const r = fn(v, k);
|
|
516
|
-
if (r !== skip)
|
|
521
|
+
if (r !== exports.skip)
|
|
517
522
|
ret.push(r);
|
|
518
523
|
}
|
|
519
524
|
return Object.fromEntries(ret);
|
|
@@ -523,7 +528,7 @@ const applyClearing = (() => {
|
|
|
523
528
|
const ret = [];
|
|
524
529
|
for (const [k, v] of this) {
|
|
525
530
|
const r = fn(v, k);
|
|
526
|
-
if (r !== skip)
|
|
531
|
+
if (r !== exports.skip)
|
|
527
532
|
ret.push(r);
|
|
528
533
|
}
|
|
529
534
|
return ret;
|
|
@@ -532,7 +537,7 @@ const applyClearing = (() => {
|
|
|
532
537
|
const ret = [];
|
|
533
538
|
for (const [k, v] of this) {
|
|
534
539
|
const r = fn(v, k);
|
|
535
|
-
if (r !== skip)
|
|
540
|
+
if (r !== exports.skip)
|
|
536
541
|
ret.push(r);
|
|
537
542
|
}
|
|
538
543
|
return Object.fromEntries(ret);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/cmp/mjs/main.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
1
|
import '../sideEffects.js';
|
|
2
|
+
type ClsCheck = {
|
|
3
|
+
(i: unknown, num: BooleanConstructor): i is boolean;
|
|
4
|
+
(i: unknown, num: NumberConstructor): i is number;
|
|
5
|
+
(i: unknown, str: StringConstructor): i is string;
|
|
6
|
+
(i: unknown, buff: BufferConstructor): i is Buffer;
|
|
7
|
+
(i: unknown, arr: ArrayConstructor): i is any[];
|
|
8
|
+
(i: unknown, obj: ObjectConstructor): i is Obj<unknown>;
|
|
9
|
+
(i: unknown, fn: FunctionConstructor): i is Fn;
|
|
10
|
+
(i: unknown, fn: SymbolConstructor): i is symbol;
|
|
11
|
+
<T>(i: unknown, prm: PromiseConstructor): i is Promise<T>;
|
|
12
|
+
<C extends abstract new (...args: any) => any>(i: unknown, cls: C): i is InstanceType<C>;
|
|
13
|
+
};
|
|
14
|
+
export declare const getClsName: (i: any) => any;
|
|
15
|
+
export declare const getCls: (i: any) => any;
|
|
16
|
+
export declare const isCls: ClsCheck;
|
|
17
|
+
export declare const inCls: ClsCheck;
|
|
18
|
+
export declare const skip: undefined;
|
|
2
19
|
declare const applyClearing: () => void;
|
|
3
20
|
export default applyClearing;
|
package/cmp/mjs/main.js
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
export const getClsName = i => {
|
|
2
|
+
if (i === null)
|
|
3
|
+
return 'Null';
|
|
4
|
+
if (i === undefined)
|
|
5
|
+
return 'Undef';
|
|
6
|
+
if (i !== i)
|
|
7
|
+
return 'Nan';
|
|
8
|
+
return Object.getPrototypeOf(i)?.constructor.name ?? 'Prototypeless';
|
|
9
|
+
};
|
|
10
|
+
export const getCls = i => Object.getPrototypeOf(i)?.constructor ?? null;
|
|
11
|
+
export const isCls = (i, C) => {
|
|
12
|
+
// NaN only matches against the NaN primitive (not the Number Form)
|
|
13
|
+
if (i !== i)
|
|
14
|
+
return C !== C;
|
|
15
|
+
// `null` and `undefined` only match to themselves
|
|
16
|
+
if (i == null)
|
|
17
|
+
return i === C;
|
|
18
|
+
// Otherwise strictly check the constructor
|
|
19
|
+
return Object.getPrototypeOf(i).constructor === C;
|
|
20
|
+
};
|
|
21
|
+
export const inCls = (i, C) => i instanceof C;
|
|
22
|
+
export const skip = undefined;
|
|
1
23
|
const applyClearing = (() => {
|
|
2
24
|
const global = globalThis;
|
|
3
25
|
// Prevent multiple installations...
|
|
@@ -59,29 +81,7 @@ const applyClearing = (() => {
|
|
|
59
81
|
// </SYMBOLS>
|
|
60
82
|
];
|
|
61
83
|
const syms = Object.fromEntries(symNames.map(term => [term, Symbol(`${pfx}:${term}`)]));
|
|
62
|
-
|
|
63
|
-
if (i === null)
|
|
64
|
-
return 'Null';
|
|
65
|
-
if (i === undefined)
|
|
66
|
-
return 'Undef';
|
|
67
|
-
if (i !== i)
|
|
68
|
-
return 'Nan';
|
|
69
|
-
return Object.getPrototypeOf(i)?.constructor.name ?? 'Prototypeless';
|
|
70
|
-
};
|
|
71
|
-
const getCls = i => Object.getPrototypeOf(i)?.constructor ?? null;
|
|
72
|
-
const isCls = (i, C) => {
|
|
73
|
-
// NaN only matches against the NaN primitive (not the Number Form)
|
|
74
|
-
if (i !== i)
|
|
75
|
-
return C !== C;
|
|
76
|
-
// `null` and `undefined` only match to themselves
|
|
77
|
-
if (i == null)
|
|
78
|
-
return i === C;
|
|
79
|
-
// Otherwise strictly check the constructor
|
|
80
|
-
return Object.getPrototypeOf(i).constructor === C;
|
|
81
|
-
};
|
|
82
|
-
const inCls = (i, C) => i instanceof C;
|
|
83
|
-
const skip = undefined;
|
|
84
|
-
Object.assign(global, { ...syms, clearing: { getClsName, getCls, isCls, inCls } });
|
|
84
|
+
Object.assign(global, { ...syms });
|
|
85
85
|
const protoDefs = (Cls, def) => {
|
|
86
86
|
let protoVals = [];
|
|
87
87
|
let classVals = [];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/cmp/sideEffects.d.ts
CHANGED
|
@@ -26,37 +26,6 @@ declare global {
|
|
|
26
26
|
charVal: (c: string) => bigint,
|
|
27
27
|
valChar: (n: bigint) => string
|
|
28
28
|
};
|
|
29
|
-
type ClsCheck = {
|
|
30
|
-
(i: unknown, num: BooleanConstructor): i is boolean,
|
|
31
|
-
(i: unknown, num: NumberConstructor): i is number,
|
|
32
|
-
(i: unknown, str: StringConstructor): i is string,
|
|
33
|
-
(i: unknown, buff: BufferConstructor): i is Buffer,
|
|
34
|
-
(i: unknown, arr: ArrayConstructor): i is any[],
|
|
35
|
-
(i: unknown, obj: ObjectConstructor): i is Obj<unknown>,
|
|
36
|
-
(i: unknown, fn: FunctionConstructor): i is Fn,
|
|
37
|
-
(i: unknown, fn: SymbolConstructor): i is symbol,
|
|
38
|
-
<T>(i: unknown, prm: PromiseConstructor): i is Promise<T>,
|
|
39
|
-
<C extends abstract new (...args: any) => any>(i: unknown, cls: C): i is InstanceType<C>
|
|
40
|
-
};
|
|
41
|
-
const clearing: {
|
|
42
|
-
|
|
43
|
-
getClsName: (i: any) => string,
|
|
44
|
-
getCls: {
|
|
45
|
-
(i: number): NumberConstructor,
|
|
46
|
-
(i: string): StringConstructor,
|
|
47
|
-
(i: Buffer): BufferConstructor,
|
|
48
|
-
(i: any[]): ArrayConstructor,
|
|
49
|
-
(i: { [K: string]: any }): ObjectConstructor,
|
|
50
|
-
(i: (...a: any[]) => any): FunctionConstructor,
|
|
51
|
-
(i: Promise<any>): PromiseConstructor,
|
|
52
|
-
<T>(i: T): { new (...args: any[]): T }
|
|
53
|
-
},
|
|
54
|
-
isCls: ClsCheck,
|
|
55
|
-
inCls: ClsCheck,
|
|
56
|
-
|
|
57
|
-
skip: Skip
|
|
58
|
-
|
|
59
|
-
};
|
|
60
29
|
|
|
61
30
|
// <SYMBOLS> :: declarations :: /const ([a-zA-Z0-9]+)[ ]*[:][ ]*unique symbol;/
|
|
62
31
|
const add: unique symbol;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gershy/clearing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Adds the features you always wish javascript had!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clearing",
|
|
@@ -22,22 +22,25 @@
|
|
|
22
22
|
"tsx": "^4.21.0",
|
|
23
23
|
"typescript": "^5.9.3"
|
|
24
24
|
},
|
|
25
|
+
|
|
25
26
|
"type": "module",
|
|
26
27
|
"files": [
|
|
27
28
|
"cmp"
|
|
28
29
|
],
|
|
30
|
+
"types": "./cmp/mjs/main.d.ts",
|
|
29
31
|
"exports": {
|
|
30
32
|
".": {
|
|
31
33
|
"import": "./cmp/mjs/main.js",
|
|
32
34
|
"require": "./cmp/cjs/main.js"
|
|
33
35
|
}
|
|
34
36
|
},
|
|
37
|
+
|
|
35
38
|
"scripts": {
|
|
36
39
|
"test": "npm run ts.check && npx tsx ./src/main.test.ts",
|
|
37
40
|
"ts.check": "npx tsc --noEmit",
|
|
38
41
|
"build.cjs": "tsc -p ts/tsconfig.cjs.json",
|
|
39
42
|
"build.mjs": "tsc -p ts/tsconfig.mjs.json",
|
|
40
|
-
"build": "node ./build.js removeCmp && npm run build.cjs && npm run build.mjs && node ./build.js
|
|
43
|
+
"build": "node ./build.js removeCmp && npm run build.cjs && npm run build.mjs && node ./build.js finalizeExportVariants",
|
|
41
44
|
"git.pub": "npm run test && git add --all && git commit -m \"automated\" && git push",
|
|
42
45
|
"npm.login": "npm login",
|
|
43
46
|
"npm.pub": "npm run test && npm run build && npm publish --access public"
|