pepka 1.7.0 → 1.8.0

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/dist/bundle.cjs CHANGED
@@ -195,32 +195,46 @@ const qmapKeys = curry2((keyMap, o) => {
195
195
  return o;
196
196
  });
197
197
  // FIXME: qmap(any, tags) -> some function!!!
198
+ /**
199
+ * @param pipe (v, i, list: T[]) -> T.
200
+ * @param data T[].
201
+ * @returns T[].
202
+ */
198
203
  const qmap = curry2((pipe, arr) => {
199
204
  for (const i in arr)
200
205
  arr[i] = pipe(arr[i], +i, arr);
201
206
  return arr;
202
207
  });
208
+ /**
209
+ * @param cond (v, k) -> boolean.
210
+ * @param data T extends AnyObject.
211
+ * @returns T
212
+ */
203
213
  const qmapObj = curry2((pipe, o) => {
204
214
  for (const k in o)
205
215
  o[k] = pipe(o[k], k, o);
206
216
  return o;
207
217
  });
218
+ /**
219
+ * @param cond (v, k) -> boolean.
220
+ * @param data T extends any[] | AnyObject.
221
+ * @returns T
222
+ */
208
223
  const qfilter = curry2((cond, data) => {
209
- const isArr = isArray(data);
210
- let indicies_offset, indicies2rm;
211
- if (isArr) {
212
- indicies_offset = 0;
213
- indicies2rm = [];
224
+ if (isArray(data)) {
225
+ let indicies_offset = 0;
226
+ const indicies2rm = [];
227
+ const len = length(data);
228
+ for (let i = 0; i < len; i++)
229
+ if (!cond(data[i], i))
230
+ indicies2rm.push(i);
231
+ for (const i of indicies2rm)
232
+ data.splice(i - indicies_offset++, 1);
214
233
  }
215
- for (let k in data)
216
- if (!cond(data[k], k)) // @ts-ignore
217
- if (isArr)
218
- indicies2rm.push(+k);
219
- else
234
+ else
235
+ for (const k in data)
236
+ if (!cond(data[k], k))
220
237
  delete data[k];
221
- if (isArr) // @ts-ignore
222
- for (const i of indicies2rm) // @ts-ignore
223
- data.splice(i - indicies_offset++, 1);
224
238
  return data;
225
239
  });
226
240
  const qempty = (o) => {
@@ -627,6 +641,13 @@ const forEachSerial = (() => {
627
641
  })();
628
642
  /** Promise.all wrapper for functional pipelining. */
629
643
  const waitAll = (promises) => Promise.all(promises);
644
+ const qwaitAll = async (xs) => new Promise((ff, rj) => {
645
+ const len = length(xs);
646
+ let j = len;
647
+ for (let i = 0; i < len; i++)
648
+ xs[i].then((x) => { xs[i] = x; if (--j)
649
+ ff(xs); }).catch(rj);
650
+ });
630
651
  /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
631
652
  * @param {AnyFunc<Promise>} fn - function to wait.
632
653
  * @param {T} s - any value to tap and return back
@@ -640,6 +661,29 @@ const composeAsync = (() => {
640
661
  const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
641
662
  return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
642
663
  })();
664
+ /**
665
+ * @param cond async (v, k) -> boolean.
666
+ * @param data T extends any[] | AnyObject.
667
+ * @returns T
668
+ */
669
+ const qfilterAsync = curry2(async (cond, data // dunno how to merge it with sync version...
670
+ ) => {
671
+ if (isArray(data)) {
672
+ let indicies_offset = 0;
673
+ const indicies2rm = [];
674
+ const len = length(data);
675
+ for (let i = 0; i < len; i++)
676
+ if (!await cond(data[i], i))
677
+ indicies2rm.push(i);
678
+ for (const i of indicies2rm)
679
+ data.splice(i - indicies_offset++, 1);
680
+ }
681
+ else
682
+ for (const k in data)
683
+ if (!await cond(data[k], k))
684
+ delete data[k];
685
+ return data;
686
+ });
643
687
 
644
688
  const ecran = '\\';
645
689
  // TODO: make it splicy, not accumulatie by symbols.
@@ -824,6 +868,7 @@ exports.qassoc = qassoc;
824
868
  exports.qassocPath = qassocPath;
825
869
  exports.qempty = qempty;
826
870
  exports.qfilter = qfilter;
871
+ exports.qfilterAsync = qfilterAsync;
827
872
  exports.qfreeze = qfreeze;
828
873
  exports.qfreezeShallow = qfreezeShallow;
829
874
  exports.qmap = qmap;
@@ -843,6 +888,7 @@ exports.qreverse = qreverse;
843
888
  exports.qslice = qslice;
844
889
  exports.qsort = qsort;
845
890
  exports.quniq = quniq;
891
+ exports.qwaitAll = qwaitAll;
846
892
  exports.range = range;
847
893
  exports.reduce = reduce;
848
894
  exports.reflect = reflect;
package/dist/bundle.d.ts CHANGED
@@ -50,6 +50,7 @@ export declare const forEachSerial: {
50
50
  };
51
51
  /** Promise.all wrapper for functional pipelining. */
52
52
  export declare const waitAll: <T>(promises: Promise<T>[]) => Promise<Awaited<T>[]>;
53
+ export declare const qwaitAll: <T>(xs: Promise<T>[]) => Promise<T[]>;
53
54
  /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
54
55
  * @param {AnyFunc<Promise>} fn - function to wait.
55
56
  * @param {T} s - any value to tap and return back
@@ -70,6 +71,17 @@ export declare const forEachAsync: {
70
71
  };
71
72
  /** The same as compose, but waits for promises in chains and returns a Promise. */
72
73
  export declare const composeAsync: <TIn extends any[] = any[], TOut = any>(...fns: AnyFunc[]) => Composed<TIn, Promise<TOut>>;
74
+ /**
75
+ * @param cond async (v, k) -> boolean.
76
+ * @param data T extends any[] | AnyObject.
77
+ * @returns T
78
+ */
79
+ export declare const qfilterAsync: {
80
+ (a: Placeholder, b: any[] | AnyObject): (a: (v: any, k: string | number) => Promise<boolean> | boolean) => Promise<any[] | AnyObject>;
81
+ (a: (v: any, k: string | number) => Promise<boolean> | boolean, b: Placeholder): (b: any[] | AnyObject) => Promise<any[] | AnyObject>;
82
+ (a: (v: any, k: string | number) => Promise<boolean> | boolean): (b: any[] | AnyObject) => Promise<any[] | AnyObject>;
83
+ (a: (v: any, k: string | number) => Promise<boolean> | boolean, b: any[] | AnyObject): Promise<any[] | AnyObject>;
84
+ };
73
85
  declare const length$1: <T extends AnyArray | string>(s: T) => T extends string ? StrLen<T> : T["length"];
74
86
  export declare const symbol: unique symbol;
75
87
  export declare const toLower: (s: string) => string;
@@ -147,18 +159,33 @@ export declare const qmapKeys: {
147
159
  [oldKey: string]: string | AnyFunc;
148
160
  }, b: AnyObject): AnyObject;
149
161
  };
