@gershy/clearing 0.0.30 → 0.0.31
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.js +67 -19
- package/cmp/mjs/main.js +67 -19
- package/cmp/sideEffects.d.ts +168 -105
- package/package.json +1 -1
- package/readme.md +255 -209
package/cmp/cjs/main.js
CHANGED
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const applyClearing = (() => {
|
|
4
4
|
// Prevent multiple installations...
|
|
5
5
|
const global = globalThis;
|
|
6
|
-
|
|
7
|
-
if (global[memSym])
|
|
6
|
+
if (global[Symbol.for(`@gershy/clearing:mem`)])
|
|
8
7
|
return;
|
|
9
|
-
global[
|
|
8
|
+
global[Symbol.for(`@gershy/clearing:mem`)] = true;
|
|
10
9
|
const getClsName = i => {
|
|
11
10
|
if (i === null)
|
|
12
11
|
return 'Null';
|
|
@@ -52,7 +51,7 @@ const applyClearing = (() => {
|
|
|
52
51
|
}
|
|
53
52
|
};
|
|
54
53
|
const symNames = [
|
|
55
|
-
// <SYMBOLS> ::
|
|
54
|
+
// <SYMBOLS> :: runtimeNames :: /[']([a-zA-Z0-9]+)[']/
|
|
56
55
|
'add',
|
|
57
56
|
'allArr',
|
|
58
57
|
'allObj',
|
|
@@ -98,20 +97,64 @@ const applyClearing = (() => {
|
|
|
98
97
|
'toNum',
|
|
99
98
|
'toObj',
|
|
100
99
|
'toStr',
|
|
101
|
-
'upper'
|
|
100
|
+
'upper',
|
|
101
|
+
'walk'
|
|
102
102
|
// </SYMBOLS>
|
|
103
103
|
];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
104
|
+
const cl = {
|
|
105
|
+
getClsName, getCls, isCls, inCls, then, safe, skip,
|
|
106
|
+
...Object.fromEntries(symNames.map(term => [term, Symbol(`@gershy/clearing:${term}`)]))
|
|
107
|
+
};
|
|
108
|
+
Object.assign(global, { cl, clearing: cl });
|
|
109
|
+
// <SYMBOLS> :: runtimeRefs :: /^[ ]*const[ ]([a-zA-Z0-9]+)[:]/
|
|
110
|
+
const add = clearing.add;
|
|
111
|
+
const allArr = clearing.allArr;
|
|
112
|
+
const allObj = clearing.allObj;
|
|
113
|
+
const at = clearing.at;
|
|
114
|
+
const assert = clearing.assert;
|
|
115
|
+
const base32 = clearing.base32;
|
|
116
|
+
const base36 = clearing.base36;
|
|
117
|
+
const base62 = clearing.base62;
|
|
118
|
+
const base64Std = clearing.base64Std;
|
|
119
|
+
const base64Url = clearing.base64Url;
|
|
120
|
+
const baseline = clearing.baseline;
|
|
121
|
+
const char = clearing.char;
|
|
122
|
+
const charset = clearing.charset;
|
|
123
|
+
const code = clearing.code;
|
|
124
|
+
const count = clearing.count;
|
|
125
|
+
const cut = clearing.cut;
|
|
126
|
+
const empty = clearing.empty;
|
|
127
|
+
const find = clearing.find;
|
|
128
|
+
const fire = clearing.fire;
|
|
129
|
+
const group = clearing.group;
|
|
130
|
+
const has = clearing.has;
|
|
131
|
+
const hasHead = clearing.hasHead;
|
|
132
|
+
const hasTail = clearing.hasTail;
|
|
133
|
+
const indent = clearing.indent;
|
|
134
|
+
const int32 = clearing.int32;
|
|
135
|
+
const int64 = clearing.int64;
|
|
136
|
+
const isInt = clearing.isInt;
|
|
137
|
+
const later = clearing.later;
|
|
138
|
+
const limn = clearing.limn;
|
|
139
|
+
const lower = clearing.lower;
|
|
140
|
+
const map = clearing.map;
|
|
141
|
+
const mapk = clearing.mapk;
|
|
142
|
+
const merge = clearing.merge;
|
|
143
|
+
const mod = clearing.mod;
|
|
144
|
+
const padHead = clearing.padHead;
|
|
145
|
+
const padTail = clearing.padTail;
|
|
146
|
+
const rem = clearing.rem;
|
|
147
|
+
const slash = clearing.slash;
|
|
148
|
+
const slice = clearing.slice;
|
|
149
|
+
const suppress = clearing.suppress;
|
|
150
|
+
const toArr = clearing.toArr;
|
|
151
|
+
const toBin = clearing.toBin;
|
|
152
|
+
const toNum = clearing.toNum;
|
|
153
|
+
const toObj = clearing.toObj;
|
|
154
|
+
const toStr = clearing.toStr;
|
|
155
|
+
const upper = clearing.upper;
|
|
156
|
+
const walk = clearing.walk;
|
|
113
157
|
// </SYMBOLS>
|
|
114
|
-
} = global.clearing;
|
|
115
158
|
const assignSyms = (Cls, def) => {
|
|
116
159
|
const protoVals = [];
|
|
117
160
|
for (const key of Reflect.ownKeys(def))
|
|
@@ -149,7 +192,7 @@ const applyClearing = (() => {
|
|
|
149
192
|
// });
|
|
150
193
|
// >> { small: { a: 1, b: 2, c: 3 }, medium: { d: 4, e: 5, f: 6, g: 7 }, big: { h: 8, i: 9, j: 10 } }
|
|
151
194
|
const ret = {};
|
|
152
|
-
for (const [k, v] of this) {
|
|
195
|
+
for (const [k, v] of this[walk]()) {
|
|
153
196
|
const g = fn(v, k);
|
|
154
197
|
if (g === skip)
|
|
155
198
|
continue;
|
|
@@ -180,8 +223,8 @@ const applyClearing = (() => {
|
|
|
180
223
|
}
|
|
181
224
|
return Object.fromEntries(arr);
|
|
182
225
|
},
|
|
183
|
-
[merge](
|
|
184
|
-
for (const [k, v] of
|
|
226
|
+
[merge](obj) {
|
|
227
|
+
for (const [k, v] of obj[walk]()) {
|
|
185
228
|
// `skip` can be passed to remove properties
|
|
186
229
|
if (v === skip) {
|
|
187
230
|
delete this[k];
|
|
@@ -220,7 +263,7 @@ const applyClearing = (() => {
|
|
|
220
263
|
}
|
|
221
264
|
return ret;
|
|
222
265
|
},
|
|
223
|
-
*[
|
|
266
|
+
*[walk]() { for (const k in this)
|
|
224
267
|
yield [k, this[k]]; }
|
|
225
268
|
});
|
|
226
269
|
assignSyms(Array, {});
|
|
@@ -422,6 +465,11 @@ const applyClearing = (() => {
|
|
|
422
465
|
[toStr]() { return dec.decode(this); },
|
|
423
466
|
[toNum]() { return (new Uint8Array(this))[toNum](); }
|
|
424
467
|
});
|
|
468
|
+
assignSyms(SharedArrayBuffer, {});
|
|
469
|
+
assignSyms(SharedArrayBuffer.prototype, {
|
|
470
|
+
[toStr]() { return dec.decode(new Uint8Array(this)); },
|
|
471
|
+
[toNum]() { return (new Uint8Array(this))[toNum](); }
|
|
472
|
+
});
|
|
425
473
|
assignSyms(Uint8Array, {});
|
|
426
474
|
assignSyms(Uint8Array.prototype, {
|
|
427
475
|
[toStr]() { return dec.decode(this); },
|
package/cmp/mjs/main.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const applyClearing = (() => {
|
|
2
2
|
// Prevent multiple installations...
|
|
3
3
|
const global = globalThis;
|
|
4
|
-
|
|
5
|
-
if (global[memSym])
|
|
4
|
+
if (global[Symbol.for(`@gershy/clearing:mem`)])
|
|
6
5
|
return;
|
|
7
|
-
global[
|
|
6
|
+
global[Symbol.for(`@gershy/clearing:mem`)] = true;
|
|
8
7
|
const getClsName = i => {
|
|
9
8
|
if (i === null)
|
|
10
9
|
return 'Null';
|
|
@@ -50,7 +49,7 @@ const applyClearing = (() => {
|
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
51
|
const symNames = [
|
|
53
|
-
// <SYMBOLS> ::
|
|
52
|
+
// <SYMBOLS> :: runtimeNames :: /[']([a-zA-Z0-9]+)[']/
|
|
54
53
|
'add',
|
|
55
54
|
'allArr',
|
|
56
55
|
'allObj',
|
|
@@ -96,20 +95,64 @@ const applyClearing = (() => {
|
|
|
96
95
|
'toNum',
|
|
97
96
|
'toObj',
|
|
98
97
|
'toStr',
|
|
99
|
-
'upper'
|
|
98
|
+
'upper',
|
|
99
|
+
'walk'
|
|
100
100
|
// </SYMBOLS>
|
|
101
101
|
];
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
const cl = {
|
|
103
|
+
getClsName, getCls, isCls, inCls, then, safe, skip,
|
|
104
|
+
...Object.fromEntries(symNames.map(term => [term, Symbol(`@gershy/clearing:${term}`)]))
|
|
105
|
+
};
|
|
106
|
+
Object.assign(global, { cl, clearing: cl });
|
|
107
|
+
// <SYMBOLS> :: runtimeRefs :: /^[ ]*const[ ]([a-zA-Z0-9]+)[:]/
|
|
108
|
+
const add = clearing.add;
|
|
109
|
+
const allArr = clearing.allArr;
|
|
110
|
+
const allObj = clearing.allObj;
|
|
111
|
+
const at = clearing.at;
|
|
112
|
+
const assert = clearing.assert;
|
|
113
|
+
const base32 = clearing.base32;
|
|
114
|
+
const base36 = clearing.base36;
|
|
115
|
+
const base62 = clearing.base62;
|
|
116
|
+
const base64Std = clearing.base64Std;
|
|
117
|
+
const base64Url = clearing.base64Url;
|
|
118
|
+
const baseline = clearing.baseline;
|
|
119
|
+
const char = clearing.char;
|
|
120
|
+
const charset = clearing.charset;
|
|
121
|
+
const code = clearing.code;
|
|
122
|
+
const count = clearing.count;
|
|
123
|
+
const cut = clearing.cut;
|
|
124
|
+
const empty = clearing.empty;
|
|
125
|
+
const find = clearing.find;
|
|
126
|
+
const fire = clearing.fire;
|
|
127
|
+
const group = clearing.group;
|
|
128
|
+
const has = clearing.has;
|
|
129
|
+
const hasHead = clearing.hasHead;
|
|
130
|
+
const hasTail = clearing.hasTail;
|
|
131
|
+
const indent = clearing.indent;
|
|
132
|
+
const int32 = clearing.int32;
|
|
133
|
+
const int64 = clearing.int64;
|
|
134
|
+
const isInt = clearing.isInt;
|
|
135
|
+
const later = clearing.later;
|
|
136
|
+
const limn = clearing.limn;
|
|
137
|
+
const lower = clearing.lower;
|
|
138
|
+
const map = clearing.map;
|
|
139
|
+
const mapk = clearing.mapk;
|
|
140
|
+
const merge = clearing.merge;
|
|
141
|
+
const mod = clearing.mod;
|
|
142
|
+
const padHead = clearing.padHead;
|
|
143
|
+
const padTail = clearing.padTail;
|
|
144
|
+
const rem = clearing.rem;
|
|
145
|
+
const slash = clearing.slash;
|
|
146
|
+
const slice = clearing.slice;
|
|
147
|
+
const suppress = clearing.suppress;
|
|
148
|
+
const toArr = clearing.toArr;
|
|
149
|
+
const toBin = clearing.toBin;
|
|
150
|
+
const toNum = clearing.toNum;
|
|
151
|
+
const toObj = clearing.toObj;
|
|
152
|
+
const toStr = clearing.toStr;
|
|
153
|
+
const upper = clearing.upper;
|
|
154
|
+
const walk = clearing.walk;
|
|
111
155
|
// </SYMBOLS>
|
|
112
|
-
} = global.clearing;
|
|
113
156
|
const assignSyms = (Cls, def) => {
|
|
114
157
|
const protoVals = [];
|
|
115
158
|
for (const key of Reflect.ownKeys(def))
|
|
@@ -147,7 +190,7 @@ const applyClearing = (() => {
|
|
|
147
190
|
// });
|
|
148
191
|
// >> { small: { a: 1, b: 2, c: 3 }, medium: { d: 4, e: 5, f: 6, g: 7 }, big: { h: 8, i: 9, j: 10 } }
|
|
149
192
|
const ret = {};
|
|
150
|
-
for (const [k, v] of this) {
|
|
193
|
+
for (const [k, v] of this[walk]()) {
|
|
151
194
|
const g = fn(v, k);
|
|
152
195
|
if (g === skip)
|
|
153
196
|
continue;
|
|
@@ -178,8 +221,8 @@ const applyClearing = (() => {
|
|
|
178
221
|
}
|
|
179
222
|
return Object.fromEntries(arr);
|
|
180
223
|
},
|
|
181
|
-
[merge](
|
|
182
|
-
for (const [k, v] of
|
|
224
|
+
[merge](obj) {
|
|
225
|
+
for (const [k, v] of obj[walk]()) {
|
|
183
226
|
// `skip` can be passed to remove properties
|
|
184
227
|
if (v === skip) {
|
|
185
228
|
delete this[k];
|
|
@@ -218,7 +261,7 @@ const applyClearing = (() => {
|
|
|
218
261
|
}
|
|
219
262
|
return ret;
|
|
220
263
|
},
|
|
221
|
-
*[
|
|
264
|
+
*[walk]() { for (const k in this)
|
|
222
265
|
yield [k, this[k]]; }
|
|
223
266
|
});
|
|
224
267
|
assignSyms(Array, {});
|
|
@@ -420,6 +463,11 @@ const applyClearing = (() => {
|
|
|
420
463
|
[toStr]() { return dec.decode(this); },
|
|
421
464
|
[toNum]() { return (new Uint8Array(this))[toNum](); }
|
|
422
465
|
});
|
|
466
|
+
assignSyms(SharedArrayBuffer, {});
|
|
467
|
+
assignSyms(SharedArrayBuffer.prototype, {
|
|
468
|
+
[toStr]() { return dec.decode(new Uint8Array(this)); },
|
|
469
|
+
[toNum]() { return (new Uint8Array(this))[toNum](); }
|
|
470
|
+
});
|
|
423
471
|
assignSyms(Uint8Array, {});
|
|
424
472
|
assignSyms(Uint8Array.prototype, {
|
|
425
473
|
[toStr]() { return dec.decode(this); },
|
package/cmp/sideEffects.d.ts
CHANGED
|
@@ -1,7 +1,144 @@
|
|
|
1
|
-
|
|
1
|
+
// TODO: HEEERE add "iterate" or "walk" symbol for typed iteration
|
|
2
|
+
|
|
3
|
+
// <SYMBOLS> :: consts :: /declare[ ]const[ ]([a-zA-Z0-9]+)[:]/
|
|
4
|
+
declare const add: unique symbol;
|
|
5
|
+
declare const allArr: unique symbol;
|
|
6
|
+
declare const allObj: unique symbol;
|
|
7
|
+
declare const at: unique symbol;
|
|
8
|
+
declare const assert: unique symbol;
|
|
9
|
+
declare const base32: unique symbol;
|
|
10
|
+
declare const base36: unique symbol;
|
|
11
|
+
declare const base62: unique symbol;
|
|
12
|
+
declare const base64Std: unique symbol;
|
|
13
|
+
declare const base64Url: unique symbol;
|
|
14
|
+
declare const baseline: unique symbol;
|
|
15
|
+
declare const char: unique symbol;
|
|
16
|
+
declare const charset: unique symbol;
|
|
17
|
+
declare const code: unique symbol;
|
|
18
|
+
declare const count: unique symbol;
|
|
19
|
+
declare const cut: unique symbol;
|
|
20
|
+
declare const empty: unique symbol;
|
|
21
|
+
declare const find: unique symbol;
|
|
22
|
+
declare const fire: unique symbol;
|
|
23
|
+
declare const group: unique symbol;
|
|
24
|
+
declare const has: unique symbol;
|
|
25
|
+
declare const hasHead: unique symbol;
|
|
26
|
+
declare const hasTail: unique symbol;
|
|
27
|
+
declare const indent: unique symbol;
|
|
28
|
+
declare const int32: unique symbol;
|
|
29
|
+
declare const int64: unique symbol;
|
|
30
|
+
declare const isInt: unique symbol;
|
|
31
|
+
declare const later: unique symbol;
|
|
32
|
+
declare const limn: unique symbol;
|
|
33
|
+
declare const lower: unique symbol;
|
|
34
|
+
declare const map: unique symbol;
|
|
35
|
+
declare const mapk: unique symbol;
|
|
36
|
+
declare const merge: unique symbol;
|
|
37
|
+
declare const mod: unique symbol;
|
|
38
|
+
declare const padHead: unique symbol;
|
|
39
|
+
declare const padTail: unique symbol;
|
|
40
|
+
declare const rem: unique symbol;
|
|
41
|
+
declare const slash: unique symbol;
|
|
42
|
+
declare const slice: unique symbol;
|
|
43
|
+
declare const suppress: unique symbol;
|
|
44
|
+
declare const toArr: unique symbol;
|
|
45
|
+
declare const toBin: unique symbol;
|
|
46
|
+
declare const toNum: unique symbol;
|
|
47
|
+
declare const toObj: unique symbol;
|
|
48
|
+
declare const toStr: unique symbol;
|
|
49
|
+
declare const upper: unique symbol;
|
|
50
|
+
declare const walk: unique symbol;
|
|
51
|
+
// </SYMBOLS>
|
|
2
52
|
|
|
53
|
+
declare global {
|
|
54
|
+
|
|
55
|
+
const clearing: {
|
|
56
|
+
|
|
57
|
+
skip: Skip,
|
|
58
|
+
// isCls: ClsCheck,
|
|
59
|
+
// inCls: ClsCheck,
|
|
60
|
+
getClsName: (v: any) => string,
|
|
61
|
+
getCls: (v: any) => any,
|
|
62
|
+
then: {
|
|
63
|
+
<V, R0 = V, R1 = never>(val: Promise<V>, rsv?: (v: V) => R0, rjc?: (e: any) => R1): Promise<R0 | R1>,
|
|
64
|
+
<V, R0 = V, R1 = never>(val: V, rsv?: (v: V) => R0, rjc?: (e: any) => R1): R0 | R1;
|
|
65
|
+
},
|
|
66
|
+
safe: {
|
|
67
|
+
<V, R0 = never>(fn: () => Promise<V>, rjc?: (e: any) => R0): Promise<V | R0>,
|
|
68
|
+
<V, R0 = never>(fn: () => V, rjc?: (e: any) => R0): Promise<V | R0>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
} & {
|
|
72
|
+
|
|
73
|
+
[K in 'isCls' | 'inCls']: {
|
|
74
|
+
(i: unknown, num: BooleanConstructor): i is boolean,
|
|
75
|
+
(i: unknown, num: NumberConstructor): i is number,
|
|
76
|
+
(i: unknown, str: StringConstructor): i is string,
|
|
77
|
+
(i: unknown, buff: Buffer): i is Buffer,
|
|
78
|
+
(i: unknown, arr: ArrayConstructor): i is any[],
|
|
79
|
+
(i: unknown, obj: ObjectConstructor): i is Obj<unknown>,
|
|
80
|
+
(i: unknown, fn: FunctionConstructor): i is (...args: any[]) => any,
|
|
81
|
+
(i: unknown, fn: SymbolConstructor): i is symbol,
|
|
82
|
+
<T>(i: unknown, prm: PromiseConstructor): i is Promise<T>,
|
|
83
|
+
<C extends abstract new (...args: any) => any>(i: unknown, cls: C): i is InstanceType<C>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
} & {
|
|
87
|
+
|
|
88
|
+
// <SYMBOLS> :: declarations :: /^[ ]*([a-zA-Z0-9]+)[:][ ]+typeof \1/
|
|
89
|
+
add: typeof add, //`Symbol('@gershy/clearing:add')`,
|
|
90
|
+
allArr: typeof allArr, //`Symbol('@gershy/clearing:allArr')`,
|
|
91
|
+
allObj: typeof allObj, //`Symbol('@gershy/clearing:allObj')`,
|
|
92
|
+
at: typeof at, //`Symbol('@gershy/clearing:at')`,
|
|
93
|
+
assert: typeof assert, //`Symbol('@gershy/clearing:assert')`,
|
|
94
|
+
base32: typeof base32, //`Symbol('@gershy/clearing:base32')`,
|
|
95
|
+
base36: typeof base36, //`Symbol('@gershy/clearing:base36')`,
|
|
96
|
+
base62: typeof base62, //`Symbol('@gershy/clearing:base62')`,
|
|
97
|
+
base64Std: typeof base64Std, //`Symbol('@gershy/clearing:base64Std')`,
|
|
98
|
+
base64Url: typeof base64Url, //`Symbol('@gershy/clearing:base64Url')`,
|
|
99
|
+
baseline: typeof baseline, //`Symbol('@gershy/clearing:baseline')`,
|
|
100
|
+
char: typeof char, //`Symbol('@gershy/clearing:char')`,
|
|
101
|
+
charset: typeof charset, //`Symbol('@gershy/clearing:charset')`,
|
|
102
|
+
code: typeof code, //`Symbol('@gershy/clearing:code')`,
|
|
103
|
+
count: typeof count, //`Symbol('@gershy/clearing:count')`,
|
|
104
|
+
cut: typeof cut, //`Symbol('@gershy/clearing:cut')`,
|
|
105
|
+
empty: typeof empty, //`Symbol('@gershy/clearing:empty')`,
|
|
106
|
+
find: typeof find, //`Symbol('@gershy/clearing:find')`,
|
|
107
|
+
fire: typeof fire, //`Symbol('@gershy/clearing:fire')`,
|
|
108
|
+
group: typeof group, //`Symbol('@gershy/clearing:group')`,
|
|
109
|
+
has: typeof has, //`Symbol('@gershy/clearing:has')`,
|
|
110
|
+
hasHead: typeof hasHead, //`Symbol('@gershy/clearing:hasHead')`,
|
|
111
|
+
hasTail: typeof hasTail, //`Symbol('@gershy/clearing:hasTail')`,
|
|
112
|
+
indent: typeof indent, //`Symbol('@gershy/clearing:indent')`,
|
|
113
|
+
int32: typeof int32, //`Symbol('@gershy/clearing:int32')`,
|
|
114
|
+
int64: typeof int64, //`Symbol('@gershy/clearing:int64')`,
|
|
115
|
+
isInt: typeof isInt, //`Symbol('@gershy/clearing:isInt')`,
|
|
116
|
+
later: typeof later, //`Symbol('@gershy/clearing:later')`,
|
|
117
|
+
limn: typeof limn, //`Symbol('@gershy/clearing:limn')`,
|
|
118
|
+
lower: typeof lower, //`Symbol('@gershy/clearing:lower')`,
|
|
119
|
+
map: typeof map, //`Symbol('@gershy/clearing:map')`,
|
|
120
|
+
mapk: typeof mapk, //`Symbol('@gershy/clearing:mapk')`,
|
|
121
|
+
merge: typeof merge, //`Symbol('@gershy/clearing:merge')`,
|
|
122
|
+
mod: typeof mod, //`Symbol('@gershy/clearing:mod')`,
|
|
123
|
+
padHead: typeof padHead, //`Symbol('@gershy/clearing:padHead')`,
|
|
124
|
+
padTail: typeof padTail, //`Symbol('@gershy/clearing:padTail')`,
|
|
125
|
+
rem: typeof rem, //`Symbol('@gershy/clearing:rem')`,
|
|
126
|
+
slash: typeof slash, //`Symbol('@gershy/clearing:slash')`,
|
|
127
|
+
slice: typeof slice, //`Symbol('@gershy/clearing:slice')`,
|
|
128
|
+
suppress: typeof suppress, //`Symbol('@gershy/clearing:suppress')`,
|
|
129
|
+
toArr: typeof toArr, //`Symbol('@gershy/clearing:toArr')`,
|
|
130
|
+
toBin: typeof toBin, //`Symbol('@gershy/clearing:toBin')`,
|
|
131
|
+
toNum: typeof toNum, //`Symbol('@gershy/clearing:toNum')`,
|
|
132
|
+
toObj: typeof toObj, //`Symbol('@gershy/clearing:toObj')`,
|
|
133
|
+
toStr: typeof toStr, //`Symbol('@gershy/clearing:toStr')`,
|
|
134
|
+
upper: typeof upper, //`Symbol('@gershy/clearing:upper')`,
|
|
135
|
+
walk: typeof walk, //`Symbol('@gershy/clearing:walk')`
|
|
136
|
+
// </SYMBOLS>
|
|
137
|
+
|
|
138
|
+
};
|
|
139
|
+
|
|
3
140
|
// Util
|
|
4
|
-
type Obj<V = any> = { [
|
|
141
|
+
type Obj<V = any> = { [K in string]: V };
|
|
5
142
|
type Arr<V = any> = V[];
|
|
6
143
|
|
|
7
144
|
// Differentiate between "map" and "rec" ("record") - maps have arbitrary keys; recs have fixed keys
|
|
@@ -31,85 +168,6 @@ declare global {
|
|
|
31
168
|
valChar: (n: bigint) => string
|
|
32
169
|
};
|
|
33
170
|
|
|
34
|
-
type Then = {
|
|
35
|
-
<V, R0 = V, R1 = never>(val: Promise<V>, rsv?: (v: V) => R0, rjc?: (e: any) => R1): Promise<R0 | R1>,
|
|
36
|
-
<V, R0 = V, R1 = never>(val: V, rsv?: (v: V) => R0, rjc?: (e: any) => R1): R0 | R1;
|
|
37
|
-
};
|
|
38
|
-
type Safe = {
|
|
39
|
-
<V, R0 = never>(fn: () => Promise<V>, rjc?: (e: any) => R0): Promise<V | R0>,
|
|
40
|
-
<V, R0 = never>(fn: () => V, rjc?: (e: any) => R0): Promise<V | R0>
|
|
41
|
-
};
|
|
42
|
-
type ClsCheck = {
|
|
43
|
-
(i: unknown, num: BooleanConstructor): i is boolean,
|
|
44
|
-
(i: unknown, num: NumberConstructor): i is number,
|
|
45
|
-
(i: unknown, str: StringConstructor): i is string,
|
|
46
|
-
(i: unknown, buff: Buffer): i is Buffer,
|
|
47
|
-
(i: unknown, arr: ArrayConstructor): i is any[],
|
|
48
|
-
(i: unknown, obj: ObjectConstructor): i is Obj<unknown>,
|
|
49
|
-
(i: unknown, fn: FunctionConstructor): i is (...args: any[]) => any,
|
|
50
|
-
(i: unknown, fn: SymbolConstructor): i is symbol,
|
|
51
|
-
<T>(i: unknown, prm: PromiseConstructor): i is Promise<T>,
|
|
52
|
-
<C extends abstract new (...args: any) => any>(i: unknown, cls: C): i is InstanceType<C>
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const clearing: readonly {
|
|
56
|
-
|
|
57
|
-
skip: Skip,
|
|
58
|
-
isCls: ClsCheck,
|
|
59
|
-
inCls: ClsCheck,
|
|
60
|
-
getClsName: (v: any) => string,
|
|
61
|
-
getCls: (v: any) => any,
|
|
62
|
-
|
|
63
|
-
// <SYMBOLS> :: declarations :: /([a-zA-Z0-9]+)[:]/
|
|
64
|
-
add: '@gershy/clearing/add',
|
|
65
|
-
allArr: '@gershy/clearing/allArr',
|
|
66
|
-
allObj: '@gershy/clearing/allObj',
|
|
67
|
-
at: '@gershy/clearing/at',
|
|
68
|
-
assert: '@gershy/clearing/assert',
|
|
69
|
-
base32: '@gershy/clearing/base32',
|
|
70
|
-
base36: '@gershy/clearing/base36',
|
|
71
|
-
base62: '@gershy/clearing/base62',
|
|
72
|
-
base64Std: '@gershy/clearing/base64Std',
|
|
73
|
-
base64Url: '@gershy/clearing/base64Url',
|
|
74
|
-
baseline: '@gershy/clearing/baseline',
|
|
75
|
-
char: '@gershy/clearing/char',
|
|
76
|
-
charset: '@gershy/clearing/charset',
|
|
77
|
-
code: '@gershy/clearing/code',
|
|
78
|
-
count: '@gershy/clearing/count',
|
|
79
|
-
cut: '@gershy/clearing/cut',
|
|
80
|
-
empty: '@gershy/clearing/empty',
|
|
81
|
-
find: '@gershy/clearing/find',
|
|
82
|
-
fire: '@gershy/clearing/fire',
|
|
83
|
-
group: '@gershy/clearing/group',
|
|
84
|
-
has: '@gershy/clearing/has',
|
|
85
|
-
hasHead: '@gershy/clearing/hasHead',
|
|
86
|
-
hasTail: '@gershy/clearing/hasTail',
|
|
87
|
-
indent: '@gershy/clearing/indent',
|
|
88
|
-
int32: '@gershy/clearing/int32',
|
|
89
|
-
int64: '@gershy/clearing/int64',
|
|
90
|
-
isInt: '@gershy/clearing/isInt',
|
|
91
|
-
later: '@gershy/clearing/later',
|
|
92
|
-
limn: '@gershy/clearing/limn',
|
|
93
|
-
lower: '@gershy/clearing/lower',
|
|
94
|
-
map: '@gershy/clearing/map',
|
|
95
|
-
mapk: '@gershy/clearing/mapk',
|
|
96
|
-
merge: '@gershy/clearing/merge',
|
|
97
|
-
mod: '@gershy/clearing/mod',
|
|
98
|
-
padHead: '@gershy/clearing/padHead',
|
|
99
|
-
padTail: '@gershy/clearing/padTail',
|
|
100
|
-
rem: '@gershy/clearing/rem',
|
|
101
|
-
slash: '@gershy/clearing/slash',
|
|
102
|
-
slice: '@gershy/clearing/slice',
|
|
103
|
-
suppress: '@gershy/clearing/suppress',
|
|
104
|
-
toArr: '@gershy/clearing/toArr',
|
|
105
|
-
toBin: '@gershy/clearing/toBin',
|
|
106
|
-
toNum: '@gershy/clearing/toNum',
|
|
107
|
-
toObj: '@gershy/clearing/toObj',
|
|
108
|
-
toStr: '@gershy/clearing/toStr',
|
|
109
|
-
upper: '@gershy/clearing/upper',
|
|
110
|
-
// </SYMBOLS>
|
|
111
|
-
};
|
|
112
|
-
|
|
113
171
|
// Adding symbol properties to Object.prototype will cause typescript to think these properties
|
|
114
172
|
// are also available for extending types, e.g. Array - to avoid this we merge in an object which
|
|
115
173
|
// defines every symbol as `undefined`!
|
|
@@ -160,7 +218,8 @@ declare global {
|
|
|
160
218
|
[clearing.toNum]: undefined,
|
|
161
219
|
[clearing.toObj]: undefined,
|
|
162
220
|
[clearing.toStr]: undefined,
|
|
163
|
-
[clearing.upper]: undefined
|
|
221
|
+
[clearing.upper]: undefined,
|
|
222
|
+
[clearing.walk]: undefined
|
|
164
223
|
// </SYMBOLS>
|
|
165
224
|
};
|
|
166
225
|
|
|
@@ -213,19 +272,20 @@ declare global {
|
|
|
213
272
|
}
|
|
214
273
|
|
|
215
274
|
interface ObjectConstructor {}
|
|
216
|
-
interface Object {
|
|
217
|
-
|
|
218
|
-
[clearing.
|
|
219
|
-
[clearing.
|
|
220
|
-
[clearing.
|
|
221
|
-
[clearing.
|
|
222
|
-
[clearing.
|
|
223
|
-
[clearing.
|
|
224
|
-
[clearing.
|
|
225
|
-
[clearing.
|
|
226
|
-
[clearing.
|
|
227
|
-
[clearing.
|
|
228
|
-
[
|
|
275
|
+
interface Object extends SymbolsProto {
|
|
276
|
+
|
|
277
|
+
[clearing.empty]: <O extends Obj> (this: O) => this is Obj<never>,
|
|
278
|
+
[clearing.at]: <O extends Obj, K extends string | string[], D extends any = Skip>(this: O, k: K, def?: D) => Dive<O, K extends string[] ? K : [ K ], D>,
|
|
279
|
+
[clearing.has]: <O extends Obj> (this: O, k: unknown) => k is keyof O,
|
|
280
|
+
[clearing.map]: <O extends Obj, V> (this: O, fn: (v: ObjVals<O>, k: ObjKeys<O>) => V) => { [K in keyof O]: Exclude<V, Skip> },
|
|
281
|
+
[clearing.mapk]: <O extends Obj, K extends string, V> (this: O, fn: (v: ObjVals<O>, k: ObjKeys<O>) => Skip | [ K, V ]) => { [KK in K]: V },
|
|
282
|
+
[clearing.merge]: <A extends Obj, B extends Obj> (this: A, val: B) => A & B,
|
|
283
|
+
[clearing.slice]: <O extends Obj, K extends readonly (keyof O)[]> (this: O, keys: K) => { [P in K[number]]: SkipNever<O[P]> },
|
|
284
|
+
[clearing.slash]: <O extends Obj, T extends readonly (keyof O)[]> (this: O, keys: T) => { [K in keyof O as Exclude<keyof O, T[number]>]: O[K] },
|
|
285
|
+
[clearing.toArr]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => any> (this: O, fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
|
|
286
|
+
[clearing.count]: () => number,
|
|
287
|
+
[clearing.group]: <O extends Obj, G extends string> (this: O, fn: (v: O[keyof O], k: keyof O) => Skip | G) => { [K in G]?: Partial<O> },
|
|
288
|
+
[clearing.walk]: <O extends Obj> (this: O) => Iterable<[ ObjKeys<O>, ObjVals<O> ]>,
|
|
229
289
|
|
|
230
290
|
$$inspect: <O>(this: O) => { v: O }
|
|
231
291
|
|
|
@@ -236,6 +296,10 @@ declare global {
|
|
|
236
296
|
[clearing.toStr]: () => string,
|
|
237
297
|
[clearing.toNum]: () => bigint
|
|
238
298
|
}
|
|
299
|
+
interface SharedArrayBuffer {
|
|
300
|
+
[clearing.toStr]: () => string,
|
|
301
|
+
[clearing.toNum]: () => bigint
|
|
302
|
+
}
|
|
239
303
|
|
|
240
304
|
interface Uint8ArrayConstructor {}
|
|
241
305
|
interface Uint8Array {
|
|
@@ -246,7 +310,6 @@ declare global {
|
|
|
246
310
|
interface PromiseConstructor {
|
|
247
311
|
[clearing.allArr]: <V extends Promise<any>>(arr: Arr<V>) => Promise<Arr<Exclude<Awaited<V>, Skip>>>,
|
|
248
312
|
[clearing.allObj]: <V extends Promise<any>>(obj: Obj<V>) => Promise<Obj<Exclude<Awaited<V>, Skip>>>,
|
|
249
|
-
// [allObj]: <O extends { [K: string]: Promise<any> }>(obj: O) => Promise<{ [K in keyof O]: Exclude<Awaited<O[K]>, Skip> }>,
|
|
250
313
|
[clearing.later]: <T=void>() => PromiseLater<T>
|
|
251
314
|
}
|
|
252
315
|
interface Promise<T> {}
|
|
@@ -262,20 +325,20 @@ declare global {
|
|
|
262
325
|
[clearing.find]: (fn: (val: T) => any) => ({ found: true, val: T } | { found: false, val: null }),
|
|
263
326
|
[clearing.map]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
|
|
264
327
|
[clearing.toArr]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
|
|
265
|
-
[clearing.toObj]: <R extends readonly [string, any]>(fn: (val: T) => Skip | R) =>
|
|
328
|
+
[clearing.toObj]: <R extends readonly [string, any]>(fn: (val: T) => Skip | R) => Obj<R[1]>,
|
|
266
329
|
[clearing.rem]: (val: T) => void
|
|
267
330
|
}
|
|
268
331
|
|
|
269
332
|
interface MapConstructor {}
|
|
270
333
|
interface Map<K, V> extends SymbolsProto {
|
|
271
|
-
[clearing.add]:
|
|
272
|
-
[clearing.count]:
|
|
273
|
-
[clearing.empty]:
|
|
274
|
-
[clearing.find]:
|
|
275
|
-
[clearing.map]:
|
|
276
|
-
[clearing.toArr]: <T>(fn: (val: V, key: K) => T)
|
|
277
|
-
[clearing.toObj]: <
|
|
278
|
-
[clearing.rem]:
|
|
334
|
+
[clearing.add]: (k: K, v: V) => void,
|
|
335
|
+
[clearing.count]: (this: Map<K, V>) => number,
|
|
336
|
+
[clearing.empty]: () => this is Map<K, never>,
|
|
337
|
+
[clearing.find]: (fn: (val: V, key: K) => any) => ({ found: true, val: V, key: K } | { found: false, val: null, key: null }),
|
|
338
|
+
[clearing.map]: <T> (fn: (val: V, key: K) => Skip | readonly [string, any]) => { [K: string]: any },
|
|
339
|
+
[clearing.toArr]: <T> (fn: (val: V, key: K) => T) => Exclude<T, Skip>[],
|
|
340
|
+
[clearing.toObj]: <RK, RV>(fn: (val: V, key: K) => Skip | readonly [ RK, RV ]) => { [K in RK]: RV },
|
|
341
|
+
[clearing.rem]: (key: K) => void
|
|
279
342
|
}
|
|
280
343
|
|
|
281
344
|
interface StringConstructor {
|