pepka 1.12.1 → 1.12.3

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
@@ -102,15 +102,21 @@ const isSafe = (prop) => !(prop in unsafe_props);
102
102
  class QPromise extends Promise {
103
103
  oncancel;
104
104
  ff;
105
+ rj;
105
106
  _cancel_data;
106
107
  cancel(resolve = false) {
107
108
  if (resolve)
108
- this.ff();
109
+ this.ff?.();
110
+ else
111
+ this.rj?.();
109
112
  this.oncancel(this._cancel_data);
110
113
  }
111
114
  constructor(fn, oncancel = noop) {
112
115
  let _cancel_data = not_assigned;
113
- super((ff, rj) => _cancel_data = fn(ff, rj));
116
+ super((ff, rj) => {
117
+ _cancel_data = fn(ff, rj);
118
+ setTimeout(() => { this.ff = ff; this.rj = rj; });
119
+ });
114
120
  this.oncancel = oncancel;
115
121
  const set_cb = () => this._cancel_data = _cancel_data;
116
122
  // @ts-ignore-next
@@ -163,6 +169,9 @@ const includes = curry2((s, ss) => {
163
169
  return false;
164
170
  }
165
171
  });
172
+ const always = (s) => () => s;
173
+ const identity = (s) => s;
174
+ const trim = (s) => s.trim();
166
175
 
167
176
  const { min } = Math;
168
177
  const z = 0;
@@ -208,7 +217,7 @@ const qmergeDeepX = mergeDeep$1(2);
208
217
  const qmergeDeepAdd = mergeDeep$1(3);
209
218
  /** @param o1 <- o2 */
210
219
  const qmergeShallow = curry2((o1, o2) => Object.assign(o1, o2));
211
- /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
220
+ /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } removes a key when null. */
212
221
  const qmapKeys = curry2((keyMap, o) => {
213
222
  let k, mapped, newKey, newValue, swap = {}, inswap;
214
223
  for (k in keyMap)
@@ -335,23 +344,26 @@ const rmel = (index, xs) => {
335
344
  return xs;
336
345
  };
337
346
  const seen = new Set();
338
- const quniq = (xs) => {
339
- seen.clear();
340
- let size = length(xs);
347
+ const quniqWith = curry2((getter, xs) => {
348
+ let size = length(xs), cur;
341
349
  for (let i = z; i < size; i++) {
342
350
  const x = xs[i];
343
- if (seen.has(x)) {
351
+ cur = getter(x);
352
+ if (seen.has(cur)) {
344
353
  rmel(i, xs);
345
354
  size--;
346
355
  i--;
347
356
  }
348
357
  else
349
- seen.add(x);
358
+ seen.add(cur);
350
359
  }
360
+ seen.clear();
351
361
  return xs;
352
- };
362
+ });
363
+ const quniq = quniqWith(identity);
353
364
  // Aliases.
354
365
  const qpush = qappend;
366
+ const quniqBy = quniqWith;
355
367
 
356
368
  const { assign } = Object;
357
369
  // TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
@@ -407,9 +419,6 @@ const find = curry2((fn, s) => s.find(fn));
407
419
  const findIndex = curry2((fn, s) => s.findIndex(fn));
408
420
  const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
409
421
  const divide = curry2((a, b) => b / a);
410
- const always = (s) => () => s;
411
- const identity = (s) => s;
412
- const trim = (s) => s.trim();
413
422
  const not = (x) => !x;
414
423
  const keys = (o) => Object.keys(o);
415
424
  const values = (o) => Object.values(o);
@@ -646,7 +655,7 @@ const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
646
655
  * @param data any
647
656
  * @returns data with prop over pipe.
648
657
  */
649
- const overProp = curry3((prop, pipe, data) => (prop in data) && assoc(prop, pipe(data[prop]), data));
658
+ const overProp = curry3((prop, pipe, data) => prop in data ? assoc(prop, pipe(data[prop]), data) : data);
650
659
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
651
660
  const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
652
661
  const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
@@ -931,6 +940,8 @@ exports.qreverse = qreverse;
931
940
  exports.qslice = qslice;
932
941
  exports.qsort = qsort;
933
942
  exports.quniq = quniq;
943
+ exports.quniqBy = quniqBy;
944
+ exports.quniqWith = quniqWith;
934
945
  exports.qwaitAll = qwaitAll;
935
946
  exports.range = range;
936
947
  exports.reduce = reduce;
package/dist/bundle.d.ts CHANGED
@@ -111,6 +111,9 @@ export declare const includes: {
111
111
  (a: unknown): (b: unknown[]) => boolean;
112
112
  (a: unknown, b: unknown[]): boolean;
113
113
  };
114
+ export declare const always: <T extends any>(s: T) => () => T;
115
+ export declare const identity: <T extends any>(s: T) => T;
116
+ export declare const trim: (s: string) => string;
114
117
  export declare const qappend: {
115
118
  (a: Placeholder, b: any[]): (a: any) => any[];
116
119
  (a: any, b: Placeholder): (b: any[]) => any[];
@@ -144,7 +147,7 @@ export declare const qmergeShallow: {
144
147
  (a: AnyObject): (b: AnyObject) => AnyObject;
145
148
  (a: AnyObject, b: AnyObject): AnyObject;
146
149
  };
147
- /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
150
+ /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } removes a key when null. */
148
151
  export declare const qmapKeys: {
149
152
  (a: Placeholder, b: AnyObject): (a: {
150
153
  [oldKey: string]: string | AnyFunc;
@@ -231,17 +234,30 @@ export declare const qpick: {
231
234
  (a: string[], b: AnyObject): AnyObject;
232
235
  };
233
236
  export declare const qslice: (...args: AnyArgs) => any;
234
- export declare const quniq: (xs: any[]) => any[];
237
+ export declare const quniqWith: {
238
+ (a: Placeholder, b: any[]): (a: AnyFunc) => any[];
239
+ (a: AnyFunc, b: Placeholder): (b: any[]) => any[];
240
+ (a: AnyFunc): (b: any[]) => any[];
241
+ (a: AnyFunc, b: any[]): any[];
242
+ };
243
+ export declare const quniq: (b: any[]) => any[];
235
244
  export declare const qpush: {
236
245
  (a: Placeholder, b: any[]): (a: any) => any[];
237
246
  (a: any, b: Placeholder): (b: any[]) => any[];
238
247
  (a: any): (b: any[]) => any[];
239
248
  (a: any, b: any[]): any[];
240
249
  };
250
+ export declare const quniqBy: {
251
+ (a: Placeholder, b: any[]): (a: AnyFunc) => any[];
252
+ (a: AnyFunc, b: Placeholder): (b: any[]) => any[];
253
+ (a: AnyFunc): (b: any[]) => any[];
254
+ (a: AnyFunc, b: any[]): any[];
255
+ };
241
256
  export declare const isNil: <T extends any>(s: T) => T extends (null | undefined) ? true : false;
242
257
  export declare class QPromise<T> extends Promise<T> {
243
258
  private oncancel;
244
259
  private ff;
260
+ private rj;
245
261
  private _cancel_data;
246
262
  cancel(resolve?: boolean): void;
247
263
  constructor(fn: AnyFunc<any, [
@@ -389,9 +405,6 @@ export declare const divide: {
389
405
  (a: number): (b: number) => number;
390
406
  (a: number, b: number): number;
391
407
  };
392
- export declare const always: <T extends any>(s: T) => () => T;
393
- export declare const identity: <T extends any>(s: T) => T;
394
- export declare const trim: (s: string) => string;
395
408
  type T_not = {
396
409
  (x: true): false;
397
410
  (x: false): true;
package/dist/bundle.mjs CHANGED
@@ -100,15 +100,21 @@ const isSafe = (prop) => !(prop in unsafe_props);
100
100
  class QPromise extends Promise {
101
101
  oncancel;
102
102
  ff;
103
+ rj;
103
104
  _cancel_data;
104
105
  cancel(resolve = false) {
105
106
  if (resolve)
106
- this.ff();
107
+ this.ff?.();
108
+ else
109
+ this.rj?.();
107
110
  this.oncancel(this._cancel_data);
108
111
  }
109
112
  constructor(fn, oncancel = noop) {
110
113
  let _cancel_data = not_assigned;
111
- super((ff, rj) => _cancel_data = fn(ff, rj));
114
+ super((ff, rj) => {
115
+ _cancel_data = fn(ff, rj);
116
+ setTimeout(() => { this.ff = ff; this.rj = rj; });
117
+ });
112
118
  this.oncancel = oncancel;
113
119
  const set_cb = () => this._cancel_data = _cancel_data;
114
120
  // @ts-ignore-next
@@ -161,6 +167,9 @@ const includes = curry2((s, ss) => {
161
167
  return false;
162
168
  }
163
169
  });
170
+ const always = (s) => () => s;
171
+ const identity = (s) => s;
172
+ const trim = (s) => s.trim();
164
173
 
165
174
  const { min } = Math;
166
175
  const z = 0;
@@ -206,7 +215,7 @@ const qmergeDeepX = mergeDeep$1(2);
206
215
  const qmergeDeepAdd = mergeDeep$1(3);
207
216
  /** @param o1 <- o2 */
208
217
  const qmergeShallow = curry2((o1, o2) => Object.assign(o1, o2));
209
- /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
218
+ /** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } removes a key when null. */
210
219
  const qmapKeys = curry2((keyMap, o) => {
211
220
  let k, mapped, newKey, newValue, swap = {}, inswap;
212
221
  for (k in keyMap)
@@ -333,23 +342,26 @@ const rmel = (index, xs) => {
333
342
  return xs;
334
343
  };
335
344
  const seen = new Set();
336
- const quniq = (xs) => {
337
- seen.clear();
338
- let size = length(xs);
345
+ const quniqWith = curry2((getter, xs) => {
346
+ let size = length(xs), cur;
339
347
  for (let i = z; i < size; i++) {
340
348
  const x = xs[i];
341
- if (seen.has(x)) {
349
+ cur = getter(x);
350
+ if (seen.has(cur)) {
342
351
  rmel(i, xs);
343
352
  size--;
344
353
  i--;
345
354
  }
346
355
  else
347
- seen.add(x);
356
+ seen.add(cur);
348
357
  }
358
+ seen.clear();
349
359
  return xs;
350
- };
360
+ });
361
+ const quniq = quniqWith(identity);
351
362
  // Aliases.
352
363
  const qpush = qappend;
364
+ const quniqBy = quniqWith;
353
365
 
354
366
  const { assign } = Object;
355
367
  // TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
@@ -405,9 +417,6 @@ const find = curry2((fn, s) => s.find(fn));
405
417
  const findIndex = curry2((fn, s) => s.findIndex(fn));
406
418
  const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
407
419
  const divide = curry2((a, b) => b / a);
408
- const always = (s) => () => s;
409
- const identity = (s) => s;
410
- const trim = (s) => s.trim();
411
420
  const not = (x) => !x;
412
421
  const keys = (o) => Object.keys(o);
413
422
  const values = (o) => Object.values(o);
@@ -644,7 +653,7 @@ const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
644
653
  * @param data any
645
654
  * @returns data with prop over pipe.
646
655
  */
647
- const overProp = curry3((prop, pipe, data) => (prop in data) && assoc(prop, pipe(data[prop]), data));
656
+ const overProp = curry3((prop, pipe, data) => prop in data ? assoc(prop, pipe(data[prop]), data) : data);
648
657
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
649
658
  const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
650
659
  const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
@@ -808,4 +817,4 @@ const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => c
808
817
  // TODO: possibly introduce a second argument limiting unfolding.
809
818
  const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
810
819
 
811
- export { F, QPromise, 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, forEachParallel, 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, propLens, 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 };
820
+ export { F, QPromise, 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, forEachParallel, 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, propLens, 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, quniqBy, quniqWith, 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
@@ -36,13 +36,13 @@
36
36
  "lint": "tslint src/*.ts",
37
37
  "gentypes": "dts-bundle-generator --no-check --export-referenced-types=false -o dist/bundle.d.ts src/index.ts",
38
38
  "dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
39
- "watch": "nodemon --watch src 'npm run dev'",
39
+ "watch": "nodemon --watch src --ext ts,js --exec \"npm run dev\"",
40
40
  "prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
41
41
  "prod:es": "cross-env NODE_ENV=production BUILD=es rollup -c",
42
42
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
43
43
  "all": "npm run dev && npm run prod"
44
44
  },
45
- "version": "1.12.1",
45
+ "version": "1.12.3",
46
46
  "devDependencies": {
47
47
  "@rollup/plugin-commonjs": "^29.0.2",
48
48
  "@rollup/plugin-node-resolve": "^16.0.3",
@@ -50,6 +50,7 @@
50
50
  "@types/node": "^25.5.0",
51
51
  "cross-env": "^10.1.0",
52
52
  "dts-bundle-generator": "^9.5.1",
53
+ "nodemon": "^3.1.14",
53
54
  "rollup": "^4.59.0",
54
55
  "rollup-plugin-typescript2": "^0.36.0",
55
56
  "ts-node": "^10.9.2",
package/src/common.ts CHANGED
@@ -44,5 +44,8 @@ export const includes = curry2(
44
44
  }
45
45
  }
46
46
  )
47
- export { length } from './internal'
47
+ export const always = <T extends any>(s: T) => () => s
48
+ export const identity = <T extends any>(s: T) => s
49
+ export const trim = (s: string) => s.trim()
48
50
 
51
+ export { length } from './internal'
package/src/quick.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { includes, length, type } from "./common"
1
+ import { identity, includes, length, type } from "./common"
2
2
  import { curry2, curry3 } from "./curry"
3
3
  import { AnyFunc, AnyObject, Reducer } from "./types"
4
4
  import { inf, isArray, isFunc, isNil, isNum, isObj, isSafe } from "./utils"
@@ -175,16 +175,19 @@ const rmel = (index: number, xs: any[]) => {
175
175
  return xs
176
176
  }
177
177
  const seen = new Set()
178
- export const quniq = (xs: any[]) => {
179
- seen.clear()
180
- let size = length(xs)
178
+ export const quniqWith = curry2((getter: AnyFunc, xs: any[]) => {
179
+ let size = length(xs), cur: any
181
180
  for(let i=z; i<size; i++) {
182
181
  const x = xs[i]
183
- if(seen.has(x)) {rmel(i, xs); size--; i--}
184
- else seen.add(x)
182
+ cur = getter(x)
183
+ if(seen.has(cur)) {rmel(i, xs); size--; i--}
184
+ else seen.add(cur)
185
185
  }
186
+ seen.clear()
186
187
  return xs
187
- }
188
+ })
189
+ export const quniq = quniqWith(identity)
188
190
 
189
191
  // Aliases.
190
- export const qpush = qappend
192
+ export const qpush = qappend
193
+ export const quniqBy = quniqWith
package/src/safe.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { eq, equals, includes, length, symbol, type } from './common'
1
+ import { always, eq, equals, identity, includes, length, symbol, type } from './common'
2
2
  import { __, curry, curry2, curry3 } from './curry'
3
3
  import { is_typed_arr, startsWithWith } from './internal'
4
4
  import { AnyArray, IndexesOfArray, Split } from './internal_types'
@@ -108,9 +108,6 @@ export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
108
108
  export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
109
109
  export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
110
110
  export const divide = curry2((a: number, b: number) => b/a)
111
- export const always = <T extends any>(s: T) => () => s
112
- export const identity = <T extends any>(s: T) => s
113
- export const trim = (s: string) => s.trim()
114
111
 
115
112
  type T_not = {
116
113
  (x: true): false
package/src/utils.ts CHANGED
@@ -21,14 +21,18 @@ export const isSafe = (prop: string) => !(prop in unsafe_props)
21
21
  // TODO: add .then(), .finally() and .catch() to return QPromise.
22
22
  export class QPromise<T> extends Promise<T> {
23
23
  private ff: AnyFunc
24
+ private rj: AnyFunc
24
25
  private _cancel_data: any
25
26
  public cancel(resolve = false) {
26
- if(resolve) this.ff()
27
+ if(resolve) this.ff?.(); else this.rj?.()
27
28
  this.oncancel(this._cancel_data)
28
29
  }
29
30
  constructor(fn: AnyFunc<any, [AnyFunc, AnyFunc, AnyFunc?]>, private oncancel = noop) {
30
31
  let _cancel_data: any = not_assigned
31
- super((ff, rj) => _cancel_data = fn(ff, rj))
32
+ super((ff, rj) => {
33
+ _cancel_data = fn(ff, rj)
34
+ setTimeout(() => {this.ff = ff; this.rj = rj})
35
+ })
32
36
  const set_cb = () => this._cancel_data=_cancel_data
33
37
  // @ts-ignore-next
34
38
  if(_cancel_data!==not_assigned) set_cb()