162
+ /**
163
+ * @param pipe (v, i, list: T[]) -> T.
164
+ * @param data T[].
165
+ * @returns T[].
166
+ */
150
167
  export declare const qmap: {
151
- (a: Placeholder, b: any[]): (a: (s: any, i?: number, list?: any[]) => any) => any[];
152
- (a: (s: any, i?: number, list?: any[]) => any, b: Placeholder): (b: any[]) => any[];
153
- (a: (s: any, i?: number, list?: any[]) => any): (b: any[]) => any[];
154
- (a: (s: any, i?: number, list?: any[]) => any, b: any[]): any[];
168
+ (a: Placeholder, b: any[] | AnyObject): (a: (s: any, i?: number, list?: any[] | AnyObject | undefined) => any) => any[] | AnyObject;
169
+ (a: (s: any, i?: number, list?: any[] | AnyObject | undefined) => any, b: Placeholder): (b: any[] | AnyObject) => any[] | AnyObject;
170
+ (a: (s: any, i?: number, list?: any[] | AnyObject | undefined) => any): (b: any[] | AnyObject) => any[] | AnyObject;
171
+ (a: (s: any, i?: number, list?: any[] | AnyObject | undefined) => any, b: any[] | AnyObject): any[] | AnyObject;
155
172
  };
