@gershy/clearing 0.0.23 → 0.0.24

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 CHANGED
@@ -470,8 +470,8 @@ const applyClearing = (() => {
470
470
  });
471
471
  protoDefs(Promise, {
472
472
  $: {
473
- [allArr]: Promise.all,
474
- [allObj]: (obj) => {
473
+ [allArr]: arr => Promise.all(arr).then(arr => arr.filter(v => v !== exports.skip)),
474
+ [allObj]: obj => {
475
475
  // Need to get `keys` immediately, in case `obj` mutates before resolution
476
476
  const keys = Object.keys(obj);
477
477
  return Promise.all(Object.values(obj)).then(vals => {
package/cmp/mjs/main.js CHANGED
@@ -461,8 +461,8 @@ const applyClearing = (() => {
461
461
  });
462
462
  protoDefs(Promise, {
463
463
  $: {
464
- [allArr]: Promise.all,
465
- [allObj]: (obj) => {
464
+ [allArr]: arr => Promise.all(arr).then(arr => arr.filter(v => v !== skip)),
465
+ [allObj]: obj => {
466
466
  // Need to get `keys` immediately, in case `obj` mutates before resolution
467
467
  const keys = Object.keys(obj);
468
468
  return Promise.all(Object.values(obj)).then(vals => {
@@ -3,6 +3,7 @@ declare global {
3
3
  // Util
4
4
  type Fn<A extends any[] = any[], T = any> = (...args: A) => T;
5
5
  type Obj<V = any> = { [k: string]: V };
6
+ type Arr<V = any> = V[];
6
7
 
7
8
  // Differentiate between "map" and "rec" ("record") - maps have arbitrary keys; recs have fixed keys
8
9
  type ObjMode<O extends { [K: string]: any }> = O extends { [K in infer KK]: any } ? (string extends KK ? 'map' : 'rec') : never;
@@ -138,8 +139,8 @@ declare global {
138
139
  [assert]: <V = any>(args: V, fn: (args: V) => boolean) => void
139
140
  }
140
141
  interface Error extends SymbolsProto {
141
- [mod]: (props: { [K: string]: any }) => Error,
142
- [fire]: (props?: { [K: string]: any }) => never,
142
+ [mod]: (props: string | Obj<any> | ((msg: string, err: Error) => Obj<any>)) => Error,
143
+ [fire]: (props?: string | Obj<any> | ((msg: string, err: Error) => Obj<any>)) => never,
143
144
  [suppress]: () => Error,
144
145
  [limn]: (seen?: Map<any, any>) => (Obj<Json> & {
145
146
  form: string,
@@ -203,8 +204,9 @@ declare global {
203
204
  }
204
205
 
205
206
  interface PromiseConstructor {
206
- [allArr]: PromiseConstructor['all'],
207
- [allObj]: <O extends { [K: string]: Promise<any> }>(obj: O) => Promise<{ [K in keyof O]: Exclude<Awaited<O[K]>, Skip> }>,
207
+ [allArr]: <V extends Promise<any>>(arr: Arr<V>) => Promise<Arr<Exclude<Awaited<V>, Skip>>>,
208
+ [allObj]: <V extends Promise<any>>(obj: Obj<V>) => Promise<Obj<Exclude<Awaited<V>, Skip>>>,
209
+ // [allObj]: <O extends { [K: string]: Promise<any> }>(obj: O) => Promise<{ [K in keyof O]: Exclude<Awaited<O[K]>, Skip> }>,
208
210
  [later]: <T=void>() => PromiseLater<T>
209
211
  }
210
212
  interface Promise<T> {}
@@ -230,9 +232,9 @@ declare global {
230
232
  [count]: () => number,
231
233
  [empty]: () => boolean,
232
234
  [find]: (fn: (val: V, key: K) => any) => ({ found: true, val: V, key: K } | { found: false, val: null, key: null }),
233
- [map]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [Key: string]: any },
235
+ [map]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [K: string]: any },
234
236
  [toArr]: <T>(fn: (val: V, key: K) => T) => Exclude<T, Skip>[],
235
- [toObj]: <T>(fn: (val: V, key: K) => Skip | readonly [string, any]) => { [Key: string]: any },
237
+ [toObj]: <R>(fn: (val: V, key: K) => Skip | readonly [string, R]) => Obj<R>,
236
238
  [rem]: (key: K) => void
237
239
  }
238
240
 
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@gershy/clearing",
3
- "version": "0.0.23",
4
- "versionCommit": "ccce646c1a4bc2ec3f349a1b02a8498a930c373e",
3
+ "version": "0.0.24",
5
4
  "description": "Adds the features you always wish javascript had!",
6
5
  "keywords": [
7
6
  "clearing",
@@ -43,5 +42,7 @@
43
42
  "git.pub": "npm run test && git add --all && git commit -m \"automated\" && git push",
44
43
  "npm.login": "npm login",
45
44
  "npm.pub": "npm run test && npm run build && npm publish --access public"
46
- }
45
+ },
46
+ "peerDependencies": {},
47
+ "dependencies": {}
47
48
  }
package/readme.md CHANGED
@@ -217,7 +217,7 @@ console.log(obj[mapk]((v, k) => [ k.toUpperCase(), v * 10 ])); // { A: 10, B: 20
217
217
 
218
218
  ### `Object.prototype[merge]`
219
219
 
220
- Deep merges another object into `this` (mutates in place). Use `clearing.skip` for deletion.
220
+ Deep merges another object into `this` (mutates in place). Use `skip` global for deletion.
221
221
 
222
222
  ```ts
223
223
 
@@ -652,10 +652,20 @@ Error[assert]({ x: 10, y: 5 }, ({ x, y }) => x < y); // throws!
652
652
  Modifies an error's message and adds properties. Returns the error for chaining.
653
653
 
654
654
  ```ts
655
- throw Error('something failed')[mod]({ code: 'err99', context: { userId: 123 } });
655
+ // Add context to errors:
656
+ throw Error('oops')[mod]({ code: 'err99', context: { userId: 123 } });
656
657
 
657
- // Can also modify the message
658
- throw Error('base error')[mod]({ message: 'enhanced message', extra: 'data' });
658
+ // Overwrite the error message by passing a string, or supplying "message" or "msg" properties:
659
+ throw Error('oops')[mod]('new message');
660
+ throw Error('oops')[mod]({ msg: 'new message', extra: 'data' });
661
+ throw Error('oops')[mod]({ message: 'new message', extra: 'data' });
662
+
663
+ // Pass a callback to succinctly reference the original message:
664
+ throw Error('oops')[mod](msg => `Modified message! Original: ${msg}`);
665
+ throw Error('oops')[mod](msg => ({
666
+ msg: `Modified message! Original: ${msg}`,
667
+ extra: 'data'
668
+ }));
659
669
  ```
660
670
 
661
671
  ### `Error.prototype[fire]`