pepka 1.10.0 → 1.11.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
@@ -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,6 +349,7 @@ const quniq = (xs) => {
346
349
  // Aliases.
347
350
  const qpush = qappend;
348
351
 
352
+ const { assign } = Object;
349
353
  // TODO: over, lensProp, 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));
@@ -628,14 +632,14 @@ 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
639
  /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
636
640
  const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
637
641
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
638
- const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
642
+ const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
639
643
  const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
640
644
  const zipObj = curry2((a, b) => reduce((ac, s, i) => assoc(s, b[i], ac), {}, a));
641
645
  // TODO: Tuple curried functions to replace these `AnyFuncs`.
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,6 +347,7 @@ const quniq = (xs) => {
344
347
  // Aliases.
345
348
  const qpush = qappend;
346
349
 
350
+ const { assign } = Object;
347
351
  // TODO: over, lensProp, 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));
@@ -626,14 +630,14 @@ 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
637
  /** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
634
638
  const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
635
639
  /** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
636
- const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, Object.assign({}, o)));
640
+ const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
637
641
  const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
638
642
  const zipObj = curry2((a, b) => reduce((ac, s, i) => assoc(s, b[i], ac), {}, a));
639
643
  // TODO: Tuple curried functions to replace these `AnyFuncs`.
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.0",
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,6 +5,7 @@ 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
+ const {assign} = Object
8
9
  // TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
9
10
 
10
11
  export const take = (argN: number) => (...args: any[]) => args[argN]
@@ -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
@@ -431,7 +432,7 @@ export const mapKeys = curry2(
431
432
  (
432
433
  keyMap: {[oldKey: string]: string | AnyFunc},
433
434
  o: AnyObject
434
- ) => qmapKeys(keyMap, Object.assign({}, o))
435
+ ) => qmapKeys(keyMap, assign({}, o))
435
436
  )
436
437
  export const zip = curry2(
437
438
  <T1 = any, T2 = any>(a: T1[], b: T2[]) => map((s: T1, i: number) => [s, b[i]], a)
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