pepka 1.10.0 → 1.11.1

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
@@ -83,6 +83,7 @@ const startsWithWith = (comparator) => curry2((start, s) => {
83
83
  return true;
84
84
  });
85
85
 
86
+ const unsafe_props = { '__proto__': true, 'constructor': true, 'prototype': true };
86
87
  const undef = undefined;
87
88
  const nul = null;
88
89
  const inf = Infinity;
@@ -96,6 +97,7 @@ function isFunc(s) { return to(s) === 'function'; }
96
97
  const isStr = (s) => (to(s) === 'string');
97
98
  const isObj = (s) => (!isNull(s) && to(s) === 'object');
98
99
  const isNil = (s) => (isNull(s) || isUndef(s));
100
+ const isSafe = (prop) => !(prop in unsafe_props);
99
101
  // TODO: add .then(), .finally() and .catch() to return QPromise.
100
102
  class QPromise extends Promise {
101
103
  oncancel;
@@ -168,35 +170,36 @@ const z = 0;
168
170
  const qappend = curry2((s, xs) => { xs.push(s); return xs; });
169
171
  const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
170
172
  const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
171
- // strategy is for arrays: 1->clean, 2->merge, 3->push.
173
+ // strategy is for arrays: 1->replace, 2->merge, 3->push.
172
174
  const mergeDeep$1 = (strategy) => curry2((o1, o2) => {
173
175
  for (let k in o2) {
174
- switch (type(o2[k])) {
175
- case 'Array':
176
- if (strategy > 1 && type(o1[k]) === 'Array')
177
- switch (strategy) {
178
- case 2:
179
- const o1k = o1[k], o2k = o2[k];
180
- for (const i in o2k)
181
- if (o1k[i])
182
- mergeDeep$1(strategy)(o1k[i], o2k[i]);
183
- else
184
- o1k[i] = o2k[i];
185
- break;
186
- case 3: o1[k].push(...o2[k]);
176
+ if (isSafe(k))
177
+ switch (type(o2[k])) {
178
+ case 'Array':
179
+ if (strategy > 1 && type(o1[k]) === 'Array')
180
+ switch (strategy) {
181
+ case 2:
182
+ const o1k = o1[k], o2k = o2[k];
183
+ for (const i in o2k)
184
+ if (o1k[i])
185
+ mergeDeep$1(strategy)(o1k[i], o2k[i]);
186
+ else
187
+ o1k[i] = o2k[i];
188
+ break;
189
+ case 3: o1[k].push(...o2[k]);
190
+ }
191
+ else
192
+ o1[k] = o2[k];
193
+ break;
194
+ case 'Object':
195
+ if (type(o1[k]) === 'Object') {
196
+ mergeDeep$1(strategy)(o1[k], o2[k]);
197
+ break;
187
198
  }
188
- else
199
+ default:
189
200
  o1[k] = o2[k];
190
- break;
191
- case 'Object':
192
- if (type(o1[k]) === 'Object') {
193
- mergeDeep$1(strategy)(o1[k], o2[k]);
194
201
  break;
195
- }
196
- default:
197
- o1[k] = o2[k];
198
- break;
199
- }
202
+ }
200
203
  }
201
204
  return o1;
202
205
  });
@@ -346,7 +349,8 @@ const quniq = (xs) => {
346
349
  // Aliases.
347
350
  const qpush = qappend;
348
351
 
349
- // TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
352
+ const { assign } = Object;
353
+ // TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
350
354
  const take = (argN) => (...args) => args[argN];
351
355
  const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
352
356
  const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
@@ -628,14 +632,19 @@ const memoize = curry2((keyGen, fn) => {
628
632
  return res;
629
633
  };
630
634
  });
631
- const mergeShallow = curry2((o1, o2) => Object.assign({}, o1, o2));
635
+ const mergeShallow = curry2((o1, o2) => assign({}, o1, o2));
632
636
  const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), b));
633
637
  const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), b));
634
638
  const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
635
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
636
- const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
639
+ /**
640
+ * @param prop string
641
+ * @param pipe(data[prop])
642
+ * @param data any
643
+ * @returns data with prop over pipe.
644
+ */
645
+ const overProp = curry3((prop, pipe, data) => (prop in data) && assoc(prop, pipe(data[prop]), data));
637
646
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
638
- const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
647
+ const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
639
648
  const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
