@gershy/clearing 0.0.29 → 0.0.30

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 CHANGED
@@ -1,30 +1,3 @@
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: Buffer): 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;
19
- type Then = {
20
- <V, R0 = V, R1 = never>(val: Promise<V>, rsv?: (v: V) => R0, rjc?: (e: any) => R1): Promise<R0 | R1>;
21
- <V, R0 = V, R1 = never>(val: V, rsv?: (v: V) => R0, rjc?: (e: any) => R1): R0 | R1;
22
- };
23
- export declare const then: Then;
24
- type Safe = {
25
- <V, R0 = never>(fn: () => Promise<V>, rjc?: (e: any) => R0): Promise<V | R0>;
26
- <V, R0 = never>(fn: () => V, rjc?: (e: any) => R0): Promise<V | R0>;
27
- };
28
- export declare const safe: Safe;
29
2
  declare const applyClearing: () => void;
30
3
  export default applyClearing;
package/cmp/cjs/main.js CHANGED
@@ -1,65 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safe = exports.then = 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;
30
- const then = (val, rsv = (v => v), rjc = ((e) => { throw e; })) => {
31
- // Act on `val` regardless of whether it's a Promise or immediate value; return `rsv(val)`
32
- // either immediately or as a Promise
33
- if ((0, exports.inCls)(val, Promise))
34
- return val.then(rsv).catch(rjc);
35
- try {
36
- return rsv(val);
37
- }
38
- catch (err) {
39
- return rjc(err);
40
- }
41
- };
42
- exports.then = then;
43
- const safe = (fn, rjc = e => { throw e; }) => {
44
- // Execute a function which returns a value either synchronously or asynchronously; in both cases
45
- // allows errors occurring from function execution to be handled
46
- try {
47
- return (0, exports.then)(fn(), v => v, rjc);
48
- }
49
- catch (err) {
50
- return rjc(err);
51
- }
52
- };
53
- exports.safe = safe;
54
3
  const applyClearing = (() => {
55
- const global = globalThis;
56
4
  // Prevent multiple installations...
57
- const pfx = '@gershy/clearing';
58
- const memSym = Symbol.for(`${pfx}:mem`);
5
+ const global = globalThis;
6
+ const memSym = Symbol.for(`@gershy/clearing:mem`);
59
7
  if (global[memSym])
60
8
  return;
61
9
  global[memSym] = true;
62
- const [enc, dec] = [new TextEncoder(), new TextDecoder()];
10
+ const getClsName = i => {
11
+ if (i === null)
12
+ return 'Null';
13
+ if (i === undefined)
14
+ return 'Undef';
15
+ if (i !== i)
16
+ return 'Nan';
17
+ return Object.getPrototypeOf(i)?.constructor.name ?? 'Prototypeless';
18
+ };
19
+ const getCls = i => Object.getPrototypeOf(i)?.constructor ?? null;
20
+ const isCls = (i, C) => {
21
+ // NaN only matches against the NaN primitive (not the Number Form)
22
+ if (i !== i)
23
+ return C !== C;
24
+ // `null` and `undefined` only match to themselves
25
+ if (i == null)
26
+ return i === C;
27
+ // Otherwise strictly check the constructor
28
+ return Object.getPrototypeOf(i).constructor === C;
29
+ };
30
+ const inCls = (i, C) => i instanceof C;
31
+ const skip = undefined;
32
+ const then = (val, rsv = (v => v), rjc = ((e) => { throw e; })) => {
33
+ // Act on `val` regardless of whether it's a Promise or immediate value; return `rsv(val)`
34
+ // either immediately or as a Promise
35
+ if (inCls(val, Promise))
36
+ return val.then(rsv).catch(rjc);
37
+ try {
38
+ return rsv(val);
39
+ }
40
+ catch (err) {
41
+ return rjc(err);
42
+ }
43
+ };
44
+ const safe = (fn, rjc = e => { throw e; }) => {
45
+ // Execute a function which returns a value either synchronously or asynchronously; in both cases
46
+ // allows errors occurring from function execution to be handled
47
+ try {
48
+ return then(fn(), v => v, rjc);
49
+ }
50
+ catch (err) {
51
+ return rjc(err);
52
+ }
53
+ };
63
54
  const symNames = [
64
55
  // <SYMBOLS> :: definitions :: /[']([a-zA-Z0-9]+)[']/
65
56
  'add',
@@ -73,13 +64,11 @@ const applyClearing = (() => {
73
64
  'base64Std',
74
65
  'base64Url',
75
66
  'baseline',
76
- 'bind',
77
67
  'char',
78
68
  'charset',
79
69
  'code',
80
70
  'count',
81
71
  'cut',
82
- 'dive',
83
72
  'empty',
84
73
  'find',
85
74
  'fire',
@@ -112,24 +101,33 @@ const applyClearing = (() => {
112
101
  'upper'
113
102
  // </SYMBOLS>
114
103
  ];
115
- const syms = Object.fromEntries(symNames.map(term => [term, Symbol(`${pfx}:${term}`)]));
116
- Object.assign(global, { ...syms });
104
+ Object.assign(global, {
105
+ clearing: {
106
+ getClsName, getCls, isCls, inCls, then, safe, skip,
107
+ ...Object.fromEntries(symNames.map(term => [term, Symbol(`@gershy/clearing:${term}`)]))
108
+ }
109
+ });
110
+ const {
111
+ // <SYMBOLS> :: variables :: /([a-zA-Z0-9]+)/
112
+ add, allArr, allObj, at, assert, base32, base36, base62, base64Std, base64Url, baseline, char, charset, code, count, cut, empty, find, fire, group, has, hasHead, hasTail, indent, int32, int64, isInt, later, limn, lower, map, mapk, merge, mod, padHead, padTail, rem, slash, slice, suppress, toArr, toBin, toNum, toObj, toStr, upper,
113
+ // </SYMBOLS>
114
+ } = global.clearing;
117
115
  const assignSyms = (Cls, def) => {
118
116
  const protoVals = [];
119
- for (const key of Reflect.ownKeys(def)) {
120
- if (!(0, exports.isCls)(key, Symbol))
121
- throw Object.assign(Error('invalid proto key'), { Cls, keyClsName: (0, exports.getClsName)(key), key });
122
- protoVals.push([key, def[key]]);
123
- }
117
+ for (const key of Reflect.ownKeys(def))
118
+ if (!isCls(key, Symbol))
119
+ throw Object.assign(Error('invalid proto key'), { Cls, keyClsName: getClsName(key), key });
120
+ else
121
+ protoVals.push([key, def[key]]);
124
122
  // Assign class properties
125
123
  for (const [sym, value] of protoVals)
126
124
  Object.defineProperty(Cls, sym, { enumerable: false, value });
127
125
  };
128
126
  assignSyms(Object, {});
129
127
  assignSyms(Object.prototype, {
130
- [at](cmps, def = exports.skip) {
128
+ [at](cmps, def = skip) {
131
129
  let ptr = this;
132
- if (!(0, exports.isCls)(cmps, Array))
130
+ if (!isCls(cmps, Array))
133
131
  cmps = [cmps];
134
132
  for (const c of cmps) {
135
133
  if (ptr[has](c))
@@ -153,7 +151,7 @@ const applyClearing = (() => {
153
151
  const ret = {};
154
152
  for (const [k, v] of this) {
155
153
  const g = fn(v, k);
156
- if (g === exports.skip)
154
+ if (g === skip)
157
155
  continue;
158
156
  if (!ret[has](g))
159
157
  ret[g] = {};
@@ -166,7 +164,7 @@ const applyClearing = (() => {
166
164
  const ret = Object.assign({}, this);
167
165
  for (const k in ret) {
168
166
  const v = fn(ret[k], k);
169
- if (v !== exports.skip)
167
+ if (v !== skip)
170
168
  ret[k] = v;
171
169
  else
172
170
  delete ret[k];
@@ -177,7 +175,7 @@ const applyClearing = (() => {
177
175
  const arr = [];
178
176
  for (const k in this) {
179
177
  const r = fn(this[k], k);
180
- if (r !== exports.skip)
178
+ if (r !== skip)
181
179
  arr.push(r);
182
180
  }
183
181
  return Object.fromEntries(arr);
@@ -185,17 +183,17 @@ const applyClearing = (() => {
185
183
  [merge](o) {
186
184
  for (const [k, v] of o) {
187
185
  // `skip` can be passed to remove properties
188
- if (v === exports.skip) {
186
+ if (v === skip) {
189
187
  delete this[k];
190
188
  continue;
191
189
  }
192
190
  // Incoming non-Object properties are simple
193
- if (!(0, exports.isCls)(v, Object)) {
191
+ if (!isCls(v, Object)) {
194
192
  this[k] = v;
195
193
  continue;
196
194
  }
197
195
  // `v` is an Object; existing non-Object replaced with `{}`
198
- if (!this[has](k) || !(0, exports.isCls)(this[k], Object))
196
+ if (!this[has](k) || !isCls(this[k], Object))
199
197
  this[k] = {};
200
198
  // And simply recurse!
201
199
  this[k][merge](v);
@@ -211,13 +209,13 @@ const applyClearing = (() => {
211
209
  [slice](p) {
212
210
  // >> { a: 1, b: 2, c: 3, d: 4 }.slice([ 'b', 'd' ]);
213
211
  // { b: 2, d: 4 }
214
- return p[toObj](p => this[has](p) ? [p, this[p]] : exports.skip);
212
+ return p[toObj](p => this[has](p) ? [p, this[p]] : skip);
215
213
  },
216
214
  [toArr](fn) {
217
215
  const ret = [];
218
216
  for (const k in this) {
219
217
  const r = fn(this[k], k);
220
- if (r !== exports.skip)
218
+ if (r !== skip)
221
219
  ret.push(r);
222
220
  }
223
221
  return ret;
@@ -247,7 +245,7 @@ const applyClearing = (() => {
247
245
  const ret = {};
248
246
  for (const elem of this) {
249
247
  const g = fn(elem);
250
- if (g === exports.skip)
248
+ if (g === skip)
251
249
  continue;
252
250
  if (!ret[has](g))
253
251
  ret[g] = [];
@@ -261,7 +259,7 @@ const applyClearing = (() => {
261
259
  const len = this.length;
262
260
  for (let i = 0; i < len; i++) {
263
261
  const r = it(this[i], i);
264
- if (r !== exports.skip)
262
+ if (r !== skip)
265
263
  ret.push(r);
266
264
  }
267
265
  return ret;
@@ -273,18 +271,19 @@ const applyClearing = (() => {
273
271
  const len = this.length;
274
272
  for (let i = 0; i < len; i++) {
275
273
  const r = it(this[i], i);
276
- if (r !== exports.skip)
274
+ if (r !== skip)
277
275
  ret.push(r);
278
276
  }
279
277
  return Object.fromEntries(ret);
280
278
  }
281
279
  });
280
+ const [enc, dec] = [new TextEncoder(), new TextDecoder()];
282
281
  assignSyms(String, {
283
282
  [baseline]: (str, seq = '| ') => {
284
283
  return str.split('\n')[map](ln => {
285
284
  const ind = ln.indexOf(seq);
286
285
  if (ind === -1)
287
- return exports.skip;
286
+ return skip;
288
287
  return ln.slice(ind + seq.length);
289
288
  }).join('\n');
290
289
  },
@@ -320,7 +319,7 @@ const applyClearing = (() => {
320
319
  [count]() { return this.length; },
321
320
  [cut](delim, cuts = 1) {
322
321
  // `cuts` defines # of cuts (resulting array length is `num + 1`)
323
- const split = this.split(delim, cuts < Infinity ? cuts : exports.skip);
322
+ const split = this.split(delim, cuts < Infinity ? cuts : skip);
324
323
  const numDelimsSplit = split.length - 1;
325
324
  const lenConsumed = 0
326
325
  + split.reduce((a, s) => a + s.length, 0)
@@ -336,7 +335,7 @@ const applyClearing = (() => {
336
335
  if (!this)
337
336
  return this; // No-op on empty String (otherwise it would transform a 0-line string to a 1-line string)
338
337
  let indentStr;
339
- if ((0, exports.isCls)(args[0], String)) {
338
+ if (isCls(args[0], String)) {
340
339
  indentStr = args[0];
341
340
  }
342
341
  else {
@@ -350,7 +349,7 @@ const applyClearing = (() => {
350
349
  [padTail]: String.prototype.padEnd,
351
350
  [toBin]() { return enc.encode(this); },
352
351
  [toNum](cs = String[base62]) {
353
- if ((0, exports.isCls)(cs, String))
352
+ if (isCls(cs, String))
354
353
  cs = String[charset](cs);
355
354
  const base = cs.size;
356
355
  if (base === 1n)
@@ -375,7 +374,7 @@ const applyClearing = (() => {
375
374
  const ret = [];
376
375
  for (let i = 0; i < this; i++) {
377
376
  const r = fn(i);
378
- if (r !== exports.skip)
377
+ if (r !== skip)
379
378
  ret.push(r);
380
379
  }
381
380
  return Object.fromEntries(ret);
@@ -388,7 +387,7 @@ const applyClearing = (() => {
388
387
  // | singleChr.repeat(n - 1)
389
388
  if (this !== this)
390
389
  throw Error('nan');
391
- if ((0, exports.isCls)(cs, String))
390
+ if (isCls(cs, String))
392
391
  cs = String[charset](cs);
393
392
  const base = cs.size;
394
393
  if (base === 1n && padLen)
@@ -455,17 +454,17 @@ const applyClearing = (() => {
455
454
  seen.set(this, 'cycle(Error)');
456
455
  const { message, stack, cause, ...props } = this;
457
456
  return {
458
- form: (0, exports.getClsName)(this),
457
+ form: getClsName(this),
459
458
  msg: message,
460
- trace: stack?.split('\n').slice(1)[map](v => v.trim() ?? exports.skip) ?? [],
459
+ trace: (stack ?? '<no stack>').split('\n')[map](v => v.trim() ?? skip),
461
460
  ...props,
462
461
  cause: !cause ? null : cause[limn](seen)
463
462
  };
464
463
  },
465
464
  [mod](props = {} /* { cause, msg, message, ...more } */) {
466
- if ((0, exports.isCls)(props, Function))
465
+ if (isCls(props, Function))
467
466
  props = props(this.message, this);
468
- if ((0, exports.isCls)(props, String))
467
+ if (isCls(props, String))
469
468
  props = { message: props };
470
469
  const { cause = null, msg = null, message = msg ?? this.message, ...moreProps } = props;
471
470
  // - Assign `cause` to transfer props like fs "code" props, etc. - watch out, `cause` may be
@@ -473,12 +472,12 @@ const applyClearing = (() => {
473
472
  // - Assign `moreProps` to transfer any other properties
474
473
  // - Add `message` prop
475
474
  // - Only add `cause` prop if `cause` is non-null
476
- return Object.assign(this, (0, exports.inCls)(cause, Error) ? cause : {}, moreProps, cause ? { message, cause } : { message });
475
+ return Object.assign(this, inCls(cause, Error) ? cause : {}, moreProps, cause ? { message, cause } : { message });
477
476
  },
478
477
  [suppress]() {
479
478
  this[Symbol.for('@gershy.clearing.err.suppressed')] = true;
480
479
  if (this.cause) {
481
- const causes = (0, exports.inCls)(this.cause, Error) ? [this.cause] : this.cause;
480
+ const causes = inCls(this.cause, Error) ? [this.cause] : this.cause;
482
481
  for (const err of causes)
483
482
  err[suppress]();
484
483
  }
@@ -486,14 +485,14 @@ const applyClearing = (() => {
486
485
  }
487
486
  });
488
487
  assignSyms(Promise, {
489
- [allArr]: arr => Promise.all(arr).then(arr => arr.filter(v => v !== exports.skip)),
488
+ [allArr]: arr => Promise.all(arr).then(arr => arr.filter(v => v !== skip)),
490
489
  [allObj]: obj => {
491
490
  // Need to get `keys` immediately, in case `obj` mutates before resolution
492
491
  const keys = Object.keys(obj);
493
492
  return Promise.all(Object.values(obj)).then(vals => {
494
493
  const ret = {};
495
494
  for (const [i, k] of keys.entries())
496
- if (vals[i] !== exports.skip)
495
+ if (vals[i] !== skip)
497
496
  ret[k] = vals[i];
498
497
  return ret;
499
498
  });
@@ -519,7 +518,7 @@ const applyClearing = (() => {
519
518
  let ind = 0;
520
519
  for (const item of this) {
521
520
  const r = fn(item, ind++);
522
- if (r !== exports.skip)
521
+ if (r !== skip)
523
522
  ret.push(r);
524
523
  }
525
524
  return ret;
@@ -530,7 +529,7 @@ const applyClearing = (() => {
530
529
  let ind = 0;
531
530
  for (const item of this) {
532
531
  const r = fn(item, ind++);
533
- if (r !== exports.skip)
532
+ if (r !== skip)
534
533
  ret.push(r);
535
534
  }
536
535
  return ret;
@@ -539,7 +538,7 @@ const applyClearing = (() => {
539
538
  const ret = [];
540
539
  for (const item of this) {
541
540
  const r = fn(item);
542
- if (r !== exports.skip)
541
+ if (r !== skip)
543
542
  ret.push(r);
544
543
  }
545
544
  return Object.fromEntries(ret);
@@ -560,7 +559,7 @@ const applyClearing = (() => {
560
559
  const ret = [];
561
560
  for (const [k, v] of this) {
562
561
  const r = fn(v, k);
563
- if (r !== exports.skip)
562
+ if (r !== skip)
564
563
  ret.push(r);
565
564
  }
566
565
  return Object.fromEntries(ret);
@@ -570,7 +569,7 @@ const applyClearing = (() => {
570
569
  const ret = [];
571
570
  for (const [k, v] of this) {
572
571
  const r = fn(v, k);
573
- if (r !== exports.skip)
572
+ if (r !== skip)
574
573
  ret.push(r);
575
574
  }
576
575
  return ret;
@@ -579,7 +578,7 @@ const applyClearing = (() => {
579
578
  const ret = [];
580
579
  for (const [k, v] of this) {
581
580
  const r = fn(v, k);
582
- if (r !== exports.skip)
581
+ if (r !== skip)
583
582
  ret.push(r);
584
583
  }
585
584
  return Object.fromEntries(ret);
package/cmp/mjs/main.d.ts CHANGED
@@ -1,30 +1,3 @@
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: Buffer): 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;
19
- type Then = {
20
- <V, R0 = V, R1 = never>(val: Promise<V>, rsv?: (v: V) => R0, rjc?: (e: any) => R1): Promise<R0 | R1>;
21
- <V, R0 = V, R1 = never>(val: V, rsv?: (v: V) => R0, rjc?: (e: any) => R1): R0 | R1;
22
- };
23
- export declare const then: Then;
24
- type Safe = {
25
- <V, R0 = never>(fn: () => Promise<V>, rjc?: (e: any) => R0): Promise<V | R0>;
26
- <V, R0 = never>(fn: () => V, rjc?: (e: any) => R0): Promise<V | R0>;
27
- };
28
- export declare const safe: Safe;
29
2
  declare const applyClearing: () => void;
30
3
  export default applyClearing;
package/cmp/mjs/main.js CHANGED
@@ -1,56 +1,54 @@
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;
23
- export const then = (val, rsv = (v => v), rjc = ((e) => { throw e; })) => {
24
- // Act on `val` regardless of whether it's a Promise or immediate value; return `rsv(val)`
25
- // either immediately or as a Promise
26
- if (inCls(val, Promise))
27
- return val.then(rsv).catch(rjc);
28
- try {
29
- return rsv(val);
30
- }
31
- catch (err) {
32
- return rjc(err);
33
- }
34
- };
35
- export const safe = (fn, rjc = e => { throw e; }) => {
36
- // Execute a function which returns a value either synchronously or asynchronously; in both cases
37
- // allows errors occurring from function execution to be handled
38
- try {
39
- return then(fn(), v => v, rjc);
40
- }
41
- catch (err) {
42
- return rjc(err);
43
- }
44
- };
45
1
  const applyClearing = (() => {
46
- const global = globalThis;
47
2
  // Prevent multiple installations...
48
- const pfx = '@gershy/clearing';
49
- const memSym = Symbol.for(`${pfx}:mem`);
3
+ const global = globalThis;
4
+ const memSym = Symbol.for(`@gershy/clearing:mem`);
50
5
  if (global[memSym])
51
6
  return;
52
7
  global[memSym] = true;
53
- const [enc, dec] = [new TextEncoder(), new TextDecoder()];
8
+ const getClsName = i => {
9
+ if (i === null)
10
+ return 'Null';
11
+ if (i === undefined)
12
+ return 'Undef';
13
+ if (i !== i)
14
+ return 'Nan';
15
+ return Object.getPrototypeOf(i)?.constructor.name ?? 'Prototypeless';
16
+ };
17
+ const getCls = i => Object.getPrototypeOf(i)?.constructor ?? null;
18
+ const isCls = (i, C) => {
19
+ // NaN only matches against the NaN primitive (not the Number Form)
20
+ if (i !== i)
21
+ return C !== C;
22
+ // `null` and `undefined` only match to themselves
23
+ if (i == null)
24
+ return i === C;
25
+ // Otherwise strictly check the constructor
26
+ return Object.getPrototypeOf(i).constructor === C;
27
+ };
28
+ const inCls = (i, C) => i instanceof C;
29
+ const skip = undefined;
30
+ const then = (val, rsv = (v => v), rjc = ((e) => { throw e; })) => {
31
+ // Act on `val` regardless of whether it's a Promise or immediate value; return `rsv(val)`
32
+ // either immediately or as a Promise
33
+ if (inCls(val, Promise))
34
+ return val.then(rsv).catch(rjc);
35
+ try {
36
+ return rsv(val);
37
+ }
38
+ catch (err) {
39
+ return rjc(err);
40
+ }
41
+ };
42
+ const safe = (fn, rjc = e => { throw e; }) => {
43
+ // Execute a function which returns a value either synchronously or asynchronously; in both cases
44
+ // allows errors occurring from function execution to be handled
45
+ try {
46
+ return then(fn(), v => v, rjc);
47
+ }
48
+ catch (err) {
49
+ return rjc(err);
50
+ }
51
+ };
54
52
  const symNames = [
55
53
  // <SYMBOLS> :: definitions :: /[']([a-zA-Z0-9]+)[']/
56
54
  'add',
@@ -64,13 +62,11 @@ const applyClearing = (() => {
64
62
  'base64Std',
65
63
  'base64Url',
66
64
  'baseline',
67
- 'bind',
68
65
  'char',
69
66
  'charset',
70
67
  'code',
71
68
  'count',
72
69
  'cut',
73
- 'dive',
74
70
  'empty',
75
71
  'find',
76
72
  'fire',
@@ -103,15 +99,24 @@ const applyClearing = (() => {
103
99
  'upper'
104
100
  // </SYMBOLS>
105
101
  ];
106
- const syms = Object.fromEntries(symNames.map(term => [term, Symbol(`${pfx}:${term}`)]));
107
- Object.assign(global, { ...syms });
102
+ Object.assign(global, {
103
+ clearing: {
104
+ getClsName, getCls, isCls, inCls, then, safe, skip,
105
+ ...Object.fromEntries(symNames.map(term => [term, Symbol(`@gershy/clearing:${term}`)]))
106
+ }
107
+ });
108
+ const {
109
+ // <SYMBOLS> :: variables :: /([a-zA-Z0-9]+)/
110
+ add, allArr, allObj, at, assert, base32, base36, base62, base64Std, base64Url, baseline, char, charset, code, count, cut, empty, find, fire, group, has, hasHead, hasTail, indent, int32, int64, isInt, later, limn, lower, map, mapk, merge, mod, padHead, padTail, rem, slash, slice, suppress, toArr, toBin, toNum, toObj, toStr, upper,
111
+ // </SYMBOLS>
112
+ } = global.clearing;
108
113
  const assignSyms = (Cls, def) => {
109
114
  const protoVals = [];
110
- for (const key of Reflect.ownKeys(def)) {
115
+ for (const key of Reflect.ownKeys(def))
111
116
  if (!isCls(key, Symbol))
112
117
  throw Object.assign(Error('invalid proto key'), { Cls, keyClsName: getClsName(key), key });
113
- protoVals.push([key, def[key]]);
114
- }
118
+ else
119
+ protoVals.push([key, def[key]]);
115
120
  // Assign class properties
116
121
  for (const [sym, value] of protoVals)
117
122
  Object.defineProperty(Cls, sym, { enumerable: false, value });
@@ -270,6 +275,7 @@ const applyClearing = (() => {
270
275
  return Object.fromEntries(ret);
271
276
  }
272
277
  });
278
+ const [enc, dec] = [new TextEncoder(), new TextDecoder()];
273
279
  assignSyms(String, {
274
280
  [baseline]: (str, seq = '| ') => {
275
281
  return str.split('\n')[map](ln => {
@@ -448,7 +454,7 @@ const applyClearing = (() => {
448
454
  return {
449
455
  form: getClsName(this),
450
456
  msg: message,
451
- trace: stack?.split('\n').slice(1)[map](v => v.trim() ?? skip) ?? [],
457
+ trace: (stack ?? '<no stack>').split('\n')[map](v => v.trim() ?? skip),
452
458
  ...props,
453
459
  cause: !cause ? null : cause[limn](seen)
454
460
  };
@@ -1,7 +1,6 @@
1
1
  declare global {
2
2
 
3
3
  // Util
4
- type Fn<A extends any[] = any[], T = any> = (...args: A) => T;
5
4
  type Obj<V = any> = { [k: string]: V };
6
5
  type Arr<V = any> = V[];
7
6
 
@@ -18,6 +17,9 @@ declare global {
18
17
  type Dive<O extends Obj, K extends readonly string[], D = undefined> =
19
18
  K extends [ infer K0 extends string, ...infer KM extends string[] ]
20
19
  ? K0 extends keyof O
20
+ // For maps, where the type implies "any string" but we know that can't be the case, add
21
+ // the default value into the union of possible results, reflecting the possibility that
22
+ // the dive key misses
21
23
  ? (ObjMode<O> extends 'map' ? D : never) | Dive<O[K0], KM, D>
22
24
  : D
23
25
  : O;
@@ -29,121 +31,147 @@ declare global {
29
31
  valChar: (n: bigint) => string
30
32
  };
31
33
 
32
- // <SYMBOLS> :: declarations :: /const ([a-zA-Z0-9]+)[ ]*[:][ ]*unique symbol;/
33
- const add: unique symbol;
34
- const allArr: unique symbol;
35
- const allObj: unique symbol;
36
- const at: unique symbol;
37
- const assert: unique symbol;
38
- const base32: unique symbol;
39
- const base36: unique symbol;
40
- const base62: unique symbol;
41
- const base64Std: unique symbol;
42
- const base64Url: unique symbol;
43
- const baseline: unique symbol;
44
- const bind: unique symbol;
45
- const char: unique symbol;
46
- const charset: unique symbol;
47
- const code: unique symbol;
48
- const count: unique symbol;
49
- const cut: unique symbol;
50
- const dive: unique symbol;
51
- const empty: unique symbol;
52
- const find: unique symbol;
53
- const fire: unique symbol;
54
- const group: unique symbol;
55
- const has: unique symbol;
56
- const hasHead: unique symbol;
57
- const hasTail: unique symbol;
58
- const indent: unique symbol;
59
- const int32: unique symbol;
60
- const int64: unique symbol;
61
- const isInt: unique symbol;
62
- const later: unique symbol;
63
- const limn: unique symbol;
64
- const lower: unique symbol;
65
- const map: unique symbol;
66
- const mapk: unique symbol;
67
- const merge: unique symbol;
68
- const mod: unique symbol;
69
- const padHead: unique symbol;
70
- const padTail: unique symbol;
71
- const rem: unique symbol;
72
- const slash: unique symbol;
73
- const slice: unique symbol;
74
- const suppress: unique symbol;
75
- const toArr: unique symbol;
76
- const toBin: unique symbol;
77
- const toNum: unique symbol;
78
- const toObj: unique symbol;
79
- const toStr: unique symbol;
80
- const upper: unique symbol;
81
- // </SYMBOLS>
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
+ };
82
112
 
83
113
  // Adding symbol properties to Object.prototype will cause typescript to think these properties
84
114
  // are also available for extending types, e.g. Array - to avoid this we merge in an object which
85
115
  // defines every symbol as `undefined`!
86
116
  type SymbolsProto = {
87
- // <SYMBOLS> :: SymbolsProto :: /\[([a-zA-Z0-9]+)\][ ]*[:][ ]*undefined
88
- [add]: undefined,
89
- [allArr]: undefined,
90
- [allObj]: undefined,
91
- [at]: undefined,
92
- [assert]: undefined,
93
- [base32]: undefined,
94
- [base36]: undefined,
95
- [base62]: undefined,
96
- [base64Std]: undefined,
97
- [base64Url]: undefined,
98
- [baseline]: undefined,
99
- [bind]: undefined,
100
- [char]: undefined,
101
- [charset]: undefined,
102
- [code]: undefined,
103
- [count]: undefined,
104
- [cut]: undefined,
105
- [dive]: undefined,
106
- [empty]: undefined,
107
- [find]: undefined,
108
- [fire]: undefined,
109
- [group]: undefined,
110
- [has]: undefined,
111
- [hasHead]: undefined,
112
- [hasTail]: undefined,
113
- [indent]: undefined,
114
- [int32]: undefined,
115
- [int64]: undefined,
116
- [isInt]: undefined,
117
- [later]: undefined,
118
- [limn]: undefined,
119
- [lower]: undefined,
120
- [map]: undefined,
121
- [mapk]: undefined,
122
- [merge]: undefined,
123
- [mod]: undefined,
124
- [padHead]: undefined,
125
- [padTail]: undefined,
126
- [rem]: undefined,
127
- [slash]: undefined,
128
- [slice]: undefined,
129
- [suppress]: undefined,
130
- [toArr]: undefined,
131
- [toBin]: undefined,
132
- [toNum]: undefined,
133
- [toObj]: undefined,
134
- [toStr]: undefined,
135
- [upper]: undefined
117
+ // <SYMBOLS> :: proto :: /\[clearing[.]([a-zA-Z0-9]+)\][ ]*[:][ ]*undefined
118
+ [clearing.add]: undefined,
119
+ [clearing.allArr]: undefined,
120
+ [clearing.allObj]: undefined,
121
+ [clearing.at]: undefined,
122
+ [clearing.assert]: undefined,
123
+ [clearing.base32]: undefined,
124
+ [clearing.base36]: undefined,
125
+ [clearing.base62]: undefined,
126
+ [clearing.base64Std]: undefined,
127
+ [clearing.base64Url]: undefined,
128
+ [clearing.baseline]: undefined,
129
+ [clearing.char]: undefined,
130
+ [clearing.charset]: undefined,
131
+ [clearing.code]: undefined,
132
+ [clearing.count]: undefined,
133
+ [clearing.cut]: undefined,
134
+ [clearing.empty]: undefined,
135
+ [clearing.find]: undefined,
136
+ [clearing.fire]: undefined,
137
+ [clearing.group]: undefined,
138
+ [clearing.has]: undefined,
139
+ [clearing.hasHead]: undefined,
140
+ [clearing.hasTail]: undefined,
141
+ [clearing.indent]: undefined,
142
+ [clearing.int32]: undefined,
143
+ [clearing.int64]: undefined,
144
+ [clearing.isInt]: undefined,
145
+ [clearing.later]: undefined,
146
+ [clearing.limn]: undefined,
147
+ [clearing.lower]: undefined,
148
+ [clearing.map]: undefined,
149
+ [clearing.mapk]: undefined,
150
+ [clearing.merge]: undefined,
151
+ [clearing.mod]: undefined,
152
+ [clearing.padHead]: undefined,
153
+ [clearing.padTail]: undefined,
154
+ [clearing.rem]: undefined,
155
+ [clearing.slash]: undefined,
156
+ [clearing.slice]: undefined,
157
+ [clearing.suppress]: undefined,
158
+ [clearing.toArr]: undefined,
159
+ [clearing.toBin]: undefined,
160
+ [clearing.toNum]: undefined,
161
+ [clearing.toObj]: undefined,
162
+ [clearing.toStr]: undefined,
163
+ [clearing.upper]: undefined
136
164
  // </SYMBOLS>
137
165
  };
138
166
 
139
167
  interface ErrorConstructor {
140
- [assert]: <V = any>(args: V, fn: (args: V) => boolean) => void
168
+ [clearing.assert]: <V = any>(args: V, fn: (args: V) => boolean) => void
141
169
  }
142
170
  interface Error extends SymbolsProto {
143
- [mod]: (props: string | Obj<any> | ((msg: string, err: Error) => Obj<any>)) => Error,
144
- [fire]: (props?: string | Obj<any> | ((msg: string, err: Error) => Obj<any>)) => never,
145
- [suppress]: () => Error,
146
- [limn]: (seen?: Map<any, any>) => (Obj<Json> & {
171
+ [clearing.mod]: (props: string | Obj<any> | ((msg: string, err: Error) => Obj<any>)) => Error,
172
+ [clearing.fire]: (props?: string | Obj<any> | ((msg: string, err: Error) => Obj<any>)) => never,
173
+ [clearing.suppress]: () => Error,
174
+ [clearing.limn]: (seen?: Map<any, any>) => (Obj<Json> & {
147
175
  form: string,
148
176
  msg: string,
149
177
  trace: string[],
@@ -153,70 +181,73 @@ declare global {
153
181
 
154
182
  interface ArrayConstructor {}
155
183
  interface Array<T> extends SymbolsProto {
156
- [has]: (val: unknown) => boolean,
157
- [map]: <Fn extends (v: T, i: number) => any>(fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
158
- [add]: <TT extends T>(val: TT) => TT,
159
- [rem]: <TT extends T>(val: TT) => void,
160
- [count]: () => number,
161
- [empty]: () => boolean,
162
- [toObj]: <R extends readonly [string, any]>(fn: (v: T, n: number) => Skip | R) => { [K: string]: any },
163
- [find]: (fn: (val: T, n: number) => any) => ({ found: true, val: T, ind: number } | { found: false, val: null, ind: null }),
164
- [group]: <G extends string>(fn: (v: T) => Skip | G) => { [K in G]?: T[] }
184
+ [clearing.has]: (val: unknown) => boolean,
185
+ [clearing.map]: <Fn extends (v: T, i: number) => any>(fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
186
+ [clearing.add]: <TT extends T>(val: TT) => TT,
187
+ [clearing.rem]: <TT extends T>(val: TT) => void,
188
+ [clearing.count]: () => number,
189
+ [clearing.empty]: () => boolean,
190
+ [clearing.toObj]: <R extends readonly [string, any]>(fn: (v: T, n: number) => Skip | R) => { [K in R[0]]: R[1] },
191
+ [clearing.find]: (fn: (val: T, n: number) => any) => ({ found: true, val: T, ind: number } | { found: false, val: null, ind: null }),
192
+ [clearing.group]: <G extends string>(fn: (v: T, i: number) => Skip | G) => { [K in G]?: T[] }
165
193
  }
166
194
 
167
195
  interface NumberConstructor {
168
- [int32]: number,
169
- [int64]: number
196
+ [clearing.int32]: number,
197
+ [clearing.int64]: number
170
198
  }
171
199
  interface Number extends SymbolsProto {
172
- [char]: () => string,
173
- [isInt]: () => boolean,
174
- [toStr]: (str: string | CharSet, len?: number) => string,
175
- [toArr]: <T>(fn: (n: number) => T) => T[],
176
- [toObj]: <R extends readonly [string, any]>(fn: (n: number) => Skip | R) => { [K: string]: any },
177
- [toBin]: () => Uint8Array,
200
+ [clearing.char]: () => string,
201
+ [clearing.isInt]: () => boolean,
202
+ [clearing.toStr]: (str: string | CharSet, len?: number) => string,
203
+ [clearing.toArr]: <T>(fn: (n: number) => T) => T[],
204
+ [clearing.toObj]: <R extends readonly [string, any]>(fn: (n: number) => Skip | R) => { [K in R[0]]: R[1] },
205
+ [clearing.toBin]: () => Uint8Array,
178
206
  [Symbol.iterator]: () => Generator<number>
179
207
  }
180
208
 
181
209
  interface BigIntConstructor {}
182
210
  interface BigInt extends SymbolsProto {
183
- [toStr]: (str: string | CharSet, len?: number) => string,
184
- [toBin]: () => Uint8Array
211
+ [clearing.toStr]: (str: string | CharSet, len?: number) => string,
212
+ [clearing.toBin]: () => Uint8Array
185
213
  }
186
214
 
187
215
  interface ObjectConstructor {}
188
216
  interface Object {
189
- [empty]: () => boolean,
190
- [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>,
191
- [has]: <O extends Obj>(this: O, k: unknown) => k is keyof O,
192
- [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> },
193
- [mapk]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => undefined | [ string, any ]>(this: O, fn: Fn) => { [K: string]: any },
194
- [merge]: <O1 extends Obj, O2 extends Obj>(this: O1, val: O2) => O1 & O2,
195
- [slice]: <O extends Obj, K extends readonly (keyof O)[]>(this: O, keys: K) => { [P in K[number]]: SkipNever<O[P]> },
196
- [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] },
197
- [toArr]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => any>(this: O, fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
198
- [count]: () => number,
199
- [group]: <O extends Obj, G extends string>(this: O, fn: (v: O[keyof O]) => Skip | G) => { [K in G]?: Partial<O> },
200
- [Symbol.iterator]: <O extends Obj>(this: O) => Iterator<[ ObjKeys<O>, ObjVals<O> ]>
217
+ [clearing.empty]: () => boolean,
218
+ [clearing.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>,
219
+ [clearing.has]: <O extends Obj>(this: O, k: unknown) => k is keyof O,
220
+ [clearing.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> },
221
+ [clearing.mapk]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => undefined | [ string, any ]>(this: O, fn: Fn) => { [K: string]: any },
222
+ [clearing.merge]: <O1 extends Obj, O2 extends Obj>(this: O1, val: O2) => O1 & O2,
223
+ [clearing.slice]: <O extends Obj, K extends readonly (keyof O)[]>(this: O, keys: K) => { [P in K[number]]: SkipNever<O[P]> },
224
+ [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] },
225
+ [clearing.toArr]: <O extends Obj, Fn extends (v: O[keyof O], k: ObjKeys<O>) => any>(this: O, fn: Fn) => Exclude<ReturnType<Fn>, Skip>[],
226
+ [clearing.count]: () => number,
227
+ [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> },
228
+ [Symbol.iterator]: <O extends Obj>(this: O) => Iterator<[ ObjKeys<O>, ObjVals<O> ]>,
229
+
230
+ $$inspect: <O>(this: O) => { v: O }
231
+
201
232
  }
202
233
 
203
234
  interface ArrayBufferConstructor {}
204
235
  interface ArrayBuffer {
205
- [toStr]: () => string,
206
- [toNum]: () => bigint
236
+ [clearing.toStr]: () => string,
237
+ [clearing.toNum]: () => bigint
207
238
  }
208
239
 
209
240
  interface Uint8ArrayConstructor {}
210
241
  interface Uint8Array {
211
- [toStr]: () => string,
212
- [toNum]: () => bigint
242
+ [clearing.toStr]: () => string,
243
+ [clearing.toNum]: () => bigint
213
244
  }
214
245
 
215
246
  interface PromiseConstructor {
216
- [allArr]: <V extends Promise<any>>(arr: Arr<V>) => Promise<Arr<Exclude<Awaited<V>, Skip>>>,
217
- [allObj]: <V extends Promise<any>>(obj: Obj<V>) => Promise<Obj<Exclude<Awaited<V>, Skip>>>,
247
+ [clearing.allArr]: <V extends Promise<any>>(arr: Arr<V>) => Promise<Arr<Exclude<Awaited<V>, Skip>>>,
248
+ [clearing.allObj]: <V extends Promise<any>>(obj: Obj<V>) => Promise<Obj<Exclude<Awaited<V>, Skip>>>,
218
249
  // [allObj]: <O extends { [K: string]: Promise<any> }>(obj: O) => Promise<{ [K in keyof O]: Exclude<Awaited<O[K]>, Skip> }>,
219
- [later]: <T=void>() => PromiseLater<T>
250
+ [clearing.later]: <T=void>() => PromiseLater<T>
220
251
  }
221
252
  interface Promise<T> {}
222
253
  interface PromiseLater<T=void> extends Promise<T> {
@@ -226,56 +257,56 @@ declare global {
226
257
 
227
258
  interface SetConstructor {}
228
259
  interface Set<T> extends SymbolsProto {
229
- [count]: () => number,
230
- [empty]: () => boolean,
231
- [find]: (fn: (val: T) => any) => ({ found: true, val: T } | { found: false, val: null }),
232
- [map]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
233
- [toArr]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
234
- [toObj]: <R extends readonly [string, any]>(fn: (val: T) => Skip | R) => { [K: string]: any },
235
- [rem]: (val: T) => void
260
+ [clearing.count]: () => number,
261
+ [clearing.empty]: () => boolean,
262
+ [clearing.find]: (fn: (val: T) => any) => ({ found: true, val: T } | { found: false, val: null }),
263
+ [clearing.map]: <V>(fn: (val: T, ind: number) => V) => Exclude<V, Skip>[],
264
+ [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) => { [K: string]: any },
266
+ [clearing.rem]: (val: T) => void
236
267
  }
237
268
 
238
269
  interface MapConstructor {}
239
270
  interface Map<K, V> extends SymbolsProto {
240
- [add]: (k: K, v: V) => void,
241
- [count]: () => number,
242
- [empty]: () => boolean,
243
- [find]: (fn: (val: V, key: K) => any) => ({ found: true, val: V, key: K } | { found: false, val: null, key: null }),
244
- [map]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [K: string]: any },
245
- [toArr]: <T>(fn: (val: V, key: K) => T) => Exclude<T, Skip>[],
246
- [toObj]: <R>(fn: (val: V, key: K) => Skip | readonly [string, R]) => Obj<R>,
247
- [rem]: (key: K) => void
271
+ [clearing.add]: (k: K, v: V) => void,
272
+ [clearing.count]: () => number,
273
+ [clearing.empty]: () => boolean,
274
+ [clearing.find]: (fn: (val: V, key: K) => any) => ({ found: true, val: V, key: K } | { found: false, val: null, key: null }),
275
+ [clearing.map]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [K: string]: any },
276
+ [clearing.toArr]: <T>(fn: (val: V, key: K) => T) => Exclude<T, Skip>[],
277
+ [clearing.toObj]: <R extends [ string, any ]>(fn: (val: V, key: K) => Skip | R) => { [K in R[0]]: R[1] },
278
+ [clearing.rem]: (key: K) => void
248
279
  }
249
280
 
250
281
  interface StringConstructor {
251
- [base32]: string,
252
- [base36]: string,
253
- [base62]: string,
254
- [base64Url]: string,
255
- [base64Std]: string,
256
- [baseline]: (str: string) => string,
257
- [charset]: (str: string) => CharSet,
282
+ [clearing.base32]: string,
283
+ [clearing.base36]: string,
284
+ [clearing.base62]: string,
285
+ [clearing.base64Url]: string,
286
+ [clearing.base64Std]: string,
287
+ [clearing.baseline]: (str: string) => string,
288
+ [clearing.charset]: (str: string) => CharSet,
258
289
  }
259
290
  interface String extends SymbolsProto {
260
- [code]: (ind?: number) => number,
261
- [count]: () => number,
262
- [has]: (s: string) => boolean,
263
- [padHead]: (n: number, s?: string) => string,
264
- [padTail]: (n: number, s?: string) => string,
265
- [toNum]: (chrs: string | CharSet) => bigint,
266
- [toBin]: () => Uint8Array,
267
- [hasHead]: <H extends string>(this: string, head: H) => this is `${H}${string}`,
268
- [hasTail]: <T extends string>(this: string, tail: T) => this is `${string}${T}`,
269
- [upper]: <S extends string>(this: S) => Uppercase<S>,
270
- [lower]: <S extends string>(this: S) => Lowercase<S>,
271
- [cut]: {
291
+ [clearing.code]: (ind?: number) => number,
292
+ [clearing.count]: () => number,
293
+ [clearing.has]: (s: string) => boolean,
294
+ [clearing.padHead]: (n: number, s?: string) => string,
295
+ [clearing.padTail]: (n: number, s?: string) => string,
296
+ [clearing.toNum]: (chrs: string | CharSet) => bigint,
297
+ [clearing.toBin]: () => Uint8Array,
298
+ [clearing.hasHead]: <H extends string>(this: string, head: H) => this is `${H}${string}`,
299
+ [clearing.hasTail]: <T extends string>(this: string, tail: T) => this is `${string}${T}`,
300
+ [clearing.upper]: <S extends string>(this: S) => Uppercase<S>,
301
+ [clearing.lower]: <S extends string>(this: S) => Lowercase<S>,
302
+ [clearing.cut]: {
272
303
  (str: string, cuts: 1): [ string, string ],
273
304
  (str: string, cuts: 2): [ string, string, string ],
274
305
  (str: string, cuts: 3): [ string, string, string, string ],
275
306
  (str: string, cuts: 4): [ string, string, string, string, string ],
276
307
  (str: string, cuts?: number): string[]
277
308
  },
278
- [indent]: {
309
+ [clearing.indent]: {
279
310
  (amount: number, char?: string): string,
280
311
  (str: string): string
281
312
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gershy/clearing",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "Adds the features you always wish javascript had!",
5
5
  "keywords": [
6
6
  "clearing",