pepka 1.6.4 → 1.6.6
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 +16 -9
- package/dist/bundle.d.ts +24 -18
- package/dist/bundle.mjs +16 -10
- package/package.json +7 -7
- package/src/common.ts +0 -1
- package/src/curry.ts +5 -5
- package/src/quick.ts +6 -3
- package/src/safe.ts +12 -7
- package/src/utils.ts +11 -8
package/dist/bundle.cjs
CHANGED
|
@@ -78,13 +78,14 @@ const undef = undefined;
|
|
|
78
78
|
const nul = null;
|
|
79
79
|
const inf = Infinity;
|
|
80
80
|
const to = (s) => typeof s;
|
|
81
|
-
const isNull = (s) => s === nul;
|
|
82
|
-
const isUndef = (s) => s === undef;
|
|
83
|
-
const isNum = (s) => to(s) == 'number';
|
|
84
|
-
const isArray = (s) => Array.isArray(s);
|
|
85
|
-
|
|
86
|
-
const isStr = (s) => to(s) === 'string';
|
|
87
|
-
const isObj = (s) => !isNull(s) && to(s) === 'object';
|
|
81
|
+
const isNull = (s) => (s === nul);
|
|
82
|
+
const isUndef = (s) => (s === undef);
|
|
83
|
+
const isNum = (s) => (to(s) == 'number');
|
|
84
|
+
const isArray = (s) => (Array.isArray(s));
|
|
85
|
+
function isFunc(s) { return to(s) === 'function'; }
|
|
86
|
+
const isStr = (s) => (to(s) === 'string');
|
|
87
|
+
const isObj = (s) => (!isNull(s) && to(s) === 'object');
|
|
88
|
+
const isNil = (s) => (isNull(s) || isUndef(s));
|
|
88
89
|
|
|
89
90
|
// It's faster that toUpperCase() !
|
|
90
91
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F' };
|
|
@@ -99,7 +100,6 @@ const type = (s) => {
|
|
|
99
100
|
};
|
|
100
101
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
101
102
|
const length = (s) => s.length;
|
|
102
|
-
const isNil = (s) => isNull(s) || isUndef(s);
|
|
103
103
|
const eq = curry2((a, b) => a === b);
|
|
104
104
|
const equals = curry2((a, b) => {
|
|
105
105
|
const typea = type(a);
|
|
@@ -258,6 +258,8 @@ const qstartsWith = qstartsWithWith(eq);
|
|
|
258
258
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
259
259
|
* @returns data with prop over pipe. */
|
|
260
260
|
const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
|
|
261
|
+
// Aliases.
|
|
262
|
+
const qpush = qappend;
|
|
261
263
|
|
|
262
264
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
263
265
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
@@ -281,6 +283,10 @@ const compose = ((...fns) => (...args) => {
|
|
|
281
283
|
});
|
|
282
284
|
const bind = curry2((fn, context) => fn.bind(context));
|
|
283
285
|
const nth = curry2((i, data) => data[i]);
|
|
286
|
+
// FIXME: these types. Somewhere in curry2.
|
|
287
|
+
// const x = nth(0)([1,2,3])
|
|
288
|
+
// const y = nth(0)('123')
|
|
289
|
+
// const z = nth(0)(new Uint8Array([0,2,3]))
|
|
284
290
|
const slice = curry3((from, to, o) => o.slice(from, (isNum(to) ? to : inf)));
|
|
285
291
|
const flip = (fn) => curry2((b, a) => fn(a, b));
|
|
286
292
|
/** @returns first element of an array or a string. */
|
|
@@ -417,7 +423,7 @@ const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
|
417
423
|
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
418
424
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
419
425
|
const prop = curry2((key, o) => o[key]);
|
|
420
|
-
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
426
|
+
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
421
427
|
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
422
428
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
423
429
|
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
@@ -761,6 +767,7 @@ exports.qmergeShallow = qmergeShallow;
|
|
|
761
767
|
exports.qomit = qomit;
|
|
762
768
|
exports.qoverProp = qoverProp;
|
|
763
769
|
exports.qprepend = qprepend;
|
|
770
|
+
exports.qpush = qpush;
|
|
764
771
|
exports.qreduce = qreduce;
|
|
765
772
|
exports.qreverse = qreverse;
|
|
766
773
|
exports.qsort = qsort;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -44,7 +44,6 @@ export declare const typeIs: {
|
|
|
44
44
|
(a: string, b: any): boolean;
|
|
45
45
|
};
|
|
46
46
|
declare const length$1: <T extends AnyArray | string>(s: T) => T extends string ? StrLen<T> : T["length"];
|
|
47
|
-
export declare const isNil: (s: any) => boolean;
|
|
48
47
|
export declare const eq: {
|
|
49
48
|
(a: symbol, b: any): (a: any) => boolean;
|
|
50
49
|
(a: any, b: symbol): (b: any) => boolean;
|
|
@@ -70,6 +69,7 @@ export declare const qstartsWithWith: (comparator: (x: any, y: any) => boolean)
|
|
|
70
69
|
(a: string | any[]): (b: string | any[]) => boolean;
|
|
71
70
|
(a: string | any[], b: string | any[]): boolean;
|
|
72
71
|
};
|
|
72
|
+
export declare const isNil: <T extends any>(s: T) => T extends (null | undefined) ? true : false;
|
|
73
73
|
export declare const take: (argN: number) => (...args: any[]) => any;
|
|
74
74
|
export declare const ifElse: (...args: AnyArgs) => any;
|
|
75
75
|
export declare const when: (...args: AnyArgs) => any;
|
|
@@ -82,10 +82,10 @@ export declare const bind: {
|
|
|
82
82
|
(a: any, b: any): any;
|
|
83
83
|
};
|
|
84
84
|
export declare const nth: {
|
|
85
|
-
(a: symbol, b: string |
|
|
86
|
-
(a: number, b: symbol): (b: string |
|
|
87
|
-
(a: number): (b: string |
|
|
88
|
-
(a: number, b: string |
|
|
85
|
+
(a: symbol, b: string | ArrayLike<unknown>): (a: number) => unknown;
|
|
86
|
+
(a: number, b: symbol): (b: string | ArrayLike<unknown>) => unknown;
|
|
87
|
+
(a: number): (b: string | ArrayLike<unknown>) => unknown;
|
|
88
|
+
(a: number, b: string | ArrayLike<unknown>): unknown;
|
|
89
89
|
};
|
|
90
90
|
export declare const slice: (...args: AnyArgs) => any;
|
|
91
91
|
export declare const flip: <T extends AnyFunc>(fn: T) => {
|
|
@@ -382,7 +382,7 @@ export declare const prop: {
|
|
|
382
382
|
(a: string): (b: AnyObject) => any;
|
|
383
383
|
(a: string, b: AnyObject): any;
|
|
384
384
|
};
|
|
385
|
-
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
385
|
+
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
386
386
|
export declare const propEq: (...args: AnyArgs) => any;
|
|
387
387
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
388
388
|
export declare const propsEq: (...args: AnyArgs) => any;
|
|
@@ -414,10 +414,10 @@ export declare const pickBy: {
|
|
|
414
414
|
(a: Cond, b: AnyObject): any;
|
|
415
415
|
};
|
|
416
416
|
export declare const omit: {
|
|
417
|
-
(a: symbol, b: AnyObject): (a: string[]) => any
|
|
418
|
-
(a: string[], b: symbol): (b: AnyObject) => any
|
|
419
|
-
(a: string[]): (b: AnyObject) => any
|
|
420
|
-
(a: string[], b: AnyObject): any
|
|
417
|
+
(a: symbol, b: AnyObject): (a: string[]) => any;
|
|
418
|
+
(a: string[], b: symbol): (b: AnyObject) => any;
|
|
419
|
+
(a: string[]): (b: AnyObject) => any;
|
|
420
|
+
(a: string[], b: AnyObject): any;
|
|
421
421
|
};
|
|
422
422
|
export declare const fromPairs: (pairs: [
|
|
423
423
|
string,
|
|
@@ -450,20 +450,20 @@ export declare const join: {
|
|
|
450
450
|
(a: string, b: string[]): string;
|
|
451
451
|
};
|
|
452
452
|
export declare const forEach: {
|
|
453
|
-
(a: symbol, b: any[]): (a: (s:
|
|
454
|
-
(a: (s:
|
|
455
|
-
(a: (s:
|
|
456
|
-
(a: (s:
|
|
453
|
+
(a: symbol, b: any[]): (a: (s: unknown, i: number, arr: unknown[]) => any) => void;
|
|
454
|
+
(a: (s: unknown, i: number, arr: unknown[]) => any, b: symbol): (b: any[]) => void;
|
|
455
|
+
(a: (s: unknown, i: number, arr: unknown[]) => any): (b: any[]) => void;
|
|
456
|
+
(a: (s: unknown, i: number, arr: unknown[]) => any, b: any[]): void;
|
|
457
457
|
};
|
|
458
458
|
export declare const both: (...args: AnyArgs) => any;
|
|
459
459
|
export declare const isEmpty: (s: any) => boolean | null;
|
|
460
460
|
export declare const empty: (s: any) => {} | undefined;
|
|
461
461
|
export declare const replace: (...args: AnyArgs) => any;
|
|
462
462
|
export declare const filter: {
|
|
463
|
-
(a: symbol, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any
|
|
464
|
-
(a: (v: any, k: string | number) => boolean, b: symbol): (b: any[] | AnyObject) => any
|
|
465
|
-
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any
|
|
466
|
-
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any
|
|
463
|
+
(a: symbol, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any;
|
|
464
|
+
(a: (v: any, k: string | number) => boolean, b: symbol): (b: any[] | AnyObject) => any;
|
|
465
|
+
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any;
|
|
466
|
+
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any;
|
|
467
467
|
};
|
|
468
468
|
/** Saves result of a function with given key and avoids calling it again.
|
|
469
469
|
* @param {(...args: Args) string} keyGen that takes the same args and returns a key for the cache.
|
|
@@ -656,6 +656,12 @@ export declare const qstartsWith: {
|
|
|
656
656
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
657
657
|
* @returns data with prop over pipe. */
|
|
658
658
|
export declare const qoverProp: (...args: AnyArgs) => any;
|
|
659
|
+
export declare const qpush: {
|
|
660
|
+
(a: symbol, b: any[]): (a: any) => any[];
|
|
661
|
+
(a: any, b: symbol): (b: any[]) => any[];
|
|
662
|
+
(a: any): (b: any[]) => any[];
|
|
663
|
+
(a: any, b: any[]): any[];
|
|
664
|
+
};
|
|
659
665
|
type StrTmpl = ((data: AnyObject) => string);
|
|
660
666
|
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
661
667
|
@returns getTmpl('one{meme}two')({meme: 42}) -> one42two */
|
package/dist/bundle.mjs
CHANGED
|
@@ -76,13 +76,14 @@ const undef = undefined;
|
|
|
76
76
|
const nul = null;
|
|
77
77
|
const inf = Infinity;
|
|
78
78
|
const to = (s) => typeof s;
|
|
79
|
-
const isNull = (s) => s === nul;
|
|
80
|
-
const isUndef = (s) => s === undef;
|
|
81
|
-
const isNum = (s) => to(s) == 'number';
|
|
82
|
-
const isArray = (s) => Array.isArray(s);
|
|
83
|
-
|
|
84
|
-
const isStr = (s) => to(s) === 'string';
|
|
85
|
-
const isObj = (s) => !isNull(s) && to(s) === 'object';
|
|
79
|
+
const isNull = (s) => (s === nul);
|
|
80
|
+
const isUndef = (s) => (s === undef);
|
|
81
|
+
const isNum = (s) => (to(s) == 'number');
|
|
82
|
+
const isArray = (s) => (Array.isArray(s));
|
|
83
|
+
function isFunc(s) { return to(s) === 'function'; }
|
|
84
|
+
const isStr = (s) => (to(s) === 'string');
|
|
85
|
+
const isObj = (s) => (!isNull(s) && to(s) === 'object');
|
|
86
|
+
const isNil = (s) => (isNull(s) || isUndef(s));
|
|
86
87
|
|
|
87
88
|
// It's faster that toUpperCase() !
|
|
88
89
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F' };
|
|
@@ -97,7 +98,6 @@ const type = (s) => {
|
|
|
97
98
|
};
|
|
98
99
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
99
100
|
const length = (s) => s.length;
|
|
100
|
-
const isNil = (s) => isNull(s) || isUndef(s);
|
|
101
101
|
const eq = curry2((a, b) => a === b);
|
|
102
102
|
const equals = curry2((a, b) => {
|
|
103
103
|
const typea = type(a);
|
|
@@ -256,6 +256,8 @@ const qstartsWith = qstartsWithWith(eq);
|
|
|
256
256
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
257
257
|
* @returns data with prop over pipe. */
|
|
258
258
|
const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
|
|
259
|
+
// Aliases.
|
|
260
|
+
const qpush = qappend;
|
|
259
261
|
|
|
260
262
|
// TODO: possibly introduce a second argument limiting unfolding.
|
|
261
263
|
const uncurry = (fn) => (...args) => qreduce(((fn, arg) => fn ? fn(arg) : fn), fn, args);
|
|
@@ -279,6 +281,10 @@ const compose = ((...fns) => (...args) => {
|
|
|
279
281
|
});
|
|
280
282
|
const bind = curry2((fn, context) => fn.bind(context));
|
|
281
283
|
const nth = curry2((i, data) => data[i]);
|
|
284
|
+
// FIXME: these types. Somewhere in curry2.
|
|
285
|
+
// const x = nth(0)([1,2,3])
|
|
286
|
+
// const y = nth(0)('123')
|
|
287
|
+
// const z = nth(0)(new Uint8Array([0,2,3]))
|
|
282
288
|
const slice = curry3((from, to, o) => o.slice(from, (isNum(to) ? to : inf)));
|
|
283
289
|
const flip = (fn) => curry2((b, a) => fn(a, b));
|
|
284
290
|
/** @returns first element of an array or a string. */
|
|
@@ -415,7 +421,7 @@ const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
|
415
421
|
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
416
422
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
417
423
|
const prop = curry2((key, o) => o[key]);
|
|
418
|
-
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
424
|
+
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
419
425
|
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
420
426
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
421
427
|
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
@@ -648,4 +654,4 @@ const composeAsync = (() => {
|
|
|
648
654
|
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
649
655
|
})();
|
|
650
656
|
|
|
651
|
-
export { F, 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, forEachAsync, 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, qfreeze, qfreezeShallow, qmap, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qmergeShallow, qomit, qoverProp, qprepend, qreduce, qreverse, qsort, qstartsWith, qstartsWithWith, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, subtract, symbol, tail, take, tap, test, throttle, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
|
|
657
|
+
export { F, 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, forEachAsync, 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, qfreeze, qfreezeShallow, qmap, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qmergeShallow, qomit, qoverProp, qprepend, qpush, qreduce, qreverse, qsort, qstartsWith, qstartsWithWith, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, subtract, symbol, tail, take, tap, test, throttle, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
|
package/package.json
CHANGED
|
@@ -41,19 +41,19 @@
|
|
|
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.6.
|
|
44
|
+
"version": "1.6.6",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
47
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
46
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
48
48
|
"@rollup/plugin-replace": "^6.0.2",
|
|
49
|
-
"@types/node": "^
|
|
50
|
-
"cross-env": "^
|
|
49
|
+
"@types/node": "^24.1.0",
|
|
50
|
+
"cross-env": "^10.0.0",
|
|
51
51
|
"dts-bundle-generator": "^9.5.1",
|
|
52
|
-
"rollup": "^4.
|
|
52
|
+
"rollup": "^4.46.0",
|
|
53
53
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
54
54
|
"ts-node": "^10.9.2",
|
|
55
55
|
"tslint": "^6.1.3",
|
|
56
|
-
"typescript": "^5.8.
|
|
56
|
+
"typescript": "^5.8.3"
|
|
57
57
|
},
|
|
58
58
|
"sideEffects": false
|
|
59
59
|
}
|
package/src/common.ts
CHANGED
|
@@ -18,7 +18,6 @@ export const type = (s: any): string => {
|
|
|
18
18
|
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
|
19
19
|
|
|
20
20
|
export const length = <T extends AnyArray | string>(s: T): T extends string ? StrLen<T> : T["length"] => s.length as any
|
|
21
|
-
export const isNil = (s: any) => isNull(s) || isUndef(s)
|
|
22
21
|
export const eq = curry2((a: any, b: any) => a===b)
|
|
23
22
|
export const equals = curry2((a: any, b: any) => {
|
|
24
23
|
const typea = type(a)
|
package/src/curry.ts
CHANGED
|
@@ -65,11 +65,11 @@ export function curry2<Func extends Func2>(fn: Func) {
|
|
|
65
65
|
type p0 = Parameters<Func>[0]
|
|
66
66
|
type p1 = Parameters<Func>[1]
|
|
67
67
|
type ReturnT = ReturnType<Func>
|
|
68
|
-
function curried2(
|
|
69
|
-
function curried2(
|
|
70
|
-
function curried2(
|
|
71
|
-
function curried2(
|
|
72
|
-
function curried2(
|
|
68
|
+
function curried2(a: Placeholder, b: p1): (a: p0) => ReturnT
|
|
69
|
+
function curried2(a: p0, b: Placeholder): (b: p1) => ReturnT
|
|
70
|
+
function curried2(a: p0 ): (b: p1) => ReturnT
|
|
71
|
+
function curried2(a: p0, b: p1): ReturnT
|
|
72
|
+
function curried2(a: p0 | Placeholder, b?: p1) {
|
|
73
73
|
const withPlaceholder1 = a===__
|
|
74
74
|
const aln = arguments.length
|
|
75
75
|
if(aln === 1 && withPlaceholder1)
|
package/src/quick.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { curry2, curry3 } from "./curry"
|
|
2
|
-
import { includes,
|
|
2
|
+
import { includes, type, eq, qstartsWithWith } from "./common"
|
|
3
3
|
import { AnyObject, Reducer, AnyFunc } from "./types"
|
|
4
|
-
import { isFunc, isArray, isObj } from "./utils"
|
|
4
|
+
import { isFunc, isArray, isObj, isNil } from "./utils"
|
|
5
5
|
/* Then next fns seem to be excess due to their safe ver performance should be the same or better:
|
|
6
6
|
* qflat, qpick
|
|
7
7
|
*/
|
|
@@ -132,4 +132,7 @@ export const qstartsWith = qstartsWithWith(eq)
|
|
|
132
132
|
* @returns data with prop over pipe. */
|
|
133
133
|
export const qoverProp = curry3(
|
|
134
134
|
(prop: string, pipe: AnyFunc, data: any) => qassoc(prop, pipe(data[prop]), data)
|
|
135
|
-
)
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
// Aliases.
|
|
138
|
+
export const qpush = qappend
|
package/src/safe.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __, curry, curry2, curry3 } from './curry'
|
|
2
|
-
import { isNum, undef, isArray, isFunc, isObj, inf } from './utils'
|
|
3
|
-
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj
|
|
2
|
+
import { isNum, undef, isArray, isFunc, isObj, inf, isNil } from './utils'
|
|
3
|
+
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj } from './quick'
|
|
4
4
|
import { AnyFunc, Cond, AnyObject, Reducer } from './types'
|
|
5
|
-
import { symbol, type, length, equals, includes,
|
|
5
|
+
import { symbol, type, length, equals, includes, qstartsWithWith, eq } from './common'
|
|
6
6
|
import { Split, AnyArray, IndexesOfArray } from './internal_types'
|
|
7
7
|
import { is_typed_arr } from './internal'
|
|
8
8
|
// TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
|
|
@@ -40,7 +40,11 @@ export const compose = (
|
|
|
40
40
|
}
|
|
41
41
|
)
|
|
42
42
|
export const bind = curry2<AnyFunc>((fn: AnyFunc, context: any) => fn.bind(context))
|
|
43
|
-
export const nth = curry2((i: number, data:
|
|
43
|
+
export const nth = curry2(<T extends any>(i: number, data: string | ArrayLike<T>) => data[i])
|
|
44
|
+
// FIXME: these types. Somewhere in curry2.
|
|
45
|
+
// const x = nth(0)([1,2,3])
|
|
46
|
+
// const y = nth(0)('123')
|
|
47
|
+
// const z = nth(0)(new Uint8Array([0,2,3]))
|
|
44
48
|
export const slice = curry3(
|
|
45
49
|
(from: number, to: number, o: any[] | string) =>
|
|
46
50
|
o.slice(from, (isNum(to)?to:inf) as number)
|
|
@@ -234,7 +238,7 @@ export const allPass = curry2((preds: Cond[], x: any) => preds.every((pred) => p
|
|
|
234
238
|
export const anyPass = curry2((preds: Cond[], x: any) => preds.some((pred) => pred(x)))
|
|
235
239
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
236
240
|
export const prop = curry2((key: string, o: AnyObject) => o[key])
|
|
237
|
-
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
241
|
+
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
238
242
|
export const propEq = curry3(
|
|
239
243
|
(key: string, value: any, o: AnyObject) => equals(o[key], value)
|
|
240
244
|
)
|
|
@@ -320,7 +324,7 @@ export const mapObj = curry2(
|
|
|
320
324
|
(pipe: (s: any, i?: string, list?: any[]) => any, o: AnyObject) => qmapObj(pipe, {...o})
|
|
321
325
|
)
|
|
322
326
|
export const join = curry2((delimeter: string, arr: string[]) => arr.join(delimeter))
|
|
323
|
-
export const forEach = curry2((pipe: (s:
|
|
327
|
+
export const forEach = curry2(<T extends any>(pipe: (s: T, i: number, arr: T[]) => any, arr: any[]) => arr.forEach(pipe))
|
|
324
328
|
export const both = curry3((cond1: Cond, cond2: Cond, s: any) => cond2(s) && cond1(s))
|
|
325
329
|
export const isEmpty = (s: any) => {
|
|
326
330
|
switch(type(s)) {
|
|
@@ -418,7 +422,8 @@ export const zipWith = curry3(
|
|
|
418
422
|
)
|
|
419
423
|
|
|
420
424
|
// Reexport safe stuff that is ready to use externally.
|
|
421
|
-
export { toLower, toUpper, type, typeIs, length,
|
|
425
|
+
export { toLower, toUpper, type, typeIs, length, eq, equals, includes } from './common'
|
|
426
|
+
export { isNil } from './utils'
|
|
422
427
|
|
|
423
428
|
// ALIASES
|
|
424
429
|
export const mirror = identity
|
package/src/utils.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { AnyFunc, AnyObject } from "./types"
|
|
2
2
|
|
|
3
3
|
export const undef = undefined
|
|
4
4
|
export const nul = null
|
|
5
5
|
export const inf = Infinity
|
|
6
6
|
export const to = (s: any) => typeof s
|
|
7
|
-
export const isNull = (s:
|
|
8
|
-
export const isUndef = (s:
|
|
9
|
-
export const isNum = (s:
|
|
10
|
-
export const isArray = (s:
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
7
|
+
export const isNull = <T extends any>(s: T) => (s===nul) as T extends null ? true : false
|
|
8
|
+
export const isUndef = <T extends any>(s: T) => (s===undef) as T extends undefined ? true : false
|
|
9
|
+
export const isNum = <T extends any>(s: T) => (to(s)=='number') as T extends number ? true : false
|
|
10
|
+
export const isArray = <T extends any>(s: T) => (Array.isArray(s)) as T extends any[] ? true : false
|
|
11
|
+
export function isFunc<T extends AnyFunc>(value: T): true
|
|
12
|
+
export function isFunc(value: any): false
|
|
13
|
+
export function isFunc(s: any) { return to(s)==='function' }
|
|
14
|
+
export const isStr = <T extends any>(s: T) => (to(s)==='string') as T extends string ? true : false
|
|
15
|
+
export const isObj = <T extends any>(s: T) => (!isNull(s) && to(s)==='object') as T extends AnyObject ? true : false
|
|
16
|
+
export const isNil = <T extends any>(s: T) => (isNull(s) || isUndef(s)) as T extends (null|undefined) ? true : false
|