pepka 1.6.14 → 1.6.16
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 +18 -22
- package/dist/bundle.d.ts +15 -22
- package/dist/bundle.mjs +18 -21
- package/package.json +1 -1
- package/src/common.ts +2 -13
- package/src/internal.ts +15 -1
- package/src/quick.ts +1 -3
- package/src/safe.ts +7 -8
package/dist/bundle.cjs
CHANGED
|
@@ -71,8 +71,20 @@ function curry3(fn) {
|
|
|
71
71
|
return curry(fn);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
+
const length = (s) => s.length;
|
|
74
75
|
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
75
76
|
const is_typed_arr = (t) => typed_arr_re.test(t);
|
|
77
|
+
/** @param start string | any[] @param s string | any[] */
|
|
78
|
+
const startsWithWith = (comparator) => curry2((start, s) => {
|
|
79
|
+
const len_start = length(start);
|
|
80
|
+
const len_s = length(s);
|
|
81
|
+
if (len_start > len_s)
|
|
82
|
+
return false;
|
|
83
|
+
for (let i = 0; i < len_start; i++)
|
|
84
|
+
if (!comparator(s[i], start[i]))
|
|
85
|
+
return false;
|
|
86
|
+
return true;
|
|
87
|
+
});
|
|
76
88
|
|
|
77
89
|
const undef = undefined;
|
|
78
90
|
const nul = null;
|
|
@@ -99,7 +111,6 @@ const type = (s) => {
|
|
|
99
111
|
: caseMap[t[0]] + t.slice(1);
|
|
100
112
|
};
|
|
101
113
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
102
|
-
const length = (s) => s.length;
|
|
103
114
|
const eq = curry2((a, b) => a === b);
|
|
104
115
|
const equals = curry2((a, b) => {
|
|
105
116
|
const typea = type(a);
|
|
@@ -127,17 +138,6 @@ const includes = curry2((s, ss) => {
|
|
|
127
138
|
return false;
|
|
128
139
|
}
|
|
129
140
|
});
|
|
130
|
-
/** @param start string | any[] @param s string | any[] */
|
|
131
|
-
const qstartsWithWith = (comparator) => curry2((start, s) => {
|
|
132
|
-
const len_start = length(start);
|
|
133
|
-
const len_s = length(s);
|
|
134
|
-
if (len_start > len_s)
|
|
135
|
-
return false;
|
|
136
|
-
for (let i = 0; i < len_start; i++)
|
|
137
|
-
if (!comparator(s[i], start[i]))
|
|
138
|
-
return false;
|
|
139
|
-
return true;
|
|
140
|
-
});
|
|
141
141
|
|
|
142
142
|
/* Then next fns seem to be excess due to their safe ver performance should be the same or better:
|
|
143
143
|
* qflat, qpick, qslice, quniq, qflat, qflatShallow, qreduceAsync
|
|
@@ -253,8 +253,6 @@ const qassocPath = curry3((_path, v, o) => {
|
|
|
253
253
|
});
|
|
254
254
|
const qreverse = (arr) => arr.reverse();
|
|
255
255
|
const qomit = curry2((props, o) => qfilter((_, k) => !includes(k, props), o));
|
|
256
|
-
/** @param start string | any[] @param s string | any[] */
|
|
257
|
-
const qstartsWith = qstartsWithWith(eq);
|
|
258
256
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
259
257
|
* @returns data with prop over pipe. */
|
|
260
258
|
const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
|
|
@@ -319,8 +317,6 @@ const divide = curry2((a, b) => b / a);
|
|
|
319
317
|
const always = (s) => () => s;
|
|
320
318
|
const identity = (s) => s;
|
|
321
319
|
const trim = (s) => s.trim();
|
|
322
|
-
/** @param start string | any[] @param s string | any[] */
|
|
323
|
-
const startsWith = qstartsWithWith((x, y) => equals(x, y));
|
|
324
320
|
const not = (x) => !x;
|
|
325
321
|
const keys = (o) => Object.keys(o);
|
|
326
322
|
const values = (o) => Object.values(o);
|
|
@@ -398,10 +394,7 @@ const once = (fn) => {
|
|
|
398
394
|
return cache = fn(...args);
|
|
399
395
|
};
|
|
400
396
|
};
|
|
401
|
-
const reverse = (xs) =>
|
|
402
|
-
const ln = length(xs) - 1;
|
|
403
|
-
return map((_, i) => xs[ln - i], xs);
|
|
404
|
-
};
|
|
397
|
+
const reverse = (xs) => xs.toReversed();
|
|
405
398
|
const explore = (caption, level = 'log') => tap((v) => console[level](caption, v));
|
|
406
399
|
const cond = curry2((pairs, s) => {
|
|
407
400
|
for (const [cond, fn] of pairs)
|
|
@@ -421,6 +414,10 @@ const all = curry2((pred, xs) => xs.every(pred));
|
|
|
421
414
|
const any = curry2((pred, xs) => xs.some(pred));
|
|
422
415
|
const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
423
416
|
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
417
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
418
|
+
const startsWith = startsWithWith(equals);
|
|
419
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
420
|
+
const startsWithShallow = startsWithWith(eq);
|
|
424
421
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
425
422
|
const prop = curry2((key, o) => o[key]);
|
|
426
423
|
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
@@ -771,8 +768,6 @@ exports.qpush = qpush;
|
|
|
771
768
|
exports.qreduce = qreduce;
|
|
772
769
|
exports.qreverse = qreverse;
|
|
773
770
|
exports.qsort = qsort;
|
|
774
|
-
exports.qstartsWith = qstartsWith;
|
|
775
|
-
exports.qstartsWithWith = qstartsWithWith;
|
|
776
771
|
exports.range = range;
|
|
777
772
|
exports.reduce = reduce;
|
|
778
773
|
exports.reflect = reflect;
|
|
@@ -784,6 +779,7 @@ exports.some = some;
|
|
|
784
779
|
exports.sort = sort;
|
|
785
780
|
exports.split = split;
|
|
786
781
|
exports.startsWith = startsWith;
|
|
782
|
+
exports.startsWithShallow = startsWithShallow;
|
|
787
783
|
exports.subtract = subtract;
|
|
788
784
|
exports.symbol = symbol;
|
|
789
785
|
exports.tail = tail;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export declare function curry2<Func extends Func2>(fn: Func): {
|
|
|
34
34
|
type Func3 = (a: any, b: any, c: any) => any;
|
|
35
35
|
export declare function curry3<Func extends Func3>(fn: Func): (...args: AnyArgs) => any;
|
|
36
36
|
export declare const uncurry: <Args extends any[] = any[], ReturnT = any>(fn: Curried<Args>) => AnyFunc;
|
|
37
|
+
declare const length$1: <T extends AnyArray | string>(s: T) => T extends string ? StrLen<T> : T["length"];
|
|
37
38
|
export declare const symbol: unique symbol;
|
|
38
39
|
export declare const toLower: (s: string) => string;
|
|
39
40
|
export declare const toUpper: (s: string) => string;
|
|
@@ -44,7 +45,6 @@ export declare const typeIs: {
|
|
|
44
45
|
(a: string): (b: any) => boolean;
|
|
45
46
|
(a: string, b: any): boolean;
|
|
46
47
|
};
|
|
47
|
-
declare const length$1: <T extends AnyArray | string>(s: T) => T extends string ? StrLen<T> : T["length"];
|
|
48
48
|
export declare const eq: {
|
|
49
49
|
(a: symbol, b: any): (a: any) => boolean;
|
|
50
50
|
(a: any, b: symbol): (b: any) => boolean;
|
|
@@ -63,13 +63,6 @@ export declare const includes: {
|
|
|
63
63
|
(a: unknown): (b: unknown[]) => boolean;
|
|
64
64
|
(a: unknown, b: unknown[]): boolean;
|
|
65
65
|
};
|
|
66
|
-
/** @param start string | any[] @param s string | any[] */
|
|
67
|
-
export declare const qstartsWithWith: (comparator: (x: any, y: any) => boolean) => {
|
|
68
|
-
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
69
|
-
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
70
|
-
(a: string | any[]): (b: string | any[]) => boolean;
|
|
71
|
-
(a: string | any[], b: string | any[]): boolean;
|
|
72
|
-
};
|
|
73
66
|
export declare const isNil: <T extends any>(s: T) => T extends (null | undefined) ? true : false;
|
|
74
67
|
export declare const take: (argN: number) => (...args: any[]) => any;
|
|
75
68
|
export declare const ifElse: (...args: AnyArgs) => any;
|
|
@@ -212,13 +205,6 @@ export declare const divide: {
|
|
|
212
205
|
export declare const always: <T extends any>(s: T) => () => T;
|
|
213
206
|
export declare const identity: <T extends any>(s: T) => T;
|
|
214
207
|
export declare const trim: (s: string) => string;
|
|
215
|
-
/** @param start string | any[] @param s string | any[] */
|
|
216
|
-
export declare const startsWith: {
|
|
217
|
-
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
218
|
-
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
219
|
-
(a: string | any[]): (b: string | any[]) => boolean;
|
|
220
|
-
(a: string | any[], b: string | any[]): boolean;
|
|
221
|
-
};
|
|
222
208
|
type NotOverload = {
|
|
223
209
|
(x: true): false;
|
|
224
210
|
(x: false): true;
|
|
@@ -380,6 +366,20 @@ export declare const anyPass: {
|
|
|
380
366
|
(a: Cond[]): (b: any) => boolean;
|
|
381
367
|
(a: Cond[], b: any): boolean;
|
|
382
368
|
};
|
|
369
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
370
|
+
export declare const startsWith: {
|
|
371
|
+
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
372
|
+
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
373
|
+
(a: string | any[]): (b: string | any[]) => boolean;
|
|
374
|
+
(a: string | any[], b: string | any[]): boolean;
|
|
375
|
+
};
|
|
376
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
377
|
+
export declare const startsWithShallow: {
|
|
378
|
+
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
379
|
+
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
380
|
+
(a: string | any[]): (b: string | any[]) => boolean;
|
|
381
|
+
(a: string | any[], b: string | any[]): boolean;
|
|
382
|
+
};
|
|
383
383
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
384
384
|
export declare const prop: {
|
|
385
385
|
(a: symbol, b: AnyObject): (a: string) => any;
|
|
@@ -667,13 +667,6 @@ export declare const qomit: {
|
|
|
667
667
|
(a: string[]): (b: AnyObject) => any[] | AnyObject;
|
|
668
668
|
(a: string[], b: AnyObject): any[] | AnyObject;
|
|
669
669
|
};
|
|
670
|
-
/** @param start string | any[] @param s string | any[] */
|
|
671
|
-
export declare const qstartsWith: {
|
|
672
|
-
(a: symbol, b: string | any[]): (a: string | any[]) => boolean;
|
|
673
|
-
(a: string | any[], b: symbol): (b: string | any[]) => boolean;
|
|
674
|
-
(a: string | any[]): (b: string | any[]) => boolean;
|
|
675
|
-
(a: string | any[], b: string | any[]): boolean;
|
|
676
|
-
};
|
|
677
670
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
678
671
|
* @returns data with prop over pipe. */
|
|
679
672
|
export declare const qoverProp: (...args: AnyArgs) => any;
|
package/dist/bundle.mjs
CHANGED
|
@@ -69,8 +69,20 @@ function curry3(fn) {
|
|
|
69
69
|
return curry(fn);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
const length = (s) => s.length;
|
|
72
73
|
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
|
|
73
74
|
const is_typed_arr = (t) => typed_arr_re.test(t);
|
|
75
|
+
/** @param start string | any[] @param s string | any[] */
|
|
76
|
+
const startsWithWith = (comparator) => curry2((start, s) => {
|
|
77
|
+
const len_start = length(start);
|
|
78
|
+
const len_s = length(s);
|
|
79
|
+
if (len_start > len_s)
|
|
80
|
+
return false;
|
|
81
|
+
for (let i = 0; i < len_start; i++)
|
|
82
|
+
if (!comparator(s[i], start[i]))
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
});
|
|
74
86
|
|
|
75
87
|
const undef = undefined;
|
|
76
88
|
const nul = null;
|
|
@@ -97,7 +109,6 @@ const type = (s) => {
|
|
|
97
109
|
: caseMap[t[0]] + t.slice(1);
|
|
98
110
|
};
|
|
99
111
|
const typeIs = curry2((t, s) => type(s) === t);
|
|
100
|
-
const length = (s) => s.length;
|
|
101
112
|
const eq = curry2((a, b) => a === b);
|
|
102
113
|
const equals = curry2((a, b) => {
|
|
103
114
|
const typea = type(a);
|
|
@@ -125,17 +136,6 @@ const includes = curry2((s, ss) => {
|
|
|
125
136
|
return false;
|
|
126
137
|
}
|
|
127
138
|
});
|
|
128
|
-
/** @param start string | any[] @param s string | any[] */
|
|
129
|
-
const qstartsWithWith = (comparator) => curry2((start, s) => {
|
|
130
|
-
const len_start = length(start);
|
|
131
|
-
const len_s = length(s);
|
|
132
|
-
if (len_start > len_s)
|
|
133
|
-
return false;
|
|
134
|
-
for (let i = 0; i < len_start; i++)
|
|
135
|
-
if (!comparator(s[i], start[i]))
|
|
136
|
-
return false;
|
|
137
|
-
return true;
|
|
138
|
-
});
|
|
139
139
|
|
|
140
140
|
/* Then next fns seem to be excess due to their safe ver performance should be the same or better:
|
|
141
141
|
* qflat, qpick, qslice, quniq, qflat, qflatShallow, qreduceAsync
|
|
@@ -251,8 +251,6 @@ const qassocPath = curry3((_path, v, o) => {
|
|
|
251
251
|
});
|
|
252
252
|
const qreverse = (arr) => arr.reverse();
|
|
253
253
|
const qomit = curry2((props, o) => qfilter((_, k) => !includes(k, props), o));
|
|
254
|
-
/** @param start string | any[] @param s string | any[] */
|
|
255
|
-
const qstartsWith = qstartsWithWith(eq);
|
|
256
254
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
257
255
|
* @returns data with prop over pipe. */
|
|
258
256
|
const qoverProp = curry3((prop, pipe, data) => qassoc(prop, pipe(data[prop]), data));
|
|
@@ -317,8 +315,6 @@ const divide = curry2((a, b) => b / a);
|
|
|
317
315
|
const always = (s) => () => s;
|
|
318
316
|
const identity = (s) => s;
|
|
319
317
|
const trim = (s) => s.trim();
|
|
320
|
-
/** @param start string | any[] @param s string | any[] */
|
|
321
|
-
const startsWith = qstartsWithWith((x, y) => equals(x, y));
|
|
322
318
|
const not = (x) => !x;
|
|
323
319
|
const keys = (o) => Object.keys(o);
|
|
324
320
|
const values = (o) => Object.values(o);
|
|
@@ -396,10 +392,7 @@ const once = (fn) => {
|
|
|
396
392
|
return cache = fn(...args);
|
|
397
393
|
};
|
|
398
394
|
};
|
|
399
|
-
const reverse = (xs) =>
|
|
400
|
-
const ln = length(xs) - 1;
|
|
401
|
-
return map((_, i) => xs[ln - i], xs);
|
|
402
|
-
};
|
|
395
|
+
const reverse = (xs) => xs.toReversed();
|
|
403
396
|
const explore = (caption, level = 'log') => tap((v) => console[level](caption, v));
|
|
404
397
|
const cond = curry2((pairs, s) => {
|
|
405
398
|
for (const [cond, fn] of pairs)
|
|
@@ -419,6 +412,10 @@ const all = curry2((pred, xs) => xs.every(pred));
|
|
|
419
412
|
const any = curry2((pred, xs) => xs.some(pred));
|
|
420
413
|
const allPass = curry2((preds, x) => preds.every((pred) => pred(x)));
|
|
421
414
|
const anyPass = curry2((preds, x) => preds.some((pred) => pred(x)));
|
|
415
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
416
|
+
const startsWith = startsWithWith(equals);
|
|
417
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
418
|
+
const startsWithShallow = startsWithWith(eq);
|
|
422
419
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
423
420
|
const prop = curry2((key, o) => o[key]);
|
|
424
421
|
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|
|
@@ -654,4 +651,4 @@ const composeAsync = (() => {
|
|
|
654
651
|
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
655
652
|
})();
|
|
656
653
|
|
|
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,
|
|
654
|
+
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, 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, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
|
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.6.
|
|
44
|
+
"version": "1.6.16",
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
package/src/common.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { curry2 } from "./curry"
|
|
2
2
|
import { is_typed_arr } from "./internal"
|
|
3
|
-
import {
|
|
4
|
-
import { to, isNull, isStr, isUndef } from "./utils"
|
|
3
|
+
import { to, isNull, isStr } from "./utils"
|
|
5
4
|
|
|
6
5
|
// It's faster that toUpperCase() !
|
|
7
6
|
const caseMap = { u: 'U', b: 'B', n: 'N', s: 'S', f: 'F' }
|
|
@@ -17,7 +16,6 @@ export const type = (s: any): string => {
|
|
|
17
16
|
}
|
|
18
17
|
export const typeIs = curry2((t: string, s: any) => type(s)===t)
|
|
19
18
|
|
|
20
|
-
export const length = <T extends AnyArray | string>(s: T): T extends string ? StrLen<T> : T["length"] => s.length as any
|
|
21
19
|
export const eq = curry2((a: any, b: any) => a===b)
|
|
22
20
|
export const equals = curry2((a: any, b: any) => {
|
|
23
21
|
const typea = type(a)
|
|
@@ -43,13 +41,4 @@ export const includes = curry2(
|
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
43
|
)
|
|
46
|
-
|
|
47
|
-
export const qstartsWithWith = (comparator: (x: any, y: any)=>boolean) => curry2(
|
|
48
|
-
(start: any[] | string, s: any[] | string) => {
|
|
49
|
-
const len_start = length(start)
|
|
50
|
-
const len_s = length(s)
|
|
51
|
-
if(len_start>len_s) return false
|
|
52
|
-
for(let i=0; i<len_start; i++) if(!comparator(s[i], start[i])) return false
|
|
53
|
-
return true
|
|
54
|
-
}
|
|
55
|
-
)
|
|
44
|
+
export {length} from './internal'
|
package/src/internal.ts
CHANGED
|
@@ -1,2 +1,16 @@
|
|
|
1
|
+
import { curry2 } from "./curry"
|
|
2
|
+
import { AnyArray, StrLen } from "./internal_types"
|
|
3
|
+
|
|
4
|
+
export const length = <T extends AnyArray | string>(s: T): T extends string ? StrLen<T> : T["length"] => s.length as any
|
|
1
5
|
const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/
|
|
2
|
-
export const is_typed_arr = (t: string) => typed_arr_re.test(t)
|
|
6
|
+
export const is_typed_arr = (t: string) => typed_arr_re.test(t)
|
|
7
|
+
/** @param start string | any[] @param s string | any[] */
|
|
8
|
+
export const startsWithWith = (comparator: (x: any, y: any)=>boolean) => curry2(
|
|
9
|
+
(start: any[] | string, s: any[] | string) => {
|
|
10
|
+
const len_start = length(start)
|
|
11
|
+
const len_s = length(s)
|
|
12
|
+
if(len_start>len_s) return false
|
|
13
|
+
for(let i=0; i<len_start; i++) if(!comparator(s[i], start[i])) return false
|
|
14
|
+
return true
|
|
15
|
+
}
|
|
16
|
+
)
|
package/src/quick.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { curry2, curry3 } from "./curry"
|
|
2
|
-
import { includes, type, eq
|
|
2
|
+
import { includes, type, eq } from "./common"
|
|
3
3
|
import { AnyObject, Reducer, AnyFunc } from "./types"
|
|
4
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:
|
|
@@ -126,8 +126,6 @@ export const qomit = curry2(
|
|
|
126
126
|
o
|
|
127
127
|
)
|
|
128
128
|
)
|
|
129
|
-
/** @param start string | any[] @param s string | any[] */
|
|
130
|
-
export const qstartsWith = qstartsWithWith(eq)
|
|
131
129
|
/** @param prop string @param pipe (data[prop]): prop_value @param data any
|
|
132
130
|
* @returns data with prop over pipe. */
|
|
133
131
|
export const qoverProp = curry3(
|
package/src/safe.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { __, curry, curry2, curry3 } from './curry'
|
|
|
2
2
|
import { isNum, undef, isArray, isFunc, isObj, inf, isNil } from './utils'
|
|
3
3
|
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj } from './quick'
|
|
4
4
|
import { AnyFunc, Composed, Cond, AnyObject, Reducer } from './types'
|
|
5
|
-
import { symbol, type, length, equals, includes,
|
|
5
|
+
import { symbol, type, length, equals, includes, eq } from './common'
|
|
6
6
|
import { Split, AnyArray, IndexesOfArray } from './internal_types'
|
|
7
|
-
import { is_typed_arr } from './internal'
|
|
7
|
+
import { is_typed_arr, startsWithWith } from './internal'
|
|
8
8
|
// TODO: over, lensProp, reduceAsync, propsEq is up to 20x slow due to deep equals.
|
|
9
9
|
|
|
10
10
|
export const take = (argN: number) => (...args: any[]) => args[argN]
|
|
@@ -110,8 +110,6 @@ export const always = <T extends any>(s: T) => () => s
|
|
|
110
110
|
export const identity = <T extends any>(s: T) => s
|
|
111
111
|
export const trim = (s: string) => s.trim()
|
|
112
112
|
|
|
113
|
-
/** @param start string | any[] @param s string | any[] */
|
|
114
|
-
export const startsWith = qstartsWithWith((x: any, y: any) => equals(x, y))
|
|
115
113
|
type NotOverload = {
|
|
116
114
|
(x: true): false
|
|
117
115
|
(x: false): true
|
|
@@ -206,10 +204,7 @@ export const once = <Func extends AnyFunc>(fn: Func) => {
|
|
|
206
204
|
return cache = fn(...args) as ReturnType<Func>
|
|
207
205
|
}
|
|
208
206
|
}
|
|
209
|
-
export const reverse = <T extends any>(xs: T[]): T[] =>
|
|
210
|
-
const ln = length(xs)-1
|
|
211
|
-
return map((_: any, i: number) => xs[ln-i], xs)
|
|
212
|
-
}
|
|
207
|
+
export const reverse = <T extends any>(xs: T[]): T[] => xs.toReversed()
|
|
213
208
|
export const explore = (caption: string, level = 'log') => tap(
|
|
214
209
|
(v: any) => console[level](caption, v)
|
|
215
210
|
)
|
|
@@ -242,6 +237,10 @@ export const all = curry2((pred: Cond, xs: any[]) => xs.every(pred))
|
|
|
242
237
|
export const any = curry2((pred: Cond, xs: any[]) => xs.some(pred))
|
|
243
238
|
export const allPass = curry2((preds: Cond[], x: any) => preds.every((pred) => pred(x)))
|
|
244
239
|
export const anyPass = curry2((preds: Cond[], x: any) => preds.some((pred) => pred(x)))
|
|
240
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
241
|
+
export const startsWith = startsWithWith(equals)
|
|
242
|
+
/** @param start string | any[] @param s string | any[] @description detects if `s` starts with `start` */
|
|
243
|
+
export const startsWithShallow = startsWithWith(eq)
|
|
245
244
|
/** @param key string @param o AnyObject @returns o[key] */
|
|
246
245
|
export const prop = curry2((key: string, o: AnyObject) => o[key])
|
|
247
246
|
/** @param key string @param value any @param o AnyObject @returns boolean o[key] equals value */
|