pepka 1.4.2 → 1.5.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 +23 -10
- package/dist/bundle.d.ts +10 -1
- package/dist/bundle.mjs +23 -10
- package/package.json +1 -2
- package/src/safe.ts +24 -10
- package/dts-fix.js +0 -10
package/dist/bundle.cjs
CHANGED
|
@@ -343,11 +343,14 @@ const range = curry2((from, to) => genBy(add(from), to - from));
|
|
|
343
343
|
const uniq = (xs) => qreduce((accum, x) => find(equals(x), accum) ? accum : qappend(x, accum), [], xs);
|
|
344
344
|
const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
|
|
345
345
|
const diff = curry2((_xs1, _xs2) => {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
const
|
|
350
|
-
const
|
|
346
|
+
// BUG: if _xs1 is empty, results in [undefined, ...]
|
|
347
|
+
let len1 = length(_xs1);
|
|
348
|
+
let len2 = length(_xs2); // xs2 should be shorter 4 Set mem consumption.
|
|
349
|
+
const xs1 = len1 > len2 ? _xs1 : _xs2; // ['qwe', 'qwe2'].
|
|
350
|
+
const xs2 = len1 > len2 ? _xs2 : _xs1; // [].
|
|
351
|
+
if (len1 <= len2)
|
|
352
|
+
[len1, len2] = [len2, len1];
|
|
353
|
+
const xset2 = new Set(xs2); // empty set.
|
|
351
354
|
const common = new Set();
|
|
352
355
|
const out = [];
|
|
353
356
|
let i;
|
|
@@ -483,11 +486,21 @@ const replace = curry3((a, b, where
|
|
|
483
486
|
const filter = curry2((cond, data) => isArray(data)
|
|
484
487
|
? data.filter(cond)
|
|
485
488
|
: qfilter(cond, { ...data }));
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
489
|
+
/** Saves result of a function with given key and avoids calling it again.
|
|
490
|
+
* @param {(...args: Args) string} keyGen that takes the same args and returns a key for the cache.
|
|
491
|
+
* @param {(...args: Args) any} fn to be cached.
|
|
492
|
+
*/
|
|
493
|
+
const memoize = curry2((keyGen, fn) => {
|
|
494
|
+
const cache = {};
|
|
495
|
+
return (...args) => {
|
|
496
|
+
const key = keyGen(...args);
|
|
497
|
+
if (key in cache)
|
|
498
|
+
return cache[key];
|
|
499
|
+
const res = fn(...args);
|
|
500
|
+
cache[key] = res;
|
|
501
|
+
return res;
|
|
502
|
+
};
|
|
503
|
+
});
|
|
491
504
|
const mergeShallow = curry2((o1, o2) => Object.assign({}, o1, o2));
|
|
492
505
|
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), clone(b)));
|
|
493
506
|
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), clone(b)));
|
package/dist/bundle.d.ts
CHANGED
|
@@ -425,7 +425,16 @@ export declare const filter: {
|
|
|
425
425
|
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any;
|
|
426
426
|
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any;
|
|
427
427
|
};
|
|
428
|
-
|
|
428
|
+
/** Saves result of a function with given key and avoids calling it again.
|
|
429
|
+
* @param {(...args: Args) string} keyGen that takes the same args and returns a key for the cache.
|
|
430
|
+
* @param {(...args: Args) any} fn to be cached.
|
|
431
|
+
*/
|
|
432
|
+
export declare const memoize: {
|
|
433
|
+
(a: symbol, b: AnyFunc<any, any[]>): (a: (...args: any[]) => string) => (...args: any[]) => any;
|
|
434
|
+
(a: (...args: any[]) => string, b: symbol): (b: AnyFunc<any, any[]>) => (...args: any[]) => any;
|
|
435
|
+
(a: (...args: any[]) => string): (b: AnyFunc<any, any[]>) => (...args: any[]) => any;
|
|
436
|
+
(a: (...args: any[]) => string, b: AnyFunc<any, any[]>): (...args: any[]) => any;
|
|
437
|
+
};
|
|
429
438
|
export declare const mergeShallow: {
|
|
430
439
|
(a: symbol, b: AnyObject): (a: AnyObject) => AnyObject;
|
|
431
440
|
(a: AnyObject, b: symbol): (b: AnyObject) => AnyObject;
|
package/dist/bundle.mjs
CHANGED
|
@@ -341,11 +341,14 @@ const range = curry2((from, to) => genBy(add(from), to - from));
|
|
|
341
341
|
const uniq = (xs) => qreduce((accum, x) => find(equals(x), accum) ? accum : qappend(x, accum), [], xs);
|
|
342
342
|
const intersection = curry2((xs1, xs2) => xs1.filter(flip(includes)(xs2)));
|
|
343
343
|
const diff = curry2((_xs1, _xs2) => {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
const
|
|
344
|
+
// BUG: if _xs1 is empty, results in [undefined, ...]
|
|
345
|
+
let len1 = length(_xs1);
|
|
346
|
+
let len2 = length(_xs2); // xs2 should be shorter 4 Set mem consumption.
|
|
347
|
+
const xs1 = len1 > len2 ? _xs1 : _xs2; // ['qwe', 'qwe2'].
|
|
348
|
+
const xs2 = len1 > len2 ? _xs2 : _xs1; // [].
|
|
349
|
+
if (len1 <= len2)
|
|
350
|
+
[len1, len2] = [len2, len1];
|
|
351
|
+
const xset2 = new Set(xs2); // empty set.
|
|
349
352
|
const common = new Set();
|
|
350
353
|
const out = [];
|
|
351
354
|
let i;
|
|
@@ -481,11 +484,21 @@ const replace = curry3((a, b, where
|
|
|
481
484
|
const filter = curry2((cond, data) => isArray(data)
|
|
482
485
|
? data.filter(cond)
|
|
483
486
|
: qfilter(cond, { ...data }));
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
487
|
+
/** Saves result of a function with given key and avoids calling it again.
|
|
488
|
+
* @param {(...args: Args) string} keyGen that takes the same args and returns a key for the cache.
|
|
489
|
+
* @param {(...args: Args) any} fn to be cached.
|
|
490
|
+
*/
|
|
491
|
+
const memoize = curry2((keyGen, fn) => {
|
|
492
|
+
const cache = {};
|
|
493
|
+
return (...args) => {
|
|
494
|
+
const key = keyGen(...args);
|
|
495
|
+
if (key in cache)
|
|
496
|
+
return cache[key];
|
|
497
|
+
const res = fn(...args);
|
|
498
|
+
cache[key] = res;
|
|
499
|
+
return res;
|
|
500
|
+
};
|
|
501
|
+
});
|
|
489
502
|
const mergeShallow = curry2((o1, o2) => Object.assign({}, o1, o2));
|
|
490
503
|
const mergeDeep = curry2((a, b) => qmergeDeep(clone(a), clone(b)));
|
|
491
504
|
const mergeDeepX = curry2((a, b) => qmergeDeepX(clone(a), clone(b)));
|
package/package.json
CHANGED
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"test": "npm run gentypes && npm run prod:es && ava",
|
|
36
36
|
"test:report": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
37
37
|
"test:lazy": "ava",
|
|
38
|
-
"dts-fix": "node dts-fix.js",
|
|
39
38
|
"gentypes": "dts-bundle-generator --no-check --export-referenced-types=false -o dist/bundle.d.ts src/index.ts",
|
|
40
39
|
"dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
|
|
41
40
|
"prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
|
|
@@ -43,7 +42,7 @@
|
|
|
43
42
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
44
43
|
"all": "npm run dev && npm run prod"
|
|
45
44
|
},
|
|
46
|
-
"version": "1.
|
|
45
|
+
"version": "1.5.3",
|
|
47
46
|
"ava": {
|
|
48
47
|
"files": [
|
|
49
48
|
"./test/specs/*.ts"
|
package/src/safe.ts
CHANGED
|
@@ -131,11 +131,13 @@ export const uniq = (xs: any[]) => qreduce(
|
|
|
131
131
|
[], xs)
|
|
132
132
|
export const intersection = curry2((xs1: any[], xs2: any[]) => xs1.filter(flip(includes)(xs2)))
|
|
133
133
|
export const diff = curry2((_xs1: any[], _xs2: any[]) => {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
const
|
|
134
|
+
// BUG: if _xs1 is empty, results in [undefined, ...]
|
|
135
|
+
let len1 = length(_xs1)
|
|
136
|
+
let len2 = length(_xs2) // xs2 should be shorter 4 Set mem consumption.
|
|
137
|
+
const xs1 = len1>len2 ? _xs1 : _xs2 // ['qwe', 'qwe2'].
|
|
138
|
+
const xs2 = len1>len2 ? _xs2 : _xs1 // [].
|
|
139
|
+
if(len1<=len2) [len1, len2] = [len2, len1]
|
|
140
|
+
const xset2 = new Set(xs2) // empty set.
|
|
139
141
|
const common = new Set()
|
|
140
142
|
const out: any[] = []
|
|
141
143
|
let i: number
|
|
@@ -330,11 +332,23 @@ export const filter = curry2(
|
|
|
330
332
|
? data.filter(cond)
|
|
331
333
|
: qfilter(cond, {...data})
|
|
332
334
|
)
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
/** Saves result of a function with given key and avoids calling it again.
|
|
336
|
+
* @param {(...args: Args) string} keyGen that takes the same args and returns a key for the cache.
|
|
337
|
+
* @param {(...args: Args) any} fn to be cached.
|
|
338
|
+
*/
|
|
339
|
+
export const memoize = curry2(<Args extends any[]>(
|
|
340
|
+
keyGen: (...args: Args) => string,
|
|
341
|
+
fn: AnyFunc<any, Args>
|
|
342
|
+
) => {
|
|
343
|
+
const cache: {[key in string]: ReturnType<typeof fn>} = {}
|
|
344
|
+
return (...args: Args): ReturnType<typeof fn> => {
|
|
345
|
+
const key = keyGen(...args)
|
|
346
|
+
if(key in cache) return cache[key]
|
|
347
|
+
const res = fn(...args)
|
|
348
|
+
cache[key] = res
|
|
349
|
+
return res
|
|
350
|
+
}
|
|
351
|
+
})
|
|
338
352
|
export const mergeShallow = curry2(
|
|
339
353
|
(o1: AnyObject, o2: AnyObject): AnyObject =>
|
|
340
354
|
Object.assign({}, o1, o2)
|