pepka 1.9.5 → 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 +35 -30
- package/dist/bundle.mjs +35 -30
- package/package.json +1 -1
- package/src/common.ts +2 -0
- package/src/curry.ts +1 -1
- package/src/quick.ts +3 -3
- package/src/safe.ts +3 -2
- package/src/utils.ts +4 -4
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,8 @@ 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);
|
|
101
|
+
// TODO: add .then(), .finally() and .catch() to return QPromise.
|
|
99
102
|
class QPromise extends Promise {
|
|
100
103
|
oncancel;
|
|
101
104
|
ff;
|
|
@@ -107,9 +110,7 @@ class QPromise extends Promise {
|
|
|
107
110
|
}
|
|
108
111
|
constructor(fn, oncancel = noop) {
|
|
109
112
|
let _cancel_data = not_assigned;
|
|
110
|
-
super((ff, rj) =>
|
|
111
|
-
_cancel_data = fn(ff, rj);
|
|
112
|
-
});
|
|
113
|
+
super((ff, rj) => _cancel_data = fn(ff, rj));
|
|
113
114
|
this.oncancel = oncancel;
|
|
114
115
|
const set_cb = () => this._cancel_data = _cancel_data;
|
|
115
116
|
// @ts-ignore-next
|
|
@@ -120,6 +121,7 @@ class QPromise extends Promise {
|
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
|
|
124
|
+
const { isNaN } = Number;
|
|
123
125
|
// It's faster that toUpperCase() !
|
|
124
126
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F', o: 'O' };
|
|
125
127
|
const symbol = Symbol();
|
|
@@ -130,7 +132,8 @@ const type = (s) => {
|
|
|
130
132
|
const t = to(s);
|
|
131
133
|
return t === 'object'
|
|
132
134
|
? isNull(s) ? 'Null' : (s.constructor?.name || cap_type(t))
|
|
133
|
-
:
|
|
135
|
+
: t === 'number' && isNaN(s) ? 'NaN'
|
|
136
|
+
: cap_type(t);
|
|
134
137
|
};
|
|
135
138
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
136
139
|
const eq = curry2((a, b) => a === b);
|
|
@@ -167,35 +170,36 @@ const z = 0;
|
|
|
167
170
|
const qappend = curry2((s, xs) => { xs.push(s); return xs; });
|
|
168
171
|
const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
|
|
169
172
|
const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
|
|
170
|
-
// strategy is for arrays: 1->
|
|
173
|
+
// strategy is for arrays: 1->replace, 2->merge, 3->push.
|
|
171
174
|
const mergeDeep$1 = (strategy) => curry2((o1, o2) => {
|
|
172
175
|
for (let k in o2) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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;
|
|
186
198
|
}
|
|
187
|
-
|
|
199
|
+
default:
|
|
188
200
|
o1[k] = o2[k];
|
|
189
|
-
break;
|
|
190
|
-
case 'Object':
|
|
191
|
-
if (type(o1[k]) === 'Object') {
|
|
192
|
-
mergeDeep$1(strategy)(o1[k], o2[k]);
|
|
193
201
|
break;
|
|
194
|
-
|
|
195
|
-
default:
|
|
196
|
-
o1[k] = o2[k];
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
202
|
+
}
|
|
199
203
|
}
|
|
200
204
|
return o1;
|
|
201
205
|
});
|
|
@@ -345,6 +349,7 @@ const quniq = (xs) => {
|
|
|
345
349
|
// Aliases.
|
|
346
350
|
const qpush = qappend;
|
|
347
351
|
|
|
352
|
+
const { assign } = Object;
|
|
348
353
|
// TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
349
354
|
const take = (argN) => (...args) => args[argN];
|
|
350
355
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
@@ -627,14 +632,14 @@ const memoize = curry2((keyGen, fn) => {
|
|
|
627
632
|
return res;
|
|
628
633
|
};
|
|
629
634
|
});
|
|
630
|
-
const mergeShallow = curry2((o1, o2) =>
|
|
635
|
+
const mergeShallow = curry2((o1, o2) => assign({}, o1, o2));
|
|
631
636
|
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), b));
|
|
632
637
|
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), b));
|
|
633
638
|
const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
|
|
634
639
|
/** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
|
|
635
640
|
const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
|
|
636
641
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
637
|
-
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap,
|
|
642
|
+
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
|
|
638
643
|
const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
|
|
639
644
|
const zipObj = curry2((a, b) => reduce((ac, s, i) => assoc(s, b[i], ac), {}, a));
|
|
640
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,8 @@ 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);
|
|
99
|
+
// TODO: add .then(), .finally() and .catch() to return QPromise.
|
|
97
100
|
class QPromise extends Promise {
|
|
98
101
|
oncancel;
|
|
99
102
|
ff;
|
|
@@ -105,9 +108,7 @@ class QPromise extends Promise {
|
|
|
105
108
|
}
|
|
106
109
|
constructor(fn, oncancel = noop) {
|
|
107
110
|
let _cancel_data = not_assigned;
|
|
108
|
-
super((ff, rj) =>
|
|
109
|
-
_cancel_data = fn(ff, rj);
|
|
110
|
-
});
|
|
111
|
+
super((ff, rj) => _cancel_data = fn(ff, rj));
|
|
111
112
|
this.oncancel = oncancel;
|
|
112
113
|
const set_cb = () => this._cancel_data = _cancel_data;
|
|
113
114
|
// @ts-ignore-next
|
|
@@ -118,6 +119,7 @@ class QPromise extends Promise {
|
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
|
122
|
+
const { isNaN } = Number;
|
|
121
123
|
// It's faster that toUpperCase() !
|
|
122
124
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F', o: 'O' };
|
|
123
125
|
const symbol = Symbol();
|
|
@@ -128,7 +130,8 @@ const type = (s) => {
|
|
|
128
130
|
const t = to(s);
|
|
129
131
|
return t === 'object'
|
|
130
132
|
? isNull(s) ? 'Null' : (s.constructor?.name || cap_type(t))
|
|
131
|
-
:
|
|
133
|
+
: t === 'number' && isNaN(s) ? 'NaN'
|
|
134
|
+
: cap_type(t);
|
|
132
135
|
};
|
|
133
136
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
134
137
|
const eq = curry2((a, b) => a === b);
|
|
@@ -165,35 +168,36 @@ const z = 0;
|
|
|
165
168
|
const qappend = curry2((s, xs) => { xs.push(s); return xs; });
|
|
166
169
|
const qassoc = curry3((prop, v, obj) => { obj[prop] = v; return obj; });
|
|
167
170
|
const qreduce = curry3((fn, accum, arr) => arr.reduce(fn, accum));
|
|
168
|
-
// strategy is for arrays: 1->
|
|
171
|
+
// strategy is for arrays: 1->replace, 2->merge, 3->push.
|
|
169
172
|
const mergeDeep$1 = (strategy) => curry2((o1, o2) => {
|
|
170
173
|
for (let k in o2) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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;
|
|
184
196
|
}
|
|
185
|
-
|
|
197
|
+
default:
|
|
186
198
|
o1[k] = o2[k];
|
|
187
|
-
break;
|
|
188
|
-
case 'Object':
|
|
189
|
-
if (type(o1[k]) === 'Object') {
|
|
190
|
-
mergeDeep$1(strategy)(o1[k], o2[k]);
|
|
191
199
|
break;
|
|
192
|
-
|
|
193
|
-
default:
|
|
194
|
-
o1[k] = o2[k];
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
200
|
+
}
|
|
197
201
|
}
|
|
198
202
|
return o1;
|
|
199
203
|
});
|
|
@@ -343,6 +347,7 @@ const quniq = (xs) => {
|
|
|
343
347
|
// Aliases.
|
|
344
348
|
const qpush = qappend;
|
|
345
349
|
|
|
350
|
+
const { assign } = Object;
|
|
346
351
|
// TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
347
352
|
const take = (argN) => (...args) => args[argN];
|
|
348
353
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
@@ -625,14 +630,14 @@ const memoize = curry2((keyGen, fn) => {
|
|
|
625
630
|
return res;
|
|
626
631
|
};
|
|
627
632
|
});
|
|
628
|
-
const mergeShallow = curry2((o1, o2) =>
|
|
633
|
+
const mergeShallow = curry2((o1, o2) => assign({}, o1, o2));
|
|
629
634
|
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), b));
|
|
630
635
|
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), b));
|
|
631
636
|
const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
|
|
632
637
|
/** @param prop string @param pipe(data[prop]) @param data any @returns data with prop over pipe. */
|
|
633
638
|
const overProp = curry3((prop, pipe, data) => assoc(prop, pipe(data[prop]), data));
|
|
634
639
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
635
|
-
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap,
|
|
640
|
+
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
|
|
636
641
|
const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
|
|
637
642
|
const zipObj = curry2((a, b) => reduce((ac, s, i) => assoc(s, b[i], ac), {}, a));
|
|
638
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.
|
|
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/common.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { curry2 } from "./curry"
|
|
2
2
|
import { is_typed_arr } from "./internal"
|
|
3
3
|
import { isNull, isStr, to } from "./utils"
|
|
4
|
+
const {isNaN} = Number
|
|
4
5
|
|
|
5
6
|
// It's faster that toUpperCase() !
|
|
6
7
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F', o: 'O' }
|
|
@@ -13,6 +14,7 @@ export const type = (s: any): string => {
|
|
|
13
14
|
const t = to(s)
|
|
14
15
|
return t==='object'
|
|
15
16
|
? isNull(s) ? 'Null' : (s.constructor?.name||cap_type(t))
|
|
17
|
+
: t==='number'&&isNaN(s) ? 'NaN'
|
|
16
18
|
: cap_type(t)
|
|
17
19
|
}
|
|
18
20
|
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
package/src/curry.ts
CHANGED
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->
|
|
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
|
-
|
|
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,
|
|
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,8 @@ 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)
|
|
21
|
+
// TODO: add .then(), .finally() and .catch() to return QPromise.
|
|
20
22
|
export class QPromise<T> extends Promise<T> {
|
|
21
23
|
private ff: AnyFunc
|
|
22
24
|
private _cancel_data: any
|
|
@@ -26,9 +28,7 @@ export class QPromise<T> extends Promise<T> {
|
|
|
26
28
|
}
|
|
27
29
|
constructor(fn: AnyFunc<any, [AnyFunc, AnyFunc, AnyFunc?]>, private oncancel = noop) {
|
|
28
30
|
let _cancel_data: any = not_assigned
|
|
29
|
-
super((ff, rj) =>
|
|
30
|
-
_cancel_data = fn(ff, rj)
|
|
31
|
-
})
|
|
31
|
+
super((ff, rj) => _cancel_data = fn(ff, rj))
|
|
32
32
|
const set_cb = () => this._cancel_data=_cancel_data
|
|
33
33
|
// @ts-ignore-next
|
|
34
34
|
if(_cancel_data!==not_assigned) set_cb()
|