@gershy/clearing 0.0.11 → 0.0.12

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/mjs/main.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ import './sideEffects';
1
2
  declare const applyClearing: () => void;
2
3
  export default applyClearing;
@@ -0,0 +1,306 @@
1
+ declare global {
2
+
3
+ // Util
4
+ type Fn<A extends any[] = any[], T = any> = (...args: A) => T;
5
+ type Obj<V = any> = { [k: string]: V };
6
+
7
+ // Differentiate between "map" and "rec" ("record") - maps have arbitrary keys; recs have fixed keys
8
+ type ObjMode<O extends { [K: string]: any }> = O extends { [K in infer KK]: any } ? (string extends KK ? 'map' : 'rec') : never;
9
+ type ObjKeys<O extends Obj> = Extract<keyof O, string> | `${Extract<keyof O, number>}`; // Convert numbers to strings; ignores symbols
10
+ type ObjVals<O extends Obj> = O[Extract<keyof O, string>];
11
+
12
+ type Json = null | boolean | number | string | Json[] | { [K: string]: Json };
13
+ type Skip = undefined;
14
+ type SkipNever<V> = V extends Skip ? Skip extends V ? never : V : V;
15
+
16
+ type Dive<O extends Obj, K extends readonly string[], D = undefined> =
17
+ K extends [ infer K0 extends string, ...infer KM extends string[] ]
18
+ ? K0 extends keyof O
19
+ ? (ObjMode<O> extends 'map' ? D : never) | Dive<O[K0], KM, D>
20
+ : D
21
+ : O;
22
+
23
+ type CharSet = {
24
+ str: string,
25
+ size: bigint,
26
+ charVal: (c: string) => bigint,
27
+ valChar: (n: bigint) => string
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
+
61
+ // <SYMBOLS> :: declarations :: /const ([a-zA-Z0-9]+)[ ]*[:][ ]*unique symbol;/
62
+ const add: unique symbol;
63
+ const allArr: unique symbol;
64
+ const allObj: unique symbol;
65
+ const at: unique symbol;
66
+ const assert: unique symbol;
67
+ const base32: unique symbol;
68
+ const base36: unique symbol;
69
+ const base62: unique symbol;
70
+ const base64Std: unique symbol;
71
+ const base64Url: unique symbol;
72
+ const baseline: unique symbol;
73
+ const bind: unique symbol;
74
+ const bits: unique symbol;
75
+ const char: unique symbol;
76
+ const charset: unique symbol;
77
+ const code: unique symbol;
78
+ const count: unique symbol;
79
+ const cut: unique symbol;
80
+ const dive: unique symbol;
81
+ const empty: unique symbol;
82
+ const find: unique symbol;
83
+ const fire: unique symbol;
84
+ const group: unique symbol;
85
+ const has: unique symbol;
86
+ const hasHead: unique symbol;
87
+ const hasTail: unique symbol;
88
+ const indent: unique symbol;
89
+ const int32: unique symbol;
90
+ const int64: unique symbol;
91
+ const isInt: unique symbol;
92
+ const later: unique symbol;
93
+ const limn: unique symbol;
94
+ const lower: unique symbol;
95
+ const map: unique symbol;
96
+ const mapk: unique symbol;
97
+ const merge: unique symbol;
98
+ const mod: unique symbol;
99
+ const padHead: unique symbol;
100
+ const padTail: unique symbol;
101
+ const rem: unique symbol;
102
+ const slash: unique symbol;
103
+ const slice: unique symbol;
104
+ const suppress: unique symbol;
105
+ const toArr: unique symbol;
106
+ const toNum: unique symbol;
107
+ const toObj: unique symbol;
108
+ const toStr: unique symbol;
109
+ const upper: unique symbol;
110
+ // </SYMBOLS>
111
+
112
+ // Adding symbol properties to Object.prototype will cause typescript to think these properties
113
+ // are also available for extending types, e.g. Array - to avoid this we merge in an object which
114
+ // defines every symbol as `undefined`!
115
+ type SymbolsProto = {
116
+ // <SYMBOLS> :: SymbolsProto :: /\[([a-zA-Z0-9]+)\][ ]*[:][ ]*undefined
117
+ [add]: undefined,
118
+ [allArr]: undefined,
119
+ [allObj]: undefined,
120
+ [at]: undefined,
121
+ [assert]: undefined,
122
+ [base32]: undefined,
123
+ [base36]: undefined,
124
+ [base62]: undefined,
125
+ [base64Std]: undefined,
126
+ [base64Url]: undefined,
127
+ [baseline]: undefined,
128
+ [bind]: undefined,
129
+ [bits]: undefined,
130
+ [char]: undefined,
131
+ [charset]: undefined,
132
+ [code]: undefined,
133
+ [count]: undefined,
134
+ [cut]: undefined,
135
+ [dive]: undefined,
136
+ [empty]: undefined,
137
+ [find]: undefined,
138
+ [fire]: undefined,
139
+ [group]: undefined,
140
+ [has]: undefined,
141
+ [hasHead]: undefined,
142
+ [hasTail]: undefined,
143
+ [indent]: undefined,
144
+ [int32]: undefined,
145
+ [int64]: undefined,
146
+ [isInt]: undefined,
147
+ [later]: undefined,
148
+ [limn]: undefined,
149
+ [lower]: undefined,
150
+ [map]: undefined,
151
+ [mapk]: undefined,
152
+ [merge]: undefined,
153
+ [mod]: undefined,
154
+ [padHead]: undefined,
155
+ [padTail]: undefined,
156
+ [rem]: undefined,
157
+ [slash]: undefined,
158
+ [slice]: undefined,
159
+ [suppress]: undefined,
160
+ [toArr]: undefined,
161
+ [toNum]: undefined,
162
+ [toObj]: undefined,
163
+ [toStr]: undefined,
164
+ [upper]: undefined
165
+ // </SYMBOLS>
166
+ };
167
+
168
+ interface ErrorConstructor {
169
+ [assert]: <V = any>(args: V, fn: (args: V) => boolean) => void
170
+ }
171
+ interface Error extends SymbolsProto {
172
+ [mod]: (props: { [K: string]: any }) => Error,
173
+ [fire]: (props?: { [K: string]: any }) => never,
174
+ [suppress]: () => Error,
175
+ [limn]: (seen?: Map<any, any>) => (Obj<Json> & {
176
+ form: string,
177
+ msg: string,
178
+ trace: string[],
179
+ cause: null | ReturnType<Error[typeof limn]>
180
+ })
181
+ }
182
+
183
+ interface ArrayConstructor {}
184
+ interface Array<T> extends SymbolsProto {
185
+ [has]: (val: unknown) => boolean,
186
+ [map]: <Fn extends (v: T, i: number) => any>(fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
187
+ [add]: <TT extends T>(val: TT) => TT,
188
+ [rem]: <TT extends T>(val: TT) => void,
189
+ [count]: () => number,
190
+ [empty]: () => boolean,
191
+ [toObj]: <R extends readonly [string, any]>(fn: (v: T, n: number) => Skip | R) => { [K: string]: any },
192
+ [find]: (fn: (val: T, n: number) => any) => ({ found: true, val: T, ind: number } | { found: false, val: null, ind: null }),
193
+ [group]: <G extends string>(fn: (v: T) => Skip | G) => { [K in G]?: T[] }
194
+ }
195
+
196
+ interface FunctionConstructor {}
197
+ interface Function extends SymbolsProto {
198
+ [bind]: <Fn extends (...args: any[]) => any, To>(this: Fn, to: To) => ((...args: Parameters<Fn> extends [ infer A0, ...infer AM ] ? AM : never) => ReturnType<Fn>)
199
+ }
200
+
201
+ interface NumberConstructor {
202
+ [int32]: number,
203
+ [int64]: number
204
+ }
205
+ interface Number extends SymbolsProto {
206
+ [char]: () => string,
207
+ [isInt]: () => boolean,
208
+ [toStr]: (str: string | CharSet, len?: number) => string,
209
+ [toArr]: <T>(fn: (n: number) => T) => T[],
210
+ [toObj]: <R extends readonly [string, any]>(fn: (n: number) => Skip | R) => { [K: string]: any },
211
+ [bits]: () => Generator<number>,
212
+ [Symbol.iterator]: () => Generator<number>
213
+ }
214
+
215
+ interface BigIntConstructor {}
216
+ interface BigInt extends SymbolsProto {
217
+ [toStr]: (str: string | CharSet, len?: number) => string
218
+ }
219
+
220
+ interface ObjectConstructor {}
221
+ interface Object {
222
+ [empty]: () => boolean,
223
+ [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>,
224
+ [has]: <O extends Obj>(this: O, k: unknown) => k is keyof O,
225
+ [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> },
226
+ [mapk]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => undefined | [ string, any ]>(this: O, fn: Fn) => { [K: string]: any },
227
+ [merge]: <O1 extends Obj, O2 extends Obj>(this: O1, val: O2) => O1 & O2,
228
+ [slice]: <O extends Obj, K extends readonly (keyof O)[]>(this: O, keys: K) => { [P in K[number]]: SkipNever<O[P]> },
229
+ [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] },
230
+ [toArr]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => any>(this: O, fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
231
+ [count]: () => number,
232
+ [group]: <O extends Obj, G extends string>(this: O, fn: (v: O[keyof O]) => Skip | G) => { [K in G]?: Partial<O> },
233
+ [Symbol.iterator]: <O extends Obj>(this: O) => Iterator<[ ObjKeys<O>, ObjVals<O> ]>
234
+ }
235
+
236
+ interface PromiseConstructor {
237
+ [allArr]: PromiseConstructor['all'],
238
+ [allObj]: <O extends { [K: string]: Promise<any> }>(obj: O) => Promise<{ [K in keyof O]: Awaited<O[K]> }>,
239
+ [later]: <T=void>() => PromiseLater<T>
240
+ }
241
+ interface Promise<T> {}
242
+ interface PromiseLater<T=void> extends Promise<T> {
243
+ resolve: T extends void ? () => void : (v: T) => void,
244
+ reject: (err: any) => void
245
+ }
246
+
247
+ interface SetConstructor {}
248
+ interface Set<T> extends SymbolsProto {
249
+ [count]: () => number,
250
+ [empty]: () => boolean,
251
+ [find]: (fn: (val: T) => any) => ({ found: true, val: T } | { found: false, val: null }),
252
+ [map]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
253
+ [toArr]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
254
+ [toObj]: <R extends readonly [string, any]>(fn: (val: T) => Skip | R) => { [K: string]: any },
255
+ [rem]: (val: T) => void
256
+ }
257
+
258
+ interface MapConstructor {}
259
+ interface Map<K, V> extends SymbolsProto {
260
+ [add]: (k: K, v: V) => void,
261
+ [count]: () => number,
262
+ [empty]: () => boolean,
263
+ [find]: (fn: (val: V, key: K) => any) => ({ found: true, val: V, key: K } | { found: false, val: null, key: null }),
264
+ [map]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [Key: string]: any },
265
+ [toArr]: <T>(fn: (val: V, key: K) => T) => Exclude<T, Skip>[],
266
+ [toObj]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [Key: string]: any },
267
+ [rem]: (key: K) => void
268
+ }
269
+
270
+ interface StringConstructor {
271
+ [base32]: string,
272
+ [base36]: string,
273
+ [base62]: string,
274
+ [base64Url]: string,
275
+ [base64Std]: string,
276
+ [baseline]: (str: string) => string,
277
+ [charset]: (str: string) => CharSet,
278
+ }
279
+ interface String extends SymbolsProto {
280
+ [code]: (ind?: number) => number,
281
+ [count]: () => number,
282
+ [has]: (s: string) => boolean,
283
+ [padHead]: (n: number, s?: string) => string,
284
+ [padTail]: (n: number, s?: string) => string,
285
+ [toNum]: (chrs: string | CharSet) => bigint,
286
+ [hasHead]: <H extends string>(this: string, head: H) => this is `${H}${string}`,
287
+ [hasTail]: <T extends string>(this: string, tail: T) => this is `${string}${T}`,
288
+ [upper]: <S extends string>(this: S) => Uppercase<S>,
289
+ [lower]: <S extends string>(this: S) => Lowercase<S>,
290
+ [cut]: {
291
+ (str: string, cuts: 1): [ string, string ],
292
+ (str: string, cuts: 2): [ string, string, string ],
293
+ (str: string, cuts: 3): [ string, string, string, string ],
294
+ (str: string, cuts: 4): [ string, string, string, string, string ],
295
+ (str: string, cuts?: number): string[]
296
+ },
297
+ [indent]: {
298
+ (amount: number, char?: string): string,
299
+ (str: string): string
300
+ }
301
+ }
302
+
303
+ }
304
+
305
+ export {};
306
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gershy/clearing",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "description": "Adds the features you always wish javascript had!",
5
5
  "keywords": [
6
6
  "clearing",
@@ -29,18 +29,16 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "import": "./cmp/mjs/main.js",
32
- "require": "./cmp/cjs/main.js",
33
- "types": "./cmp/types/sideEffects.d.ts"
32
+ "require": "./cmp/cjs/main.js"
34
33
  }
35
34
  },
36
- "types": "./cmp/types/sideEffects.d.ts",
37
35
  "scripts": {
38
36
  "test": "npm run ts.check && npx tsx ./src/main.test.ts",
39
37
  "ts.check": "npx tsc --noEmit",
40
38
  "build.cjs": "tsc -p ts/tsconfig.cjs.json",
41
39
  "build.mjs": "tsc -p ts/tsconfig.mjs.json",
42
40
  "build.types": "npx tsx ./build.ts copyGlobalTypes",
43
- "build": "npx tsx ./build.ts removeCmp && npm run build.cjs && npm run build.mjs && npm run build.types",
41
+ "build": "npx tsx ./build.ts removeCmp && npm run build.cjs && npm run build.mjs && npm run build.types && npx tsx ./build.ts importSideEffects",
44
42
  "git.pub": "npm run test && git add --all && git commit -m \"automated\" && git push",
45
43
  "npm.login": "npm login",
46
44
  "npm.pub": "npm run test && npm run build && npm publish --access public"