640
649
  const zipObj = curry2((a, b) => reduce((ac, s, i) => assoc(s, b[i], ac), {}, a));
641
650
  // TODO: Tuple curried functions to replace these `AnyFuncs`.
@@ -655,6 +664,7 @@ const push = append;
655
664
  const some = any;
656
665
  const weakEq = eq;
657
666
  const uniqBy = uniqWith;
667
+ const propLens = overProp;
658
668
 
659
669
  /** One promise waits for another. */
660
670
  const forEachSerial = (() => {
@@ -889,6 +899,7 @@ exports.pickBy = pickBy;
889
899
  exports.prepend = prepend;
890
900
  exports.prop = prop;
891
901
  exports.propEq = propEq;
902
+ exports.propLens = propLens;
892
903
  exports.propsEq = propsEq;
893
904
  exports.push = push;
894
905
  exports.qappend = qappend;
package/dist/bundle.d.ts CHANGED
@@ -715,7 +715,12 @@ export declare const mergeDeepAdd: {
715
715
  (a: AnyObject): (b: AnyObject) => AnyObject;
716
716
  (a: AnyObject, b: AnyObject): AnyObject;
717
717
  };
718
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
718
+ /**
719
+ * @param prop string
720
+ * @param pipe(data[prop])
721
+ * @param data any
722
+ * @returns data with prop over pipe.
723
+ */
719
724
  export declare const overProp: (...args: AnyArgs) => any;
720
725
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
721
726
  export declare const mapKeys: {
@@ -779,6 +784,7 @@ export declare const uniqBy: {
779
784
  (a: (x: any, y: any) => boolean): (b: any[]) => any;
780
785
  (a: (x: any, y: any) => boolean, b: any[]): any;
781
786
  };
787
+ export declare const propLens: (...args: AnyArgs) => any;
782
788
  type StrTmpl = ((data: AnyObject) => string);
783
789
  /** Supports ecrans: '\\{"json": {yes} \\}'
784
790
  @returns getTmpl('one{meme}two')({meme: 42}) -> one42two */
package/dist/bundle.mjs CHANGED
@@ -81,6 +81,7 @@ const startsWithWith = (comparator) => curry2((start, s) => {
81
81
  return true;
82
82
  });
83
83
 
84
+ const unsafe_props = { '__proto__': true, 'constructor': true, 'prototype': true };
84
85
  const undef = undefined;
85
86
  const nul = null;
86
87
  const inf = Infinity;
@@ -94,6 +95,7 @@ function isFunc(s) { return to(s) === 'function'; }
94
95
  const isStr = (s) => (to(s) === 'string');
95
96
  const isObj = (s) => (!isNull(s) && to(s) === 'object');
96
97
  const isNil = (s) => (isNull(s) || isUndef(s));
98
+ const isSafe = (prop) => !(prop in unsafe_props);
97
99
  // TODO: add .then(), .finally() and .catch() to return QPromise.
98
100
  class QPromise extends Promise {
99
101
  oncancel;
@@ -166,35 +168,36 @@ const z = 0;
166
168
  const qappend = curry2((s, xs) => { xs.push(s); return xs; });
167
169
  const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
168
170
  const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
169
- // strategy is for arrays: 1->clean, 2->merge, 3->push.
171
+ // strategy is for arrays: 1->replace, 2->merge, 3->push.
170
172
  const mergeDeep$1 = (strategy) => curry2((o1, o2) => {
171
173
  for (let k in o2) {
172
- switch (type(o2[k])) {
173
- case 'Array':
174
- if (strategy > 1 && type(o1[k]) === 'Array')
175
- switch (strategy) {
176
- case 2:
177
- const o1k = o1[k], o2k = o2[k];
178
- for (const i in o2k)
179
- if (o1k[i])
180
- mergeDeep$1(strategy)(o1k[i], o2k[i]);
181
- else
182
- o1k[i] = o2k[i];
183
- break;
184
- case 3: o1[k].push(...o2[k]);
174
+ if (isSafe(k))
175
+ switch (type(o2[k])) {
176
+ case 'Array':
177
+ if (strategy > 1 && type(o1[k]) === 'Array')
178
+ switch (strategy) {
179
+ case 2:
180
+ const o1k = o1[k], o2k = o2[k];
181
+ for (const i in o2k)
182
+ if (o1k[i])
183
+ mergeDeep$1(strategy)(o1k[i], o2k[i]);
184
+ else
185
+ o1k[i] = o2k[i];
186
+ break;
187
+ case 3: o1[k].push(...o2[k]);
188
+ }
189
+ else
190
+ o1[k] = o2[k];
191
+ break;
192
+ case 'Object':
193
+ if (type(o1[k]) === 'Object') {
194
+ mergeDeep$1(strategy)(o1[k], o2[k]);
195
+ break;
185
196
  }
186
- else
197
+ default:
187
198
  o1[k] = o2[k];
188
- break;
189
- case 'Object':
190
- if (type(o1[k]) === 'Object') {
191
- mergeDeep$1(strategy)(o1[k], o2[k]);
192
199
  break;
193
- }
194
- default:
195
- o1[k] = o2[k];
196
- break;
197
- }
200
+ }
198
201
  }
199
202
  return o1;
200
203
  });
@@ -344,7 +347,8 @@ const quniq = (xs) => {
344
347
  // Aliases.
345
348
  const qpush = qappend;
346
349
 
347
- // TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
350
+ const { assign } = Object;
351
+ // TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
348
352
  const take = (argN) => (...args) => args[argN];
349
353
  const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
350
354
  const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
@@ -626,14 +630,19 @@ const memoize = curry2((keyGen, fn) => {
626
630
  return res;
627
631
  };
628
632
  });
629
- const mergeShallow = curry2((o1, o2) => Object.assign({}, o1, o2));
633
+ const mergeShallow = curry2((o1, o2) => assign({}, o1, o2));
630
634
  const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), b));
631
635
  const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), b));
