@gershy/clearing 0.0.6 → 0.0.8
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 +293 -357
- package/cmp/mjs/main.js +293 -357
- package/cmp/types/global.d.ts +194 -427
- package/license +15 -0
- package/package.json +7 -3
- package/readme.md +784 -1
package/cmp/types/global.d.ts
CHANGED
|
@@ -1,470 +1,241 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
|
|
3
3
|
// Util
|
|
4
|
-
type Fn<A=any[], T=any> = (...args: A) => T;
|
|
5
|
-
type Obj<V = any> = { [
|
|
4
|
+
type Fn<A extends any[] = any[], T = any> = (...args: A) => T;
|
|
5
|
+
type Obj<V = any> = { [k: string]: V };
|
|
6
6
|
|
|
7
|
+
// Differentiate between "map" and "rec" ("record") - maps have arbitrary keys; recs have fixed keys
|
|
7
8
|
type ObjMode<O extends { [K: string]: any }> = O extends { [K in infer KK]: any } ? (string extends KK ? 'map' : 'rec') : never;
|
|
8
|
-
type ObjKeys<O extends Obj> = Extract<keyof O, string
|
|
9
|
+
type ObjKeys<O extends Obj> = Extract<keyof O, string> | `${Extract<keyof O, number>}`; // Convert numbers to strings; ignores symbols
|
|
9
10
|
type ObjVals<O extends Obj> = O[Extract<keyof O, string>];
|
|
10
|
-
|
|
11
|
-
type MaybeFn<T> = T | ((...args: any[]) => T);
|
|
12
|
-
type ResolveFn<T> = T extends ((...args: any[]) => any) ? ReturnType<T> : T;
|
|
11
|
+
|
|
13
12
|
type Itr<O extends Obj> = Iterable<[ ObjKeys<O>, ObjVals<O> ]>;
|
|
14
13
|
type Json = null | boolean | number | string | Json[] | { [K: string]: Json };
|
|
15
14
|
type Skip = undefined;
|
|
16
|
-
type SkipNever<V> = V extends Skip ? Skip extends V ? never : V : V;
|
|
17
|
-
type Endable = { end: () => MaybePromise<unknown> };
|
|
18
|
-
type Callable = ((...args: any[]) => any) | { new (...args: any): any };
|
|
19
|
-
type SovereignFn<T extends Callable = Callable> = T; // & { _svrn: 1 };
|
|
20
|
-
type Assign<A, B> = Omit<A, keyof B> & B;
|
|
15
|
+
type SkipNever<V> = V extends Skip ? Skip extends V ? never : V : V;
|
|
21
16
|
type UGH = any; // Use when necessary to escape typing because typescript has failed us
|
|
22
17
|
|
|
23
18
|
type Dive<O extends Obj, K extends readonly string[], D = undefined> =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// converting a union to an intersection: https://stackoverflow.com/a/50375286/830905
|
|
36
|
-
// // type Combine<U> =
|
|
37
|
-
// // (U extends any ? (x: U) => void : never) extends (x: infer I) => void
|
|
38
|
-
// // ? I
|
|
39
|
-
// // : never;
|
|
40
|
-
// type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
|
|
41
|
-
// type Combine<Union> = Expand<(Union extends any ? (x: Union) => void : never) extends (x: infer Combined) => void ? Combined : never>;
|
|
42
|
-
// // type Combine0 = { a: number, b?: string } | { a?: number, b: string };
|
|
43
|
-
// type Combine1 = Combine<Combine0>;
|
|
44
|
-
|
|
45
|
-
// Jsfn
|
|
46
|
-
// Implements "jsfn" which is "json" but with functions allowed within the payload too! (Overall,
|
|
47
|
-
// pronounced "jay-sfun"). This is implemented simply using `fn.toString()` + `eval(fnString)`. The
|
|
48
|
-
// encoded format stores a list of all paths within the json which are stringified functions. The
|
|
49
|
-
// decoding process simply calls `JSON.parse`, loops through every stringified path, and expands
|
|
50
|
-
// the stringified values with `eval`. Of course, these functions should only be used with trusted
|
|
51
|
-
// data!
|
|
52
|
-
type Hoist = `<repo>/${string}` | `@aws/${string}`; // TODO: More imports??
|
|
53
|
-
type JsfnInst<Cls extends { new (...args: any[]): any }> = { // "jsfn instance"
|
|
54
|
-
hoist: `${Hoist}::${string}`,
|
|
55
|
-
form: Cls,
|
|
56
|
-
args: ConstructorParameters<Cls> & Jsfn
|
|
19
|
+
K extends [ infer K0 extends string, ...infer KM extends string[] ]
|
|
20
|
+
? K0 extends keyof O
|
|
21
|
+
? (ObjMode<O> extends 'map' ? D : never) | Dive<O[K0], KM, D>
|
|
22
|
+
: D
|
|
23
|
+
: O;
|
|
24
|
+
|
|
25
|
+
type CharSet = {
|
|
26
|
+
str: string,
|
|
27
|
+
size: bigint,
|
|
28
|
+
charVal: (c: string) => bigint,
|
|
29
|
+
valChar: (n: bigint) => string
|
|
57
30
|
};
|
|
58
|
-
|
|
59
|
-
type Jsfn = null | boolean | number | string | SovereignFn | JsfnInst<any> | Jsfn[] | { [K: string]: Jsfn };
|
|
60
|
-
type JsfnDecoded<T extends Jsfn, N extends string = ''> =
|
|
61
|
-
N extends '+++++'
|
|
62
|
-
? '<TOO DEEP>'
|
|
63
|
-
: T extends null
|
|
64
|
-
? T
|
|
65
|
-
: T extends boolean
|
|
66
|
-
? T
|
|
67
|
-
: T extends number
|
|
68
|
-
? T
|
|
69
|
-
: T extends string
|
|
70
|
-
? T
|
|
71
|
-
: T extends SovereignFn<infer Fn>
|
|
72
|
-
? Fn
|
|
73
|
-
: T extends JsfnInst<any>
|
|
74
|
-
? InstanceType<T['form']>
|
|
75
|
-
: T extends { [K: string]: Jsfn }
|
|
76
|
-
? { [K in keyof T]: T[K] extends Jsfn ? JsfnDecoded<T[K], `+${N}`> : never }
|
|
77
|
-
: T extends Jsfn[]
|
|
78
|
-
? { [K in keyof T]: T[K] extends Jsfn ? JsfnDecoded<T[K], `+${N}`> : never }
|
|
79
|
-
: Jsfn;
|
|
80
|
-
|
|
81
|
-
type JsfnEncoded<T extends Jsfn> = string & { _jsfn: T };
|
|
82
|
-
|
|
83
|
-
type ObjLeafs<O> = O extends Obj ? { [K in keyof O]: ObjLeafs<O[K]> }[keyof O] : O;
|
|
84
|
-
// type ObjLeafs0 = ObjLeafs<{ a: string, b: { c: number }, d: null, e: { f: { g: undefined } } }>;
|
|
85
|
-
|
|
86
|
-
type CharSet = { str: string, size: bigint, charVal: (c: string) => bigint, valChar: (n: bigint) => string };
|
|
87
31
|
|
|
88
32
|
type MaybePromise<T> = T | Promise<T>;
|
|
89
33
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
const getForm: {
|
|
122
|
-
(val: number): NumberConstructor,
|
|
123
|
-
(val: string): StringConstructor,
|
|
124
|
-
(val: Buffer): BufferConstructor,
|
|
125
|
-
(val: any[]): ArrayConstructor,
|
|
126
|
-
(val: { [K: string]: any }): ObjectConstructor,
|
|
127
|
-
(val: (...a: any[]) => any): FunctionConstructor,
|
|
128
|
-
(val: Promise<any>): PromiseConstructor,
|
|
129
|
-
<T>(val: T): { new (...args: any[]): T }
|
|
130
|
-
};
|
|
131
|
-
const hasForm: {
|
|
132
|
-
(val: any, fnc: FunctionConstructor): val is (...args: any) => any,
|
|
133
|
-
(val: any, obj: ObjectConstructor): val is { [K: string]: any },
|
|
134
|
-
(val: any, str: StringConstructor): val is string,
|
|
135
|
-
(val: any, num: NumberConstructor): val is number,
|
|
136
|
-
(val: any, arr: ArrayConstructor): val is any[],
|
|
137
|
-
(val: any, arr: BufferConstructor): val is Buffer,
|
|
138
|
-
<T>(val: any, prm: PromiseConstructor): val is Promise<T>,
|
|
139
|
-
<C>(val: unknown, cls: C): val is InstanceType<C>
|
|
140
|
-
};
|
|
141
|
-
const getFormName: (f: any) => string;
|
|
142
|
-
|
|
143
|
-
const jsfn: {
|
|
144
|
-
encode: SovereignFn<
|
|
145
|
-
<Data extends Jsfn>(dec: Data, opts?: { encodeFn?: (fn: Fn) => string }) => {
|
|
146
|
-
hoists: `<repo>/${string}::${string}`[],
|
|
147
|
-
str: JsfnEncoded<Data>;
|
|
148
|
-
}
|
|
149
|
-
>
|
|
34
|
+
type ClsCheck = {
|
|
35
|
+
(i: unknown, num: BooleanConstructor): i is boolean,
|
|
36
|
+
(i: unknown, num: NumberConstructor): i is number,
|
|
37
|
+
(i: unknown, str: StringConstructor): i is string,
|
|
38
|
+
(i: unknown, buff: BufferConstructor): i is Buffer,
|
|
39
|
+
(i: unknown, arr: ArrayConstructor): i is any[],
|
|
40
|
+
(i: unknown, obj: ObjectConstructor): i is Obj<unknown>,
|
|
41
|
+
(i: unknown, fn: FunctionConstructor): i is Fn,
|
|
42
|
+
(i: unknown, fn: SymbolConstructor): i is symbol,
|
|
43
|
+
<T>(i: unknown, prm: PromiseConstructor): i is Promise<T>,
|
|
44
|
+
<C extends abstract new (...args: any) => any>(i: unknown, cls: C): i is InstanceType<C>
|
|
45
|
+
};
|
|
46
|
+
const clearing: {
|
|
47
|
+
|
|
48
|
+
getClsName: (i: any) => string,
|
|
49
|
+
getCls: {
|
|
50
|
+
(i: number): NumberConstructor,
|
|
51
|
+
(i: string): StringConstructor,
|
|
52
|
+
(i: Buffer): BufferConstructor,
|
|
53
|
+
(i: any[]): ArrayConstructor,
|
|
54
|
+
(i: { [K: string]: any }): ObjectConstructor,
|
|
55
|
+
(i: (...a: any[]) => any): FunctionConstructor,
|
|
56
|
+
(i: Promise<any>): PromiseConstructor,
|
|
57
|
+
<T>(i: T): { new (...args: any[]): T }
|
|
58
|
+
},
|
|
59
|
+
isCls: ClsCheck,
|
|
60
|
+
inCls: ClsCheck,
|
|
61
|
+
|
|
62
|
+
skip: Skip
|
|
63
|
+
|
|
150
64
|
};
|
|
151
65
|
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
const
|
|
182
|
-
const
|
|
183
|
-
const
|
|
184
|
-
const
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
[bind]: undefined
|
|
203
|
-
[built]: undefined
|
|
204
|
-
[count]: undefined
|
|
205
|
-
[cut]: undefined
|
|
206
|
-
[dive]: undefined
|
|
207
|
-
[empty]: undefined
|
|
208
|
-
[fire]: undefined
|
|
209
|
-
[group]: undefined
|
|
210
|
-
[has]: undefined
|
|
211
|
-
[hasHead]: undefined
|
|
212
|
-
[hasTail]: undefined
|
|
213
|
-
[indent]: undefined
|
|
214
|
-
[limn]: undefined
|
|
215
|
-
[lower]: undefined
|
|
216
|
-
[mod]: undefined
|
|
217
|
-
[map]: undefined
|
|
218
|
-
[mapk]: undefined
|
|
219
|
-
[merge]: undefined
|
|
220
|
-
[padHead]: undefined
|
|
221
|
-
[padTail]: undefined
|
|
222
|
-
[rem]: undefined
|
|
223
|
-
[find]: undefined
|
|
224
|
-
[slash]: undefined
|
|
225
|
-
[slice]: undefined
|
|
226
|
-
[suppress]: undefined
|
|
227
|
-
[toArr]: undefined
|
|
228
|
-
[toNum]: undefined
|
|
229
|
-
[toObj]: undefined
|
|
230
|
-
[toStr]: undefined
|
|
231
|
-
[upper]: undefined
|
|
232
|
-
};
|
|
66
|
+
// <SYMBOLS>
|
|
67
|
+
const add: unique symbol;
|
|
68
|
+
const allArr: unique symbol;
|
|
69
|
+
const allObj: unique symbol;
|
|
70
|
+
const at: unique symbol;
|
|
71
|
+
const assert: unique symbol;
|
|
72
|
+
const base32: unique symbol;
|
|
73
|
+
const base36: unique symbol;
|
|
74
|
+
const base62: unique symbol;
|
|
75
|
+
const base64Std: unique symbol;
|
|
76
|
+
const base64Url: unique symbol;
|
|
77
|
+
const baseline: unique symbol;
|
|
78
|
+
const bind: unique symbol;
|
|
79
|
+
const bits: unique symbol;
|
|
80
|
+
const char: unique symbol;
|
|
81
|
+
const charset: unique symbol;
|
|
82
|
+
const code: unique symbol;
|
|
83
|
+
const count: unique symbol;
|
|
84
|
+
const cut: unique symbol;
|
|
85
|
+
const dive: unique symbol;
|
|
86
|
+
const empty: unique symbol;
|
|
87
|
+
const find: unique symbol;
|
|
88
|
+
const fire: unique symbol;
|
|
89
|
+
const group: unique symbol;
|
|
90
|
+
const has: unique symbol;
|
|
91
|
+
const hasHead: unique symbol;
|
|
92
|
+
const hasTail: unique symbol;
|
|
93
|
+
const indent: unique symbol;
|
|
94
|
+
const int32: unique symbol;
|
|
95
|
+
const int64: unique symbol;
|
|
96
|
+
const isInt: unique symbol;
|
|
97
|
+
const later: unique symbol;
|
|
98
|
+
const limn: unique symbol;
|
|
99
|
+
const lower: unique symbol;
|
|
100
|
+
const map: unique symbol;
|
|
101
|
+
const mapk: unique symbol;
|
|
102
|
+
const merge: unique symbol;
|
|
103
|
+
const mod: unique symbol;
|
|
104
|
+
const padHead: unique symbol;
|
|
105
|
+
const padTail: unique symbol;
|
|
106
|
+
const rem: unique symbol;
|
|
107
|
+
const slash: unique symbol;
|
|
108
|
+
const slice: unique symbol;
|
|
109
|
+
const suppress: unique symbol;
|
|
110
|
+
const toArr: unique symbol;
|
|
111
|
+
const toNum: unique symbol;
|
|
112
|
+
const toObj: unique symbol;
|
|
113
|
+
const toStr: unique symbol;
|
|
114
|
+
const upper: unique symbol;
|
|
115
|
+
// </SYMBOLS>
|
|
233
116
|
|
|
234
117
|
interface ErrorConstructor {
|
|
235
|
-
assert:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
};
|
|
239
|
-
interface Error extends ProtoWithSymbols {
|
|
118
|
+
[assert]: <V = any>(args: V, fn: (args: V) => boolean) => void
|
|
119
|
+
}
|
|
120
|
+
interface Error {
|
|
240
121
|
[mod]: (props: { [K: string]: any }) => Error,
|
|
241
122
|
[fire]: (props?: { [K: string]: any }) => never,
|
|
242
123
|
[suppress]: () => Error,
|
|
243
|
-
|
|
244
|
-
[limn]: (seen?: Map) => (Obj<Json> & {
|
|
124
|
+
[limn]: (seen?: Map<any, any>) => (Obj<Json> & {
|
|
245
125
|
form: string,
|
|
246
126
|
msg: string,
|
|
247
127
|
trace: string[],
|
|
248
128
|
cause: null | ReturnType<Error[typeof limn]>
|
|
249
129
|
})
|
|
250
|
-
}
|
|
130
|
+
}
|
|
251
131
|
|
|
252
|
-
interface ArrayConstructor {
|
|
253
|
-
|
|
254
|
-
};
|
|
255
|
-
interface Array<T> extends ProtoWithSymbols {
|
|
256
|
-
[iden]: 'arr',
|
|
132
|
+
interface ArrayConstructor {}
|
|
133
|
+
interface Array<T> {
|
|
257
134
|
[has]: (val: unknown) => boolean,
|
|
258
|
-
[map]:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
>(
|
|
262
|
-
fn: Fn
|
|
263
|
-
): Exclude<ReturnType<Fn>, Skip>[]
|
|
264
|
-
},
|
|
265
|
-
[add]: <TT extends T>(val: TT) => void,
|
|
266
|
-
[rem]: <TT extends T>(val: TT) => void,
|
|
135
|
+
[map]: <Fn extends (v: T, i: number) => any>(fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
|
|
136
|
+
[add]: <TT extends T>(val: TT) => TT,
|
|
137
|
+
[rem]: <TT extends T>(val: TT) => void,
|
|
267
138
|
[count]: () => number,
|
|
268
|
-
[empty]: (
|
|
269
|
-
[toObj]: <
|
|
270
|
-
[find]:
|
|
271
|
-
[group]: <G extends string>(fn: (v: T) => G) => { [K in G]?: T[] }
|
|
272
|
-
}
|
|
139
|
+
[empty]: () => boolean,
|
|
140
|
+
[toObj]: <R extends readonly [string, any]>(fn: (v: T, n: number) => Skip | R) => { [K: string]: any },
|
|
141
|
+
[find]: (fn: (val: T, n: number) => any) => ({ found: true, val: T, ind: number } | { found: false, val: null, ind: null }),
|
|
142
|
+
[group]: <G extends string>(fn: (v: T) => Skip | G) => { [K in G]?: T[] }
|
|
143
|
+
}
|
|
273
144
|
|
|
274
|
-
interface FunctionConstructor {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
[iden]: 'fnc',
|
|
279
|
-
[bind]: {
|
|
280
|
-
<
|
|
281
|
-
Fn extends (this: any, ...args: any[]) => any,
|
|
282
|
-
To
|
|
283
|
-
>(
|
|
284
|
-
this: Fn,
|
|
285
|
-
to: To
|
|
286
|
-
): ((this: To, ...args: Parameters<Fn>) => ReturnType<Fn>)
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
interface GeneratorFunctionConstructor {};
|
|
291
|
-
interface Generator<T> extends ProtoWithSymbols {
|
|
292
|
-
[toArr]: {
|
|
293
|
-
<
|
|
294
|
-
Fn extends (v: T) => any
|
|
295
|
-
>(
|
|
296
|
-
fn: Fn
|
|
297
|
-
):
|
|
298
|
-
ReturnType<Fn>[],
|
|
299
|
-
}
|
|
300
|
-
};
|
|
145
|
+
interface FunctionConstructor {}
|
|
146
|
+
interface Function {
|
|
147
|
+
[bind]: <Fn extends (...args: any[]) => any, To>(this: Fn, to: To) => ((...args: Parameters<Fn> extends [ infer A0, ...infer AM ] ? AM : never) => ReturnType<Fn>)
|
|
148
|
+
}
|
|
301
149
|
|
|
302
150
|
interface NumberConstructor {
|
|
303
|
-
int32: number
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
151
|
+
[int32]: number,
|
|
152
|
+
[int64]: number
|
|
153
|
+
}
|
|
154
|
+
interface Number {
|
|
155
|
+
[char]: () => string,
|
|
156
|
+
[isInt]: () => boolean,
|
|
307
157
|
[toStr]: (str: string | CharSet, len?: number) => string,
|
|
308
158
|
[toArr]: <T>(fn: (n: number) => T) => T[],
|
|
309
|
-
[
|
|
310
|
-
|
|
159
|
+
[toObj]: <R extends readonly [string, any]>(fn: (n: number) => Skip | R) => { [K: string]: any },
|
|
160
|
+
[bits]: () => Generator<number>,
|
|
161
|
+
[Symbol.iterator]: () => Generator<number>
|
|
162
|
+
}
|
|
311
163
|
|
|
312
|
-
interface BigIntConstructor {}
|
|
313
|
-
interface BigInt
|
|
164
|
+
interface BigIntConstructor {}
|
|
165
|
+
interface BigInt {
|
|
314
166
|
[toStr]: (str: string | CharSet, len?: number) => string
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
interface ObjectConstructor {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
[
|
|
323
|
-
[
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
[at]: {
|
|
334
|
-
<
|
|
335
|
-
O extends Obj,
|
|
336
|
-
K extends string | string[],
|
|
337
|
-
D extends any = undefined
|
|
338
|
-
>(
|
|
339
|
-
this: O,
|
|
340
|
-
k: string | string[],
|
|
341
|
-
def?: D
|
|
342
|
-
): Dive<O, K extends string[] ? K : [ K ], D>,
|
|
343
|
-
},
|
|
344
|
-
[has]: {
|
|
345
|
-
// <O extends Obj>(this: O, k: string): boolean,
|
|
346
|
-
// <O extends Obj>(this: O, k: string): k is (ObjMode<O> extends 'rec' ? keyof O : any),
|
|
347
|
-
// <O extends Obj>(this: O, k: string): k is (ObjMode<O> extends 'rec' ? keyof O : any),
|
|
348
|
-
|
|
349
|
-
// <O extends Obj, K extends keyof any>(this: O, k: K): this is { [K]: O[keyof O] }
|
|
350
|
-
|
|
351
|
-
<O extends Obj>(this: O, k: unknown): k is keyof O
|
|
352
|
-
|
|
353
|
-
},
|
|
354
|
-
[map]: {
|
|
355
|
-
<
|
|
356
|
-
O extends Obj,
|
|
357
|
-
Fn extends (v: ObjVals<O>, k: ObjKeys<O>) => any
|
|
358
|
-
>(
|
|
359
|
-
this: O,
|
|
360
|
-
fn: Fn
|
|
361
|
-
): { [K in keyof O]: Exclude<ReturnType<Fn>, Skip> },
|
|
362
|
-
},
|
|
363
|
-
[mapk]: {
|
|
364
|
-
<
|
|
365
|
-
O extends Obj,
|
|
366
|
-
Fn extends (v: O[keyof O], k: ObjKeys<O>) => undefined | [ string, any ]
|
|
367
|
-
>(
|
|
368
|
-
this: O,
|
|
369
|
-
fn: Fn
|
|
370
|
-
): { [K in Exclude<ReturnType<Fn>, Skip>[0]]: Exclude<ReturnType<Fn>, Skip>[1] },
|
|
371
|
-
},
|
|
372
|
-
[merge]: {
|
|
373
|
-
<
|
|
374
|
-
O1 extends Obj,
|
|
375
|
-
O2 extends Obj
|
|
376
|
-
>(
|
|
377
|
-
this: readonly O1,
|
|
378
|
-
val: readonly O2
|
|
379
|
-
): O1 & O2,
|
|
380
|
-
},
|
|
381
|
-
[slice]: {
|
|
382
|
-
<O extends Obj, K extends readonly (keyof O)[]>(this: O, keys: K): { [P in K[number]]: SkipNever<O[P]> }
|
|
383
|
-
},
|
|
384
|
-
[slash]: {
|
|
385
|
-
<
|
|
386
|
-
O extends Obj,
|
|
387
|
-
T extends readonly (keyof O)[]
|
|
388
|
-
>(
|
|
389
|
-
this: O,
|
|
390
|
-
keys: T
|
|
391
|
-
): { [K in keyof O as Exclude<keyof O, T[number]>]: O[K] }
|
|
392
|
-
},
|
|
393
|
-
[toArr]: {
|
|
394
|
-
<
|
|
395
|
-
O extends Obj,
|
|
396
|
-
Fn extends (v: O[keyof O], k: ObjKeys<O>) => any
|
|
397
|
-
>(
|
|
398
|
-
this: O,
|
|
399
|
-
fn: Fn
|
|
400
|
-
): Exclude<ReturnType<Fn>, Skip>[],
|
|
401
|
-
},
|
|
402
|
-
[built]: {
|
|
403
|
-
(this: Obj<any>): any
|
|
404
|
-
// <O extends Obj>(this: O): Obj<ObjLeafs<O>>,
|
|
405
|
-
},
|
|
406
|
-
[apart]: {
|
|
407
|
-
// Iterates all terminal values in an object tree, along with the dive key needed to access them
|
|
408
|
-
<O extends Obj>(this: O): Generator<{ dive: string[], val: any }>,
|
|
409
|
-
},
|
|
410
|
-
[dive]: {
|
|
411
|
-
<O extends Obj, Cmps extends (keyof any)[], D extends any = Skip>(this: O, cmps: readonly Cmps, def: D): Dive<O, Cmps> | D,
|
|
412
|
-
},
|
|
413
|
-
[count]: {
|
|
414
|
-
<O extends Obj>(this: O): number,
|
|
415
|
-
},
|
|
416
|
-
[Symbol.iterator]: {
|
|
417
|
-
<O extends Obj>(this: O): Iterator<[ ObjKeys<O>, ObjVals<O> ]>
|
|
418
|
-
},
|
|
419
|
-
$$inspect: <V>(this: V) => { v: V }
|
|
420
|
-
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface ObjectConstructor {}
|
|
170
|
+
interface Object {
|
|
171
|
+
[empty]: () => boolean,
|
|
172
|
+
[at]: <O extends Obj, K extends string | string[], D extends any = undefined>(this: O, k: K, def?: D) => Dive<O, K extends string[] ? K : [ K ], D>,
|
|
173
|
+
[has]: <O extends Obj>(this: O, k: unknown) => k is keyof O,
|
|
174
|
+
[map]: <O extends Obj, Fn extends (v: ObjVals<O>, k: ObjKeys<O>) => any>(this: O, fn: Fn) => { [K in keyof O]: Exclude<ReturnType<Fn>, Skip> },
|
|
175
|
+
[mapk]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => undefined | [ string, any ]>(this: O, fn: Fn) => { [K: string]: any },
|
|
176
|
+
[merge]: <O1 extends Obj, O2 extends Obj>(this: O1, val: O2) => O1 & O2,
|
|
177
|
+
[slice]: <O extends Obj, K extends readonly (keyof O)[]>(this: O, keys: K) => { [P in K[number]]: SkipNever<O[P]> },
|
|
178
|
+
[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] },
|
|
179
|
+
[toArr]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => any>(this: O, fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
|
|
180
|
+
[count]: () => number,
|
|
181
|
+
[group]: <O extends Obj, G extends string>(this: O, fn: (v: O[keyof O]) => Skip | G) => { [K in G]?: Partial<O> },
|
|
182
|
+
[Symbol.iterator]: <O extends Obj>(this: O) => Iterator<[ ObjKeys<O>, ObjVals<O> ]>
|
|
183
|
+
}
|
|
421
184
|
|
|
422
185
|
interface PromiseConstructor {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
}
|
|
428
|
-
interface Promise<T> {
|
|
429
|
-
interface PromiseLater<T=void> extends Promise<T>, ProtoWithSymbols {
|
|
186
|
+
[allArr]: PromiseConstructor['all'],
|
|
187
|
+
[allObj]: <O extends { [K: string]: Promise<any> }>(obj: O) => Promise<{ [K in keyof O]: Awaited<O[K]> }>,
|
|
188
|
+
[later]: <T=void>() => PromiseLater<T>
|
|
189
|
+
}
|
|
190
|
+
interface Promise<T> {}
|
|
191
|
+
interface PromiseLater<T=void> extends Promise<T> {
|
|
430
192
|
resolve: T extends void ? () => void : (v: T) => void,
|
|
431
193
|
reject: (err: any) => void
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
interface SetConstructor {};
|
|
435
|
-
interface Set<T> extends ProtoWithSymbols {
|
|
436
|
-
[toArr]: <V>(fn: (val: T, ind: number) => V) => V[],
|
|
437
|
-
[rem]: (val: T) => void
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
interface MapConstructor {};
|
|
442
|
-
interface Map<K, V> extends ProtoWithSymbols {
|
|
443
|
-
[add]: (k: K, v: V) => void,
|
|
444
|
-
[toArr]: <T>(fn: (val: V, key: K) => T) => T[],
|
|
445
|
-
[toObj]: <T>(fn: (val: V, key: K) => T) => { [Key in K]: T },
|
|
446
|
-
[rem]: (key: K) => void
|
|
447
|
-
};
|
|
194
|
+
}
|
|
448
195
|
|
|
196
|
+
interface SetConstructor {}
|
|
197
|
+
interface Set<T> {
|
|
198
|
+
[count]: () => number,
|
|
199
|
+
[empty]: () => boolean,
|
|
200
|
+
[find]: (fn: (val: T) => any) => ({ found: true, val: T } | { found: false, val: null }),
|
|
201
|
+
[map]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
|
|
202
|
+
[toArr]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
|
|
203
|
+
[toObj]: <R extends readonly [string, any]>(fn: (val: T) => Skip | R) => { [K: string]: any },
|
|
204
|
+
[rem]: (val: T) => void
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
interface MapConstructor {}
|
|
208
|
+
interface Map<K, V> {
|
|
209
|
+
[add]: (k: K, v: V) => void,
|
|
210
|
+
[count]: () => number,
|
|
211
|
+
[empty]: () => boolean,
|
|
212
|
+
[find]: (fn: (val: V, key: K) => any) => ({ found: true, val: V, key: K } | { found: false, val: null, key: null }),
|
|
213
|
+
[map]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [Key: string]: any },
|
|
214
|
+
[toArr]: <T>(fn: (val: V, key: K) => T) => Exclude<T, Skip>[],
|
|
215
|
+
[toObj]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [Key: string]: any },
|
|
216
|
+
[rem]: (key: K) => void
|
|
217
|
+
}
|
|
218
|
+
|
|
449
219
|
interface StringConstructor {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
interface String
|
|
459
|
-
[
|
|
460
|
-
[
|
|
461
|
-
[
|
|
462
|
-
[
|
|
220
|
+
[base32]: string,
|
|
221
|
+
[base36]: string,
|
|
222
|
+
[base62]: string,
|
|
223
|
+
[base64Url]: string,
|
|
224
|
+
[base64Std]: string,
|
|
225
|
+
[baseline]: (str: string) => string,
|
|
226
|
+
[charset]: (str: string) => CharSet,
|
|
227
|
+
}
|
|
228
|
+
interface String {
|
|
229
|
+
[code]: (ind?: number) => number,
|
|
230
|
+
[count]: () => number,
|
|
231
|
+
[has]: (s: string) => boolean,
|
|
232
|
+
[padHead]: (n: number, s?: string) => string,
|
|
233
|
+
[padTail]: (n: number, s?: string) => string,
|
|
463
234
|
[toNum]: (chrs: string | CharSet) => bigint,
|
|
464
|
-
[hasHead]<H extends string>(this: string, head: H)
|
|
465
|
-
[hasTail]<T extends string>(this: string, tail: T)
|
|
466
|
-
[upper]<S extends string>(this: S)
|
|
467
|
-
[lower]<S extends string>(this: S)
|
|
235
|
+
[hasHead]: <H extends string>(this: string, head: H) => this is `${H}${string}`,
|
|
236
|
+
[hasTail]: <T extends string>(this: string, tail: T) => this is `${string}${T}`,
|
|
237
|
+
[upper]: <S extends string>(this: S) => Uppercase<S>,
|
|
238
|
+
[lower]: <S extends string>(this: S) => Lowercase<S>,
|
|
468
239
|
[cut]: {
|
|
469
240
|
(str: string, cuts: 1): [ string, string ],
|
|
470
241
|
(str: string, cuts: 2): [ string, string, string ],
|
|
@@ -476,13 +247,9 @@ declare global {
|
|
|
476
247
|
(amount: number, char?: string): string,
|
|
477
248
|
(str: string): string
|
|
478
249
|
}
|
|
479
|
-
}
|
|
250
|
+
}
|
|
480
251
|
|
|
481
252
|
}
|
|
482
253
|
|
|
483
254
|
export {};
|
|
484
255
|
|
|
485
|
-
// Type testing - these aren't exported!
|
|
486
|
-
type Dive0 = Dive<{ a: { b: { c: 'xyz' } } }, [ 'a', 'b', 'c' ]>;
|
|
487
|
-
type Dive1 = Dive<{ a: { b: { c: 'xyz' } } }, [ 'a', 'b' ]>;
|
|
488
|
-
type Dive2 = Dive<{ a: { b: { c: 'xyz' } } }, [ 'a', 'b', 'd' ]>;
|