pepka 1.6.3 → 1.6.5
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 +22 -14
- package/dist/bundle.d.ts +28 -22
- package/dist/bundle.mjs +22 -15
- package/package.json +8 -7
- package/src/common.ts +2 -2
- package/src/curry.ts +5 -5
- package/src/internal.ts +2 -0
- package/src/quick.ts +2 -2
- package/src/safe.ts +13 -8
- package/src/utils.ts +11 -8
package/dist/bundle.cjs
CHANGED
|
@@ -71,17 +71,21 @@ function curry3(fn) {
|
|
|
71
71
|
return curry(fn);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
75
|
+
const is_typed_arr = (t) => typed_arr_re.test(t);
|
|
76
|
+
|
|
74
77
|
const undef = undefined;
|
|
75
78
|
const nul = null;
|
|
76
79
|
const inf = Infinity;
|
|
77
80
|
const to = (s) => typeof s;
|
|
78
|
-
const isNull = (s) => s === nul;
|
|
79
|
-
const isUndef = (s) => s === undef;
|
|
80
|
-
const isNum = (s) => to(s) == 'number';
|
|
81
|
-
const isArray = (s) => Array.isArray(s);
|
|
82
|
-
|
|
83
|
-
const isStr = (s) => to(s) === 'string';
|
|
84
|
-
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));
|
|
85
89
|
|
|
86
90
|
// It's faster that toUpperCase() !
|
|
87
91
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F' };
|
|
@@ -96,11 +100,10 @@ const type = (s) => {
|
|
|
96
100
|
};
|
|
97
101
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
98
102
|
const length = (s) => s.length;
|
|
99
|
-
const isNil = (s) => isNull(s) || isUndef(s);
|
|
100
103
|
const eq = curry2((a, b) => a === b);
|
|
101
104
|
const equals = curry2((a, b) => {
|
|
102
105
|
const typea = type(a);
|
|
103
|
-
if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array'))) {
|
|
106
|
+
if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
|
|
104
107
|
if (isNull(a) || isNull(b))
|
|
105
108
|
return eq(a, b);
|
|
106
109
|
if (eq(a, b))
|
|
@@ -241,6 +244,7 @@ const qfreeze = (o) => {
|
|
|
241
244
|
};
|
|
242
245
|
const qfreezeShallow = (o) => Object.freeze(o);
|
|
243
246
|
const qprepend = curry2((x, xs) => xs.unshift(x));
|
|
247
|
+
const qsort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
244
248
|
const qassocPath = curry3((_path, v, o) => {
|
|
245
249
|
const first = _path[0];
|
|
246
250
|
return qassoc(first, _path.length < 2
|
|
@@ -277,6 +281,10 @@ const compose = ((...fns) => (...args) => {
|
|
|
277
281
|
});
|
|
278
282
|
const bind = curry2((fn, context) => fn.bind(context));
|
|
279
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]))
|
|
280
288
|
const slice = curry3((from, to, o) => o.slice(from, (isNum(to) ? to : inf)));
|
|
281
289
|
const flip = (fn) => curry2((b, a) => fn(a, b));
|
|
282
290
|
/** @returns first element of an array or a string. */
|
|
@@ -301,7 +309,7 @@ const lt = curry2((a, b) => a > b);
|
|
|
301
309
|
const gte = curry2((a, b) => a <= b);
|
|
302
310
|
/** @param a @param b @returns a≥b */
|
|
303
311
|
const lte = curry2((a, b) => a >= b);
|
|
304
|
-
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
312
|
+
const sort = curry2((sortFn, xs) => [...xs].sort(sortFn));
|
|
305
313
|
const find = curry2((fn, s) => s.find(fn));
|
|
306
314
|
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
307
315
|
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
@@ -413,7 +421,7 @@ const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
|
413
421
|
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
414
422
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
415
423
|
const prop = curry2((key, o) => o[key]);
|
|
416
|
-
/** @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 */
|
|
417
425
|
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
418
426
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
419
427
|
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
@@ -426,7 +434,6 @@ const path = pathOr(undef);
|
|
|
426
434
|
const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
|
|
427
435
|
const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
|
|
428
436
|
const pathExists = compose(ifElse(equals(symbol), F, T), pathOr(symbol));
|
|
429
|
-
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
430
437
|
const clone = (s, shallow = false) => {
|
|
431
438
|
const t = type(s);
|
|
432
439
|
switch (t) {
|
|
@@ -445,7 +452,7 @@ const clone = (s, shallow = false) => {
|
|
|
445
452
|
case 'Symbol':
|
|
446
453
|
return s;
|
|
447
454
|
default:
|
|
448
|
-
return
|
|
455
|
+
return is_typed_arr(t) ? s.constructor.from(s) : s;
|
|
449
456
|
}
|
|
450
457
|
};
|
|
451
458
|
const cloneShallow = (s) => clone(s, true);
|
|
@@ -469,7 +476,7 @@ const omit = curry2((props, o) => filter((_, k) => !includes(k, props), o));
|
|
|
469
476
|
const fromPairs = (pairs) => Object.fromEntries(pairs);
|
|
470
477
|
const concat = curry2(((a, b) => b.concat(a)));
|
|
471
478
|
const map = curry2((pipe, arr) => arr.map(pipe));
|
|
472
|
-
const mapObj = curry2((pipe, o) => qmapObj(pipe,
|
|
479
|
+
const mapObj = curry2((pipe, o) => qmapObj(pipe, { ...o }));
|
|
473
480
|
const join = curry2((delimeter, arr) => arr.join(delimeter));
|
|
474
481
|
const forEach = curry2((pipe, arr) => arr.forEach(pipe));
|
|
475
482
|
const both = curry3((cond1, cond2, s) => cond2(s) && cond1(s));
|
|
@@ -760,6 +767,7 @@ exports.qoverProp = qoverProp;
|
|
|
760
767
|
exports.qprepend = qprepend;
|
|
761
768
|
exports.qreduce = qreduce;
|
|
762
769
|
exports.qreverse = qreverse;
|
|
770
|
+
exports.qsort = qsort;
|
|
763
771
|
exports.qstartsWith = qstartsWith;
|
|
764
772
|
exports.qstartsWithWith = qstartsWithWith;
|
|
765
773
|
exports.range = range;
|
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) => {
|
|
@@ -180,10 +180,10 @@ export declare const lte: {
|
|
|
180
180
|
(a: number, b: number): boolean;
|
|
181
181
|
};
|
|
182
182
|
export declare const sort: {
|
|
183
|
-
(a: symbol, b:
|
|
184
|
-
(a: (a:
|
|
185
|
-
(a: (a:
|
|
186
|
-
(a: (a:
|
|
183
|
+
(a: symbol, b: unknown[]): (a: (a: unknown, b: unknown) => number) => unknown[];
|
|
184
|
+
(a: (a: unknown, b: unknown) => number, b: symbol): (b: unknown[]) => unknown[];
|
|
185
|
+
(a: (a: unknown, b: unknown) => number): (b: unknown[]) => unknown[];
|
|
186
|
+
(a: (a: unknown, b: unknown) => number, b: unknown[]): unknown[];
|
|
187
187
|
};
|
|
188
188
|
export declare const find: {
|
|
189
189
|
(a: symbol, b: any[]): (a: Cond) => any;
|
|
@@ -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,
|
|
@@ -438,10 +438,10 @@ export declare const map: {
|
|
|
438
438
|
(a: (s: any, i?: number, list?: any[]) => any, b: any[]): any[];
|
|
439
439
|
};
|
|
440
440
|
export declare const mapObj: {
|
|
441
|
-
(a: symbol, b: AnyObject): (a: (s: any, i?: string, list?: any[]) => any) =>
|
|
442
|
-
(a: (s: any, i?: string, list?: any[]) => any, b: symbol): (b: AnyObject) =>
|
|
443
|
-
(a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) =>
|
|
444
|
-
(a: (s: any, i?: string, list?: any[]) => any, b: AnyObject):
|
|
441
|
+
(a: symbol, b: AnyObject): (a: (s: any, i?: string, list?: any[]) => any) => AnyObject;
|
|
442
|
+
(a: (s: any, i?: string, list?: any[]) => any, b: symbol): (b: AnyObject) => AnyObject;
|
|
443
|
+
(a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) => AnyObject;
|
|
444
|
+
(a: (s: any, i?: string, list?: any[]) => any, b: AnyObject): AnyObject;
|
|
445
445
|
};
|
|
446
446
|
export declare const join: {
|
|
447
447
|
(a: symbol, b: string[]): (a: string) => string;
|
|
@@ -460,10 +460,10 @@ 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.
|
|
@@ -632,6 +632,12 @@ export declare const qprepend: {
|
|
|
632
632
|
(a: any): (b: any[]) => number;
|
|
633
633
|
(a: any, b: any[]): number;
|
|
634
634
|
};
|
|
635
|
+
export declare const qsort: {
|
|
636
|
+
(a: symbol, b: any[]): (a: (a: any, b: any) => number) => any[];
|
|
637
|
+
(a: (a: any, b: any) => number, b: symbol): (b: any[]) => any[];
|
|
638
|
+
(a: (a: any, b: any) => number): (b: any[]) => any[];
|
|
639
|
+
(a: (a: any, b: any) => number, b: any[]): any[];
|
|
640
|
+
};
|
|
635
641
|
export declare const qassocPath: (...args: AnyArgs) => any;
|
|
636
642
|
export declare const qreverse: (arr: any[]) => any[];
|
|
637
643
|
export declare const qomit: {
|
package/dist/bundle.mjs
CHANGED
|
@@ -69,17 +69,21 @@ function curry3(fn) {
|
|
|
69
69
|
return curry(fn);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
73
|
+
const is_typed_arr = (t) => typed_arr_re.test(t);
|
|
74
|
+
|
|
72
75
|
const undef = undefined;
|
|
73
76
|
const nul = null;
|
|
74
77
|
const inf = Infinity;
|
|
75
78
|
const to = (s) => typeof s;
|
|
76
|
-
const isNull = (s) => s === nul;
|
|
77
|
-
const isUndef = (s) => s === undef;
|
|
78
|
-
const isNum = (s) => to(s) == 'number';
|
|
79
|
-
const isArray = (s) => Array.isArray(s);
|
|
80
|
-
|
|
81
|
-
const isStr = (s) => to(s) === 'string';
|
|
82
|
-
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));
|
|
83
87
|
|
|
84
88
|
// It's faster that toUpperCase() !
|
|
85
89
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F' };
|
|
@@ -94,11 +98,10 @@ const type = (s) => {
|
|
|
94
98
|
};
|
|
95
99
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
96
100
|
const length = (s) => s.length;
|
|
97
|
-
const isNil = (s) => isNull(s) || isUndef(s);
|
|
98
101
|
const eq = curry2((a, b) => a === b);
|
|
99
102
|
const equals = curry2((a, b) => {
|
|
100
103
|
const typea = type(a);
|
|
101
|
-
if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array'))) {
|
|
104
|
+
if (eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
|
|
102
105
|
if (isNull(a) || isNull(b))
|
|
103
106
|
return eq(a, b);
|
|
104
107
|
if (eq(a, b))
|
|
@@ -239,6 +242,7 @@ const qfreeze = (o) => {
|
|
|
239
242
|
};
|
|
240
243
|
const qfreezeShallow = (o) => Object.freeze(o);
|
|
241
244
|
const qprepend = curry2((x, xs) => xs.unshift(x));
|
|
245
|
+
const qsort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
242
246
|
const qassocPath = curry3((_path, v, o) => {
|
|
243
247
|
const first = _path[0];
|
|
244
248
|
return qassoc(first, _path.length < 2
|
|
@@ -275,6 +279,10 @@ const compose = ((...fns) => (...args) => {
|
|
|
275
279
|
});
|
|
276
280
|
const bind = curry2((fn, context) => fn.bind(context));
|
|
277
281
|
const nth = curry2((i, data) => data[i]);
|
|
282
|
+
// FIXME: these types. Somewhere in curry2.
|
|
283
|
+
// const x = nth(0)([1,2,3])
|
|
284
|
+
// const y = nth(0)('123')
|
|
285
|
+
// const z = nth(0)(new Uint8Array([0,2,3]))
|
|
278
286
|
const slice = curry3((from, to, o) => o.slice(from, (isNum(to) ? to : inf)));
|
|
279
287
|
const flip = (fn) => curry2((b, a) => fn(a, b));
|
|
280
288
|
/** @returns first element of an array or a string. */
|
|
@@ -299,7 +307,7 @@ const lt = curry2((a, b) => a > b);
|
|
|
299
307
|
const gte = curry2((a, b) => a <= b);
|
|
300
308
|
/** @param a @param b @returns a≥b */
|
|
301
309
|
const lte = curry2((a, b) => a >= b);
|
|
302
|
-
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
310
|
+
const sort = curry2((sortFn, xs) => [...xs].sort(sortFn));
|
|
303
311
|
const find = curry2((fn, s) => s.find(fn));
|
|
304
312
|
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
305
313
|
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
@@ -411,7 +419,7 @@ const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
|
411
419
|
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
412
420
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
413
421
|
const prop = curry2((key, o) => o[key]);
|
|
414
|
-
/** @param key string @param value any @param o AnyObject @returns o[key] equals value */
|
|
422
|
+
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
415
423
|
const propEq = curry3((key, value, o) => equals(o[key], value));
|
|
416
424
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
417
425
|
const propsEq = curry3((key, o1, o2) => equals(o1[key], o2[key]));
|
|
@@ -424,7 +432,6 @@ const path = pathOr(undef);
|
|
|
424
432
|
const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
|
|
425
433
|
const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
|
|
426
434
|
const pathExists = compose(ifElse(equals(symbol), F, T), pathOr(symbol));
|
|
427
|
-
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
428
435
|
const clone = (s, shallow = false) => {
|
|
429
436
|
const t = type(s);
|
|
430
437
|
switch (t) {
|
|
@@ -443,7 +450,7 @@ const clone = (s, shallow = false) => {
|
|
|
443
450
|
case 'Symbol':
|
|
444
451
|
return s;
|
|
445
452
|
default:
|
|
446
|
-
return
|
|
453
|
+
return is_typed_arr(t) ? s.constructor.from(s) : s;
|
|
447
454
|
}
|
|
448
455
|
};
|
|
449
456
|
const cloneShallow = (s) => clone(s, true);
|
|
@@ -467,7 +474,7 @@ const omit = curry2((props, o) => filter((_, k) => !includes(k, props), o));
|
|
|
467
474
|
const fromPairs = (pairs) => Object.fromEntries(pairs);
|
|
468
475
|
const concat = curry2(((a, b) => b.concat(a)));
|
|
469
476
|
const map = curry2((pipe, arr) => arr.map(pipe));
|
|
470
|
-
const mapObj = curry2((pipe, o) => qmapObj(pipe,
|
|
477
|
+
const mapObj = curry2((pipe, o) => qmapObj(pipe, { ...o }));
|
|
471
478
|
const join = curry2((delimeter, arr) => arr.join(delimeter));
|
|
472
479
|
const forEach = curry2((pipe, arr) => arr.forEach(pipe));
|
|
473
480
|
const both = curry3((cond1, cond2, s) => cond2(s) && cond1(s));
|
|
@@ -645,4 +652,4 @@ const composeAsync = (() => {
|
|
|
645
652
|
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
646
653
|
})();
|
|
647
654
|
|
|
648
|
-
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, 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 };
|
|
655
|
+
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 };
|
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"ramda",
|
|
13
13
|
"functional",
|
|
14
14
|
"fp",
|
|
15
|
+
"toolkit",
|
|
15
16
|
"pure",
|
|
16
17
|
"strongly-typed",
|
|
17
18
|
"typescript",
|
|
@@ -40,19 +41,19 @@
|
|
|
40
41
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
41
42
|
"all": "npm run dev && npm run prod"
|
|
42
43
|
},
|
|
43
|
-
"version": "1.6.
|
|
44
|
+
"version": "1.6.5",
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
46
|
-
"@rollup/plugin-node-resolve": "^16.0.
|
|
46
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
47
48
|
"@rollup/plugin-replace": "^6.0.2",
|
|
48
|
-
"@types/node": "^
|
|
49
|
-
"cross-env": "^
|
|
49
|
+
"@types/node": "^24.1.0",
|
|
50
|
+
"cross-env": "^10.0.0",
|
|
50
51
|
"dts-bundle-generator": "^9.5.1",
|
|
51
|
-
"rollup": "^4.
|
|
52
|
+
"rollup": "^4.46.0",
|
|
52
53
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
53
54
|
"ts-node": "^10.9.2",
|
|
54
55
|
"tslint": "^6.1.3",
|
|
55
|
-
"typescript": "^5.8.
|
|
56
|
+
"typescript": "^5.8.3"
|
|
56
57
|
},
|
|
57
58
|
"sideEffects": false
|
|
58
59
|
}
|
package/src/common.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { curry2 } from "./curry"
|
|
2
|
+
import { is_typed_arr } from "./internal"
|
|
2
3
|
import { AnyArray, StrLen } from "./internal_types"
|
|
3
4
|
import { to, isNull, isStr, isUndef } from "./utils"
|
|
4
5
|
|
|
@@ -17,11 +18,10 @@ export const type = (s: any): string => {
|
|
|
17
18
|
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
|
18
19
|
|
|
19
20
|
export const length = <T extends AnyArray | string>(s: T): T extends string ? StrLen<T> : T["length"] => s.length as any
|
|
20
|
-
export const isNil = (s: any) => isNull(s) || isUndef(s)
|
|
21
21
|
export const eq = curry2((a: any, b: any) => a===b)
|
|
22
22
|
export const equals = curry2((a: any, b: any) => {
|
|
23
23
|
const typea = type(a)
|
|
24
|
-
if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array'))) {
|
|
24
|
+
if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
|
|
25
25
|
if(isNull(a) || isNull(b)) return eq(a, b)
|
|
26
26
|
if(eq(a, b)) return true
|
|
27
27
|
for(const v of [a, b])
|
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/internal.ts
ADDED
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
|
*/
|
package/src/safe.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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
|
+
import { is_typed_arr } from './internal'
|
|
7
8
|
// TODO: over, lensProp. propsEq is up to 20x slow due to deep equals.
|
|
8
9
|
|
|
9
10
|
export const take = (argN: number) => (...args: any[]) => args[argN]
|
|
@@ -39,7 +40,11 @@ export const compose = (
|
|
|
39
40
|
}
|
|
40
41
|
)
|
|
41
42
|
export const bind = curry2<AnyFunc>((fn: AnyFunc, context: any) => fn.bind(context))
|
|
42
|
-
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]))
|
|
43
48
|
export const slice = curry3(
|
|
44
49
|
(from: number, to: number, o: any[] | string) =>
|
|
45
50
|
o.slice(from, (isNum(to)?to:inf) as number)
|
|
@@ -233,7 +238,7 @@ export const allPass = curry2((preds: Cond[], x: any) => preds.every((pred) => p
|
|
|
233
238
|
export const anyPass = curry2((preds: Cond[], x: any) => preds.some((pred) => pred(x)))
|
|
234
239
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
235
240
|
export const prop = curry2((key: string, o: AnyObject) => o[key])
|
|
236
|
-
/** @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 */
|
|
237
242
|
export const propEq = curry3(
|
|
238
243
|
(key: string, value: any, o: AnyObject) => equals(o[key], value)
|
|
239
244
|
)
|
|
@@ -260,7 +265,6 @@ export const pathsEq = curry3(
|
|
|
260
265
|
equals(path(_path, o1), path(_path, o2))
|
|
261
266
|
)
|
|
262
267
|
export const pathExists = compose(ifElse(equals(symbol), F, T), pathOr(symbol))
|
|
263
|
-
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/
|
|
264
268
|
export const clone = (s: any, shallow = false) => {
|
|
265
269
|
const t = type(s)
|
|
266
270
|
switch(t) {
|
|
@@ -275,7 +279,7 @@ export const clone = (s: any, shallow = false) => {
|
|
|
275
279
|
case 'Boolean': case 'Symbol':
|
|
276
280
|
return s
|
|
277
281
|
default:
|
|
278
|
-
return
|
|
282
|
+
return is_typed_arr(t) ? s.constructor.from(s) : s
|
|
279
283
|
}
|
|
280
284
|
}
|
|
281
285
|
export const cloneShallow = (s: any) => clone(s, true)
|
|
@@ -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
|