pepka 1.11.0 → 1.12.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 +17 -6
- package/dist/bundle.d.ts +7 -1
- package/dist/bundle.mjs +17 -7
- package/package.json +2 -1
- package/src/quick.ts +5 -3
- package/src/safe.ts +10 -4
- package/test/workbench.html +1 -0
package/dist/bundle.cjs
CHANGED
|
@@ -210,15 +210,19 @@ const qmergeDeepAdd = mergeDeep$1(3);
|
|
|
210
210
|
const qmergeShallow = curry2((o1, o2) => Object.assign(o1, o2));
|
|
211
211
|
/** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
212
212
|
const qmapKeys = curry2((keyMap, o) => {
|
|
213
|
-
let k, mapped, newKey, newValue;
|
|
213
|
+
let k, mapped, newKey, newValue, swap = {}, inswap;
|
|
214
214
|
for (k in keyMap)
|
|
215
215
|
if (k in o) {
|
|
216
216
|
mapped = keyMap[k];
|
|
217
217
|
[newKey, newValue] = isFunc(mapped)
|
|
218
218
|
? mapped(o[k], k, o)
|
|
219
219
|
: [mapped, o[k]];
|
|
220
|
-
|
|
221
|
-
|
|
220
|
+
if (newKey in keyMap)
|
|
221
|
+
swap[newKey] = o[newKey];
|
|
222
|
+
inswap = k in swap;
|
|
223
|
+
if (!isNil(newKey))
|
|
224
|
+
o[newKey] = inswap ? swap[k] : newValue;
|
|
225
|
+
if (!inswap && k !== newKey)
|
|
222
226
|
delete o[k];
|
|
223
227
|
}
|
|
224
228
|
return o;
|
|
@@ -350,7 +354,7 @@ const quniq = (xs) => {
|
|
|
350
354
|
const qpush = qappend;
|
|
351
355
|
|
|
352
356
|
const { assign } = Object;
|
|
353
|
-
// TODO: over,
|
|
357
|
+
// TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
354
358
|
const take = (argN) => (...args) => args[argN];
|
|
355
359
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
356
360
|
const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
|
|
@@ -636,8 +640,13 @@ const mergeShallow = curry2((o1, o2) => assign({}, o1, o2));
|
|
|
636
640
|
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), b));
|
|
637
641
|
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), b));
|
|
638
642
|
const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
|
|
639
|
-
/**
|
|
640
|
-
|
|
643
|
+
/**
|
|
644
|
+
* @param prop string
|
|
645
|
+
* @param pipe(data[prop])
|
|
646
|
+
* @param data any
|
|
647
|
+
* @returns data with prop over pipe.
|
|
648
|
+
*/
|
|
649
|
+
const overProp = curry3((prop, pipe, data) => (prop in data) && assoc(prop, pipe(data[prop]), data));
|
|
641
650
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
642
651
|
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
|
|
643
652
|
const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
|
|
@@ -659,6 +668,7 @@ const push = append;
|
|
|
659
668
|
const some = any;
|
|
660
669
|
const weakEq = eq;
|
|
661
670
|
const uniqBy = uniqWith;
|
|
671
|
+
const propLens = overProp;
|
|
662
672
|
|
|
663
673
|
/** One promise waits for another. */
|
|
664
674
|
const forEachSerial = (() => {
|
|
@@ -893,6 +903,7 @@ exports.pickBy = pickBy;
|
|
|
893
903
|
exports.prepend = prepend;
|
|
894
904
|
exports.prop = prop;
|
|
895
905
|
exports.propEq = propEq;
|
|
906
|
+
exports.propLens = propLens;
|
|
896
907
|
exports.propsEq = propsEq;
|
|
897
908
|
exports.push = push;
|
|
898
909
|
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
|
-
/**
|
|
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
|
@@ -208,15 +208,19 @@ const qmergeDeepAdd = mergeDeep$1(3);
|
|
|
208
208
|
const qmergeShallow = curry2((o1, o2) => Object.assign(o1, o2));
|
|
209
209
|
/** qmapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
210
210
|
const qmapKeys = curry2((keyMap, o) => {
|
|
211
|
-
let k, mapped, newKey, newValue;
|
|
211
|
+
let k, mapped, newKey, newValue, swap = {}, inswap;
|
|
212
212
|
for (k in keyMap)
|
|
213
213
|
if (k in o) {
|
|
214
214
|
mapped = keyMap[k];
|
|
215
215
|
[newKey, newValue] = isFunc(mapped)
|
|
216
216
|
? mapped(o[k], k, o)
|
|
217
217
|
: [mapped, o[k]];
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
if (newKey in keyMap)
|
|
219
|
+
swap[newKey] = o[newKey];
|
|
220
|
+
inswap = k in swap;
|
|
221
|
+
if (!isNil(newKey))
|
|
222
|
+
o[newKey] = inswap ? swap[k] : newValue;
|
|
223
|
+
if (!inswap && k !== newKey)
|
|
220
224
|
delete o[k];
|
|
221
225
|
}
|
|
222
226
|
return o;
|
|
@@ -348,7 +352,7 @@ const quniq = (xs) => {
|
|
|
348
352
|
const qpush = qappend;
|
|
349
353
|
|
|
350
354
|
const { assign } = Object;
|
|
351
|
-
// TODO: over,
|
|
355
|
+
// TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
352
356
|
const take = (argN) => (...args) => args[argN];
|
|
353
357
|
const ifElse = curry((cond, pipeYes, pipeNo, s) => cond(s) ? pipeYes(s) : pipeNo(s));
|
|
354
358
|
const when = curry3((cond, pipe, s) => ifElse(cond, pipe, identity, s));
|
|
@@ -634,8 +638,13 @@ const mergeShallow = curry2((o1, o2) => assign({}, o1, o2));
|
|
|
634
638
|
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), b));
|
|
635
639
|
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), b));
|
|
636
640
|
const mergeDeepAdd = curry2((a, b) => qmergeDeepAdd(clone(a), b));
|
|
637
|
-
/**
|
|
638
|
-
|
|
641
|
+
/**
|
|
642
|
+
* @param prop string
|
|
643
|
+
* @param pipe(data[prop])
|
|
644
|
+
* @param data any
|
|
645
|
+
* @returns data with prop over pipe.
|
|
646
|
+
*/
|
|
647
|
+
const overProp = curry3((prop, pipe, data) => (prop in data) && assoc(prop, pipe(data[prop]), data));
|
|
639
648
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
640
649
|
const mapKeys = curry2((keyMap, o) => qmapKeys(keyMap, assign({}, o)));
|
|
641
650
|
const zip = curry2((a, b) => map((s, i) => [s, b[i]], a));
|
|
@@ -657,6 +666,7 @@ const push = append;
|
|
|
657
666
|
const some = any;
|
|
658
667
|
const weakEq = eq;
|
|
659
668
|
const uniqBy = uniqWith;
|
|
669
|
+
const propLens = overProp;
|
|
660
670
|
|
|
661
671
|
/** One promise waits for another. */
|
|
662
672
|
const forEachSerial = (() => {
|
|
@@ -798,4 +808,4 @@ const wait = (time) => new QPromise((ff) => setTimeout(ff, time), (timeout) => c
|
|
|
798
808
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
799
809
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
800
810
|
|
|
801
|
-
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 };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -36,12 +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
40
|
"prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
|
|
40
41
|
"prod:es": "cross-env NODE_ENV=production BUILD=es rollup -c",
|
|
41
42
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
42
43
|
"all": "npm run dev && npm run prod"
|
|
43
44
|
},
|
|
44
|
-
"version": "1.
|
|
45
|
+
"version": "1.12.0",
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@rollup/plugin-commonjs": "^29.0.2",
|
|
47
48
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/quick.ts
CHANGED
|
@@ -50,14 +50,16 @@ export const qmapKeys = curry2(
|
|
|
50
50
|
keyMap: {[oldKey: string]: string | AnyFunc},
|
|
51
51
|
o: AnyObject
|
|
52
52
|
) => {
|
|
53
|
-
let k: string, mapped: string | AnyFunc, newKey: string, newValue: any
|
|
53
|
+
let k: string, mapped: string | AnyFunc, newKey: string, newValue: any, swap: AnyObject = {}, inswap: boolean
|
|
54
54
|
for(k in keyMap) if(k in o) {
|
|
55
55
|
mapped = keyMap[k]
|
|
56
56
|
;[newKey, newValue] = isFunc(mapped)
|
|
57
57
|
? (mapped as AnyFunc)(o[k], k, o)
|
|
58
58
|
: [mapped, o[k]]
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
if(newKey in keyMap) swap[newKey] = o[newKey]
|
|
60
|
+
inswap = k in swap
|
|
61
|
+
if(!isNil(newKey)) o[newKey] = inswap ? swap[k] : newValue
|
|
62
|
+
if(!inswap && k !== newKey) delete o[k]
|
|
61
63
|
}
|
|
62
64
|
return o
|
|
63
65
|
}
|
package/src/safe.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { qappend, qfilter, qfreeze, qfreezeShallow, qmapKeys, qmapObj, qmergeDee
|
|
|
6
6
|
import { AnyFunc, AnyObject, Composed, Cond, Reducer } from './types'
|
|
7
7
|
import { inf, isArray, isFunc, isNil, isNum, isObj, undef } from './utils'
|
|
8
8
|
const {assign} = Object
|
|
9
|
-
// TODO: over,
|
|
9
|
+
// TODO: over, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
10
10
|
|
|
11
11
|
export const take = (argN: number) => (...args: any[]) => args[argN]
|
|
12
12
|
export const ifElse = curry(
|
|
@@ -422,10 +422,15 @@ export const mergeDeepX = curry2(
|
|
|
422
422
|
export const mergeDeepAdd = curry2(
|
|
423
423
|
(a: AnyObject, b: AnyObject) => qmergeDeepAdd(clone(a), b) as AnyObject
|
|
424
424
|
)
|
|
425
|
-
/**
|
|
425
|
+
/**
|
|
426
|
+
* @param prop string
|
|
427
|
+
* @param pipe(data[prop])
|
|
428
|
+
* @param data any
|
|
429
|
+
* @returns data with prop over pipe.
|
|
430
|
+
*/
|
|
426
431
|
export const overProp = curry3(
|
|
427
432
|
(prop: string, pipe: AnyFunc, data: any) =>
|
|
428
|
-
assoc(prop, pipe(data[prop]), data)
|
|
433
|
+
(prop in data) && assoc(prop, pipe(data[prop]), data)
|
|
429
434
|
)
|
|
430
435
|
/** mapKeys({ a: 'b' }, { a: 44 }) -> { b: 44 } */
|
|
431
436
|
export const mapKeys = curry2(
|
|
@@ -465,4 +470,5 @@ export const notf = complement
|
|
|
465
470
|
export const push = append
|
|
466
471
|
export const some = any
|
|
467
472
|
export const weakEq = eq
|
|
468
|
-
export const uniqBy = uniqWith
|
|
473
|
+
export const uniqBy = uniqWith
|
|
474
|
+
export const propLens = overProp
|