632
636
  const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
633
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
634
- const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
637
+ /**
638
+ * @param prop string
639
+ * @param pipe(data[prop])
640
+ * @param data any
641
+ * @returns data with prop over pipe.
642
+ */
643
+ const overProp = curry3((prop, pipe, data) => (prop in data) && assoc(prop, pipe(data[prop]), data));
635
644
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
636
- const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
645
+ const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
637
646
  const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
638
647
  const zipObj = curry2((a, b) => reduce((ac, s, i) => assoc(s, b[i], ac), {}, a));
639
648
  // TODO: Tuple curried functions to replace these `AnyFuncs`.
@@ -653,6 +662,7 @@ const push = append;
653
662
  const some = any;
654
663
  const weakEq = eq;
655
664
  const uniqBy = uniqWith;
665
+ const propLens = overProp;
656
666
 
657
667
  /** One promise waits for another. */
658
668
  const forEachSerial = (() => {
@@ -794,4 +804,4 @@ const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => c
794
804
  // TODO: possibly introduce a second argument limiting unfolding.
795
805
  const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
796
806
 
797
- 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, 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 };
807
+ 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 };
package/package.json CHANGED
@@ -41,7 +41,7 @@
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.10.0",
44
+ "version": "1.11.1",
45
45
  "devDependencies": {
46
46
  "@rollup/plugin-commonjs": "^29.0.2",
47
47
  "@rollup/plugin-node-resolve": "^16.0.3",
package/src/curry.ts CHANGED
@@ -68,7 +68,7 @@ export type Curried2<p0, p1, ReturnT> = {
68
68
  }
69
69
 
70
70
  type Func2 = (a: any, b: any) => any
71
- const zero = 0, one = 1
71
+ const zero = 0
72
72
  export function curry2<Func extends Func2>(fn: Func) {
73
73
  type p0 = Parameters<Func>[0]
74
74
  type p1 = Parameters<Func>[1]
package/src/quick.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { includes, length, type } from "./common"
2
2
  import { curry2, curry3 } from "./curry"
3
3
  import { AnyFunc, AnyObject, Reducer } from "./types"
4
- import { inf, isArray, isFunc, isNil, isNum, isObj } from "./utils"
4
+ import { inf, isArray, isFunc, isNil, isNum, isObj, isSafe } from "./utils"
5
5
  const {min} = Math
6
6
  const z = 0
7
7
  /* qflat, qflatShallow, qreduceAsync */
@@ -9,10 +9,10 @@ const z = 0
9
9
  export const qappend = curry2((s: any, xs: any[]) => {xs.push(s); return xs})
10
10
  export const qassoc = curry3((prop: string, v: any, obj: AnyObject) => { obj[prop] = v; return obj })
11
11
  export const qreduce = curry3(<T>(fn: Reducer, accum: any, arr: T[]) => arr.reduce(fn, accum))
12
- // strategy is for arrays: 1->clean, 2->merge, 3->push.
12
+ // strategy is for arrays: 1->replace, 2->merge, 3->push.
13
13
  const mergeDeep = (strategy: 1|2|3) => curry2((o1: AnyObject, o2: AnyObject): AnyObject => {
14
14
  for(let k in o2) {
15
- switch(type(o2[k])) {
15
+ if(isSafe(k)) switch(type(o2[k])) {
16
16
  case 'Array':
17
17
  if(strategy>1 && type(o1[k])==='Array')
18
18
  switch(strategy) {
package/src/safe.ts CHANGED
@@ -5,7 +5,8 @@ import { AnyArray, IndexesOfArray, Split } from './internal_types'
5
5
  import { qappend, qfilter, qfreeze, qfreezeShallow, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qreduce } from './quick'
6
6
  import { AnyFunc, AnyObject, Composed, Cond, Reducer } from './types'
7
7
  import { inf, isArray, isFunc, isNil, isNum, isObj, undef } from './utils'
8
- // TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
8
+ const {assign} = Object
9
+ // TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
9
10
 
10
11
  export const take = (argN: number) => (...args: any[]) => args[argN]
11
12
  export const ifElse = curry(
@@ -410,7 +411,7 @@ export const memoize = curry2(<Args extends any[]>(
410
411
  })
411
412
  export const mergeShallow = curry2(
412
413
  (o1: AnyObject, o2: AnyObject): AnyObject =>
413
- Object.assign({}, o1, o2)
414
+ assign({}, o1, o2)
414
415
  )
415
416
  export const mergeDeep = curry2(
416
417
  (a: AnyObject, b: AnyObject) => qmergeDeep(clone(a), b) as AnyObject
@@ -421,17 +422,22 @@ export const mergeDeepX = curry2(
421
422
  export const mergeDeepAdd = curry2(
422
423
  (a: AnyObject, b: AnyObject) => qmergeDeepAdd(clone(a), b) as AnyObject
423
424
  )
424
- /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
425
+ /**
426
+ * @param prop string
427
+ * @param pipe(data[prop])
428
+ * @param data any
429
+ * @returns data with prop over pipe.
430
+ */
425
431
  export const overProp = curry3(
426
432
  (prop: string, pipe: AnyFunc, data: any) =>
427
- assoc(prop, pipe(data[prop]), data)
433
+ (prop in data) && assoc(prop, pipe(data[prop]), data)
428
434
  )
429
435
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
430
436
  export const mapKeys = curry2(
431
437
  (
432
438
  keyMap: {[oldKey: string]: string | AnyFunc},
433
439
  o: AnyObject
434
- ) => qmapKeys(keyMap, Object.assign({}, o))
440
+ ) => qmapKeys(keyMap, assign({}, o))
435
441
  )
436
442
  export const zip = curry2(
437
443
  <T1 = any, T2 = any>(a: T1[], b: T2[]) => map((s: T1, i: number) => [s, b[i]], a)
@@ -464,4 +470,5 @@ export const notf = complement
464
470
  export const push = append
465
471
  export const some = any
466
472
  export const weakEq = eq
467
- export const uniqBy = uniqWith
473
+ export const uniqBy = uniqWith
474
+ export const propLens = overProp
package/src/utils.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { noop } from "./safe"
2
2
  import { AnyFunc, AnyObject } from "./types"
3
3
 
4
+ const unsafe_props = {'__proto__': true, 'constructor': true, 'prototype': true}
4
5
  export const undef = undefined
5
6
  export const nul = null
6
7
  export const inf = Infinity
@@ -16,7 +17,7 @@ export function isFunc(s: any) { return to(s)==='function' }
16
17
  export const isStr = <T extends any>(s: T) => (to(s)==='string') as T extends string ? true : false
17
18
  export const isObj = <T extends any>(s: T) => (!isNull(s) && to(s)==='object') as T extends AnyObject ? true : false
18
19
  export const isNil = <T extends any>(s: T) => (isNull(s) || isUndef(s)) as T extends (null|undefined) ? true : false
19
-
20
+ export const isSafe = (prop: string) => !(prop in unsafe_props)
20
21
  // TODO: add .then(), .finally() and .catch() to return QPromise.
21
22
  export class QPromise<T> extends Promise<T> {
22
23
  private ff: AnyFunc