173
+ /**
174
+ * @param cond (v, k) -> boolean.
175
+ * @param data T extends AnyObject.
176
+ * @returns T
177
+ */
156
178
  export declare const qmapObj: {
157
179
  (a: Placeholder, b: AnyObject): (a: (s: any, k?: string, o?: AnyObject) => any) => AnyObject;
158
180
  (a: (s: any, k?: string, o?: AnyObject) => any, b: Placeholder): (b: AnyObject) => AnyObject;
159
181
  (a: (s: any, k?: string, o?: AnyObject) => any): (b: AnyObject) => AnyObject;
160
182
  (a: (s: any, k?: string, o?: AnyObject) => any, b: AnyObject): AnyObject;
161
183
  };
184
+ /**
185
+ * @param cond (v, k) -> boolean.
186
+ * @param data T extends any[] | AnyObject.
187
+ * @returns T
188
+ */
162
189
  export declare const qfilter: {
163
190
  (a: Placeholder, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any[] | AnyObject;
164
191
  (a: (v: any, k: string | number) => boolean, b: Placeholder): (b: any[] | AnyObject) => any[] | AnyObject;
package/dist/bundle.mjs CHANGED
@@ -193,32 +193,46 @@ const qmapKeys = curry2((keyMap, o) => {
193
193
  return o;
194
194
  });
195
195
  // FIXME: qmap(any, tags) -> some function!!!
196
+ /**
197
+ * @param pipe (v, i, list: T[]) -> T.
198
+ * @param data T[].
199
+ * @returns T[].
200
+ */
196
201
  const qmap = curry2((pipe, arr) => {
197
202
  for (const i in arr)
198
203
  arr[i] = pipe(arr[i], +i, arr);
199
204
  return arr;
200
205
  });
206
+ /**
207
+ * @param cond (v, k) -> boolean.
208
+ * @param data T extends AnyObject.
209
+ * @returns T
210
+ */
201
211
  const qmapObj = curry2((pipe, o) => {
202
212
  for (const k in o)
203
213
  o[k] = pipe(o[k], k, o);
204
214
  return o;
205
215
  });
216
+ /**
217
+ * @param cond (v, k) -> boolean.
218
+ * @param data T extends any[] | AnyObject.
219
+ * @returns T
220
+ */
206
221
  const qfilter = curry2((cond, data) => {
207
- const isArr = isArray(data);
208
- let indicies_offset, indicies2rm;
209
- if (isArr) {
210
- indicies_offset = 0;
211
- indicies2rm = [];
222
+ if (isArray(data)) {
223
+ let indicies_offset = 0;
224
+ const indicies2rm = [];
225
+ const len = length(data);
226
+ for (let i = 0; i < len; i++)
227
+ if (!cond(data[i], i))
228
+ indicies2rm.push(i);
229
+ for (const i of indicies2rm)
230
+ data.splice(i - indicies_offset++, 1);
212
231
  }
213
- for (let k in data)
214
- if (!cond(data[k], k)) // @ts-ignore
215
- if (isArr)
216
- indicies2rm.push(+k);
217
- else
232
+ else
233
+ for (const k in data)
234
+ if (!cond(data[k], k))
218
235
  delete data[k];
219
- if (isArr) // @ts-ignore
220
- for (const i of indicies2rm) // @ts-ignore
221
- data.splice(i - indicies_offset++, 1);
222
236
  return data;
223
237
  });
224
238
  const qempty = (o) => {
@@ -625,6 +639,13 @@ const forEachSerial = (() => {
625
639
  })();
626
640
  /** Promise.all wrapper for functional pipelining. */
627
641
  const waitAll = (promises) => Promise.all(promises);
642
+ const qwaitAll = async (xs) => new Promise((ff, rj) => {
643
+ const len = length(xs);
644
+ let j = len;
645
+ for (let i = 0; i < len; i++)
646
+ xs[i].then((x) => { xs[i] = x; if (--j)
647
+ ff(xs); }).catch(rj);
648
+ });
628
649
  /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
629
650
  * @param {AnyFunc<Promise>} fn - function to wait.
630
651
  * @param {T} s - any value to tap and return back
@@ -638,6 +659,29 @@ const composeAsync = (() => {
638
659
  const pipe = async (fns, input, i) => ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input);
639
660
  return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
640
661
  })();
662
+ /**
663
+ * @param cond async (v, k) -> boolean.
664
+ * @param data T extends any[] | AnyObject.
665
+ * @returns T
666
+ */
667
+ const qfilterAsync = curry2(async (cond, data // dunno how to merge it with sync version...
668
+ ) => {
669
+ if (isArray(data)) {
670
+ let indicies_offset = 0;
671
+ const indicies2rm = [];
672
+ const len = length(data);
673
+ for (let i = 0; i < len; i++)
674
+ if (!await cond(data[i], i))
675
+ indicies2rm.push(i);
676
+ for (const i of indicies2rm)
677
+ data.splice(i - indicies_offset++, 1);
678
+ }
679
+ else
680
+ for (const k in data)
681
+ if (!await cond(data[k], k))
682
+ delete data[k];
683
+ return data;
684
+ });
641
685
 
642
686
  const ecran = '\\';
643
687
  // TODO: make it splicy, not accumulatie by symbols.
@@ -723,4 +767,4 @@ const wait = (time) => new Promise((ff) => setTimeout(ff, time));
723
767
  // TODO: possibly introduce a second argument limiting unfolding.
724
768
  const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
725
769
 
726
- export { F, T, __, add, all, allPass, always, any, anyPass, append, assoc, assocPath, bind, both, callFrom, callWith, clone, cloneShallow, complement, compose, composeAsync, concat, cond, curry, curry2, curry3, debounce, diff, divide, echo, empty, eq, equals, explore, filter, find, findIndex, flat, flatShallow, flatTo, flip, forEach, forEachAsync, forEachSerial, freeze, freezeShallow, fromPairs, genBy, getTmpl, gt, gte, head, identity, ifElse, includes, indexOf, intersection, isEmpty, isNil, join, keys, last, length, lt, lte, map, mapKeys, mapObj, memoize, mergeDeep, mergeDeepAdd, mergeDeepX, mergeShallow, mirror, multiply, noop, not, notf, nth, omit, once, overProp, path, pathEq, pathExists, pathOr, pathsEq, pick, pickBy, prepend, prop, propEq, propsEq, push, qappend, qassoc, qassocPath, qempty, qfilter, qfreeze, qfreezeShallow, qmap, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qmergeShallow, qomit, qoverProp, qpick, qprepend, qpush, qreduce, qreverse, qslice, qsort, quniq, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, startsWithShallow, subtract, symbol, tail, take, tap, test, throttle, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqBy, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
770
+ export { F, T, __, add, all, allPass, always, any, anyPass, append, assoc, assocPath, bind, both, callFrom, callWith, clone, cloneShallow, complement, compose, composeAsync, concat, cond, curry, curry2, curry3, debounce, diff, divide, echo, empty, eq, equals, explore, filter, find, findIndex, flat, flatShallow, flatTo, flip, forEach, forEachAsync, forEachSerial, freeze, freezeShallow, fromPairs, genBy, getTmpl, gt, gte, head, identity, ifElse, includes, indexOf, intersection, isEmpty, isNil, join, keys, last, length, lt, lte, map, mapKeys, mapObj, memoize, mergeDeep, mergeDeepAdd, mergeDeepX, mergeShallow, mirror, multiply, noop, not, notf, nth, omit, once, overProp, path, pathEq, pathExists, pathOr, pathsEq, pick, pickBy, prepend, prop, propEq, propsEq, push, qappend, qassoc, qassocPath, qempty, qfilter, qfilterAsync, qfreeze, qfreezeShallow, qmap, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qmergeShallow, qomit, qoverProp, qpick, qprepend, qpush, qreduce, qreverse, qslice, qsort, quniq, qwaitAll, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, startsWithShallow, subtract, symbol, tail, take, tap, test, throttle, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqBy, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
package/package.json CHANGED
@@ -41,15 +41,15 @@
41
41
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
42
42
  "all": "npm run dev && npm run prod"
43
43
  },
44
- "version": "1.7.0",
44
+ "version": "1.8.0",
45
45
  "devDependencies": {
46
- "@rollup/plugin-commonjs": "^29.0.0",
46
+ "@rollup/plugin-commonjs": "^29.0.2",
47
47
  "@rollup/plugin-node-resolve": "^16.0.3",
48
48
  "@rollup/plugin-replace": "^6.0.3",
49
- "@types/node": "^25.0.3",
49
+ "@types/node": "^25.5.0",
50
50
  "cross-env": "^10.1.0",
51
51
  "dts-bundle-generator": "^9.5.1",
52
- "rollup": "^4.54.0",
52
+ "rollup": "^4.59.0",
53
53
  "rollup-plugin-typescript2": "^0.36.0",
54
54
  "ts-node": "^10.9.2",
55
55
  "tslint": "^6.1.3",
package/src/async.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { curry2 } from "./curry"
2
- import { head } from "./safe"
3
- import { AnyFunc, Composed } from "./types"
2
+ import { head, length } from "./safe"
3
+ import { AnyFunc, AnyObject, Composed } from "./types"
4
+ import { isArray } from "./utils"
4
5
 
5
6
  /** One promise waits for another. */
6
7
  export const forEachSerial = (() => {
@@ -16,6 +17,10 @@ export const forEachSerial = (() => {
16
17
  })()
17
18
  /** Promise.all wrapper for functional pipelining. */
18
19
  export const waitAll = <T>(promises: Promise<T>[]) => Promise.all<T>(promises)
20
+ export const qwaitAll = async <T>(xs: Promise<T>[]) => new Promise<T[]>((ff, rj) => {
21
+ const len = length(xs); let j = len
22
+ for(let i=0; i<len; i++) xs[i].then((x: T) => {xs[i]=x as any; if(--j) ff(xs as any)}).catch(rj)
23
+ })
19
24
  /** Waits for a Promise that been generated by the first arg, then returns an untoched value. Types T.
20
25
  * @param {AnyFunc<Promise>} fn - function to wait.
21
26
  * @param {T} s - any value to tap and return back
@@ -32,4 +37,26 @@ export const composeAsync = (() => {
32
37
  ~i ? await pipe(fns, [await fns[i](...input)], --i) : head(input)
33
38
  return <TIn extends any[] = any[], TOut = any>(...fns: AnyFunc[]): Composed<TIn, Promise<TOut>> =>
34
39
  (...input: any[]) => pipe(fns, input, fns.length-1)
35
- })()
40
+ })()
41
+ /**
42
+ * @param cond async (v, k) -> boolean.
43
+ * @param data T extends any[] | AnyObject.
44
+ * @returns T
45
+ */
46
+ export const qfilterAsync = curry2(async <T extends any[] | AnyObject>(
47
+ cond: (v: any, k: string | number) => Promise<boolean> | boolean,
48
+ data: T // dunno how to merge it with sync version...
49
+ ): Promise<T> => {
50
+ if(isArray(data)) {
51
+ let indicies_offset = 0
52
+ const indicies2rm: number[] = []
53
+ const len = length(data as any[])
54
+ for(let i = 0; i<len; i++)
55
+ if(!await cond(data[i], i))
56
+ indicies2rm.push(i)
57
+ for(const i of indicies2rm)
58
+ data.splice(i - indicies_offset++, 1)
59
+ } else for(const k in data)
60
+ if(!await cond(data[k], k)) delete data[k]
61
+ return data
62
+ })
package/src/quick.ts CHANGED
@@ -63,39 +63,51 @@ export const qmapKeys = curry2(
63
63
  }
64
64
  )
65
65
  // FIXME: qmap(any, tags) -> some function!!!
66
+ /**
67
+ * @param pipe (v, i, list: T[]) -> T.
68
+ * @param data T[].
69
+ * @returns T[].
70
+ */
66
71
  export const qmap = curry2(
67
- (pipe: (s: any, i?: number, list?: any[]) => any, arr: any[]) => {
72
+ <T extends any[]|AnyObject>(pipe: (s: any, i?: number, list?: T) => T[Extract<keyof T, string>], arr: T) => {
68
73
  for(const i in arr) arr[i] = pipe(arr[i], +i, arr)
69
74
  return arr
70
75
  }
71
76
  )
77
+ /**
78
+ * @param cond (v, k) -> boolean.
79
+ * @param data T extends AnyObject.
80
+ * @returns T
81
+ */
72
82
  export const qmapObj = curry2(
73
83
  (pipe: (s: any, k?: string, o?: AnyObject) => any, o: AnyObject) => {
74
84
  for(const k in o) o[k] = pipe(o[k], k, o)
75
85
  return o
76
86
  }
77
87
  )
88
+ /**
89
+ * @param cond (v, k) -> boolean.
90
+ * @param data T extends any[] | AnyObject.
91
+ * @returns T
92
+ */
78
93
  export const qfilter = curry2(
79
- <T extends any[] | AnyObject>(
80
- cond: (v: any, k: string | number) => boolean,
81
- data: T
82
- ): T => {
83
- const isArr = isArray(data)
84
- let indicies_offset: number, indicies2rm: number[]
85
- if(isArr) {
86
- indicies_offset = 0
87
- indicies2rm = []
88
- }
89
- for(let k in data)
90
- if(!cond(data[k], k)) // @ts-ignore
91
- if(isArr) indicies2rm.push(+k)
92
- else delete data[k]
93
- if(isArr)// @ts-ignore
94
- for(const i of indicies2rm) // @ts-ignore
95
- data.splice(i - indicies_offset++, 1)
96
- return data
97
- }
98
- )
94
+ <T extends any[] | AnyObject>(
95
+ cond: (v: any, k: string | number) => boolean,
96
+ data: T
97
+ ): T => {
98
+ if(isArray(data)) {
99
+ let indicies_offset = 0
100
+ const indicies2rm: number[] = []
101
+ const len = length(data as any[])
102
+ for(let i = 0; i<len; i++)
103
+ if(!cond(data[i], i))
104
+ indicies2rm.push(i)
105
+ for(const i of indicies2rm)
106
+ data.splice(i - indicies_offset++, 1)
107
+ } else for(const k in data)
108
+ if(!cond(data[k], k)) delete data[k]
109
+ return data
110
+ })
99
111
  export const qempty = <T extends AnyObject|any[]>(o: T): T extends any[] ? [] : {} => {
100
112
  if(isArray(o)) o.splice(0)
101
113
  else for(const i in o) delete o[i]