pepka 1.6.2 → 1.6.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 +32 -2
- package/dist/bundle.d.ts +25 -22
- package/dist/bundle.mjs +30 -3
- package/package.json +8 -28
- package/src/index.ts +1 -0
- package/src/quick.ts +1 -0
- package/src/safe.ts +4 -4
- package/src/timers.ts +20 -11
package/dist/bundle.cjs
CHANGED
|
@@ -301,7 +301,7 @@ const lt = curry2((a, b) => a > b);
|
|
|
301
301
|
const gte = curry2((a, b) => a <= b);
|
|
302
302
|
/** @param a @param b @returns a≥b */
|
|
303
303
|
const lte = curry2((a, b) => a >= b);
|
|
304
|
-
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
304
|
+
const sort = curry2((sortFn, xs) => xs.sort(sortFn)); // TODO: make it shallow cloning.
|
|
305
305
|
const find = curry2((fn, s) => s.find(fn));
|
|
306
306
|
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
307
307
|
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
@@ -338,7 +338,7 @@ const complement = (fn) => (...args) => {
|
|
|
338
338
|
return !f || f && out.$args_left <= 0 ? not(out) : complement(out);
|
|
339
339
|
};
|
|
340
340
|
const sizeof = (s) => {
|
|
341
|
-
if (
|
|
341
|
+
if (isObj(s)) {
|
|
342
342
|
let len = 0;
|
|
343
343
|
for (let _k in s)
|
|
344
344
|
len++;
|
|
@@ -594,6 +594,33 @@ const getTmpl = (tmpl) => {
|
|
|
594
594
|
};
|
|
595
595
|
};
|
|
596
596
|
|
|
597
|
+
const debounce = (time, fn) => {
|
|
598
|
+
let queue = [];
|
|
599
|
+
let to;
|
|
600
|
+
return ((...args) => new Promise((ff) => {
|
|
601
|
+
clearTimeout(to);
|
|
602
|
+
to = setTimeout(async () => {
|
|
603
|
+
const res = await fn(...args);
|
|
604
|
+
for (ff of queue)
|
|
605
|
+
ff(res);
|
|
606
|
+
queue.splice(0);
|
|
607
|
+
}, time);
|
|
608
|
+
queue.push(ff);
|
|
609
|
+
}));
|
|
610
|
+
};
|
|
611
|
+
// export const debouncePrepared =
|
|
612
|
+
const throttle = (time, fn) => {
|
|
613
|
+
let on = true;
|
|
614
|
+
return (...args) => {
|
|
615
|
+
if (on) {
|
|
616
|
+
on = false;
|
|
617
|
+
setTimeout(() => on = true, time);
|
|
618
|
+
return fn(...args);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
};
|
|
622
|
+
const wait = (time) => new Promise((ff) => setTimeout(ff, time));
|
|
623
|
+
|
|
597
624
|
/** One promise waits for another. */
|
|
598
625
|
const forEachSerial = (() => {
|
|
599
626
|
const pipe = async (fn, items, i) => {
|
|
@@ -646,6 +673,7 @@ exports.cond = cond;
|
|
|
646
673
|
exports.curry = curry;
|
|
647
674
|
exports.curry2 = curry2;
|
|
648
675
|
exports.curry3 = curry3;
|
|
676
|
+
exports.debounce = debounce;
|
|
649
677
|
exports.diff = diff;
|
|
650
678
|
exports.divide = divide;
|
|
651
679
|
exports.echo = echo;
|
|
@@ -751,6 +779,7 @@ exports.tail = tail;
|
|
|
751
779
|
exports.take = take;
|
|
752
780
|
exports.tap = tap;
|
|
753
781
|
exports.test = test;
|
|
782
|
+
exports.throttle = throttle;
|
|
754
783
|
exports.toLower = toLower;
|
|
755
784
|
exports.toPairs = toPairs;
|
|
756
785
|
exports.toUpper = toUpper;
|
|
@@ -761,6 +790,7 @@ exports.uncurry = uncurry;
|
|
|
761
790
|
exports.uniq = uniq;
|
|
762
791
|
exports.uniqWith = uniqWith;
|
|
763
792
|
exports.values = values;
|
|
793
|
+
exports.wait = wait;
|
|
764
794
|
exports.waitAll = waitAll;
|
|
765
795
|
exports.waitTap = waitTap;
|
|
766
796
|
exports.weakEq = weakEq;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ export declare const typeIs: {
|
|
|
43
43
|
(a: string): (b: any) => boolean;
|
|
44
44
|
(a: string, b: any): boolean;
|
|
45
45
|
};
|
|
46
|
-
declare const length$1: <T extends
|
|
46
|
+
declare const length$1: <T extends AnyArray | string>(s: T) => T extends string ? StrLen<T> : T["length"];
|
|
47
47
|
export declare const isNil: (s: any) => boolean;
|
|
48
48
|
export declare const eq: {
|
|
49
49
|
(a: symbol, b: any): (a: any) => boolean;
|
|
@@ -209,8 +209,8 @@ export declare const divide: {
|
|
|
209
209
|
(a: number): (b: number) => number;
|
|
210
210
|
(a: number, b: number): number;
|
|
211
211
|
};
|
|
212
|
-
export declare const always: <T extends
|
|
213
|
-
export declare const identity: <T extends
|
|
212
|
+
export declare const always: <T extends any>(s: T) => () => T;
|
|
213
|
+
export declare const identity: <T extends any>(s: T) => T;
|
|
214
214
|
export declare const trim: (s: string) => string;
|
|
215
215
|
/** @param start string | any[] @param s string | any[] */
|
|
216
216
|
export declare const startsWith: {
|
|
@@ -288,7 +288,7 @@ export declare const noop: (...args: any[]) => any;
|
|
|
288
288
|
* @param {string} fnName - property name of the function.
|
|
289
289
|
* @param {AnyObject} o - the object with the function. */
|
|
290
290
|
export declare const callFrom: (...args: AnyArgs) => any;
|
|
291
|
-
export declare const complement: (fn: AnyFunc) => (...args: any) => boolean | any;
|
|
291
|
+
export declare const complement: (fn: AnyFunc) => (...args: any) => boolean | ((...args: any) => boolean | /*elided*/ any);
|
|
292
292
|
export declare const sizeof: (s: any[] | string | AnyObject) => number;
|
|
293
293
|
export declare const range: {
|
|
294
294
|
(a: symbol, b: number): (a: number) => any[];
|
|
@@ -324,7 +324,7 @@ export declare const genBy: {
|
|
|
324
324
|
(a: (i: number) => any, b: number): any[];
|
|
325
325
|
};
|
|
326
326
|
export declare const once: <Func extends AnyFunc>(fn: Func) => (...args: Parameters<Func>) => any;
|
|
327
|
-
export declare const reverse: <T extends
|
|
327
|
+
export declare const reverse: <T extends any>(xs: T[]) => T[];
|
|
328
328
|
export declare const explore: (caption: string, level?: string) => (b: any) => any;
|
|
329
329
|
export declare const cond: {
|
|
330
330
|
(a: symbol, b: any): (a: [
|
|
@@ -350,7 +350,7 @@ export declare const cond: {
|
|
|
350
350
|
* @param object AnyObject
|
|
351
351
|
*/
|
|
352
352
|
export declare const assoc: (...args: AnyArgs) => any;
|
|
353
|
-
export declare const assocPath: any;
|
|
353
|
+
export declare const assocPath: (...args: AnyArgs) => any;
|
|
354
354
|
export declare const all: {
|
|
355
355
|
(a: symbol, b: any[]): (a: Cond) => boolean;
|
|
356
356
|
(a: Cond, b: symbol): (b: any[]) => boolean;
|
|
@@ -386,7 +386,7 @@ export declare const prop: {
|
|
|
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;
|
|
389
|
-
export declare const pathOr: any;
|
|
389
|
+
export declare const pathOr: (...args: AnyArgs) => any;
|
|
390
390
|
export declare const path: any;
|
|
391
391
|
export declare const pathEq: (...args: AnyArgs) => any;
|
|
392
392
|
export declare const pathsEq: (...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[] | AnyObject;
|
|
418
|
+
(a: string[], b: symbol): (b: AnyObject) => any[] | AnyObject;
|
|
419
|
+
(a: string[]): (b: AnyObject) => any[] | AnyObject;
|
|
420
|
+
(a: string[], b: AnyObject): any[] | AnyObject;
|
|
421
421
|
};
|
|
422
422
|
export declare const fromPairs: (pairs: [
|
|
423
423
|
string,
|
|
@@ -460,20 +460,20 @@ 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[] | AnyObject;
|
|
464
|
+
(a: (v: any, k: string | number) => boolean, b: symbol): (b: any[] | AnyObject) => any[] | AnyObject;
|
|
465
|
+
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any[] | AnyObject;
|
|
466
|
+
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any[] | AnyObject;
|
|
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.
|
|
470
470
|
* @param {(...args: Args) any} fn to be cached.
|
|
471
471
|
*/
|
|
472
472
|
export declare const memoize: {
|
|
473
|
-
(a: symbol, b: AnyFunc<any, any[]>): (a: (...args: any[]) => string) => (...args: any[]) => any
|
|
474
|
-
(a: (...args: any[]) => string, b: symbol): (b: AnyFunc<any, any[]>) => (...args: any[]) => any
|
|
475
|
-
(a: (...args: any[]) => string): (b: AnyFunc<any, any[]>) => (...args: any[]) => any
|
|
476
|
-
(a: (...args: any[]) => string, b: AnyFunc<any, any[]>): (...args: any[]) => any
|
|
473
|
+
(a: symbol, b: AnyFunc<any, any[]>): (a: (...args: any[]) => string) => (...args: any[]) => ReturnType<AnyFunc<any, any[]>>;
|
|
474
|
+
(a: (...args: any[]) => string, b: symbol): (b: AnyFunc<any, any[]>) => (...args: any[]) => ReturnType<AnyFunc<any, any[]>>;
|
|
475
|
+
(a: (...args: any[]) => string): (b: AnyFunc<any, any[]>) => (...args: any[]) => ReturnType<AnyFunc<any, any[]>>;
|
|
476
|
+
(a: (...args: any[]) => string, b: AnyFunc<any, any[]>): (...args: any[]) => ReturnType<AnyFunc<any, any[]>>;
|
|
477
477
|
};
|
|
478
478
|
export declare const mergeShallow: {
|
|
479
479
|
(a: symbol, b: AnyObject): (a: AnyObject) => AnyObject;
|
|
@@ -538,7 +538,7 @@ export declare const zipWith: (...args: AnyArgs) => any;
|
|
|
538
538
|
export declare const mirror: <T extends unknown>(s: T) => T;
|
|
539
539
|
export declare const reflect: <T extends unknown>(s: T) => T;
|
|
540
540
|
export declare const echo: <T extends unknown>(s: T) => T;
|
|
541
|
-
export declare const notf: (fn: AnyFunc) => (...args: any) => boolean | any;
|
|
541
|
+
export declare const notf: (fn: AnyFunc) => (...args: any) => boolean | ((...args: any) => boolean | /*elided*/ any);
|
|
542
542
|
export declare const push: {
|
|
543
543
|
(a: symbol, b: any[]): (a: any) => any[];
|
|
544
544
|
(a: any, b: symbol): (b: any[]) => any[];
|
|
@@ -622,7 +622,7 @@ export declare const qfilter: {
|
|
|
622
622
|
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any[] | AnyObject;
|
|
623
623
|
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any[] | AnyObject;
|
|
624
624
|
};
|
|
625
|
-
export declare const qempty: <T extends any[]
|
|
625
|
+
export declare const qempty: <T extends AnyObject | any[]>(o: T) => T extends any[] ? [
|
|
626
626
|
] : {};
|
|
627
627
|
export declare const qfreeze: <T extends AnyObject>(o: T) => Readonly<T>;
|
|
628
628
|
export declare const qfreezeShallow: <T extends AnyObject>(o: T) => Readonly<T>;
|
|
@@ -632,7 +632,7 @@ export declare const qprepend: {
|
|
|
632
632
|
(a: any): (b: any[]) => number;
|
|
633
633
|
(a: any, b: any[]): number;
|
|
634
634
|
};
|
|
635
|
-
export declare const qassocPath: any;
|
|
635
|
+
export declare const qassocPath: (...args: AnyArgs) => any;
|
|
636
636
|
export declare const qreverse: (arr: any[]) => any[];
|
|
637
637
|
export declare const qomit: {
|
|
638
638
|
(a: symbol, b: AnyObject): (a: string[]) => any[] | AnyObject;
|
|
@@ -654,6 +654,9 @@ type StrTmpl = ((data: AnyObject) => string);
|
|
|
654
654
|
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
655
655
|
@returns getTmpl('one{meme}two')({meme: 42}) -> one42two */
|
|
656
656
|
export declare const getTmpl: (tmpl: string) => StrTmpl;
|
|
657
|
+
export declare const debounce: <T extends AnyFunc>(time: number, fn: T) => (...args: Parameters<T>) => Promise<ReturnType<T>>;
|
|
658
|
+
export declare const throttle: <T extends AnyFunc>(time: number, fn: T) => (...args: Parameters<T>) => any;
|
|
659
|
+
export declare const wait: (time: number) => Promise<unknown>;
|
|
657
660
|
/** One promise waits for another. */
|
|
658
661
|
export declare const forEachSerial: {
|
|
659
662
|
(a: symbol, b: any[]): (a: AnyFunc) => Promise<void>;
|
package/dist/bundle.mjs
CHANGED
|
@@ -299,7 +299,7 @@ const lt = curry2((a, b) => a > b);
|
|
|
299
299
|
const gte = curry2((a, b) => a <= b);
|
|
300
300
|
/** @param a @param b @returns a≥b */
|
|
301
301
|
const lte = curry2((a, b) => a >= b);
|
|
302
|
-
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
302
|
+
const sort = curry2((sortFn, xs) => xs.sort(sortFn)); // TODO: make it shallow cloning.
|
|
303
303
|
const find = curry2((fn, s) => s.find(fn));
|
|
304
304
|
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
305
305
|
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
@@ -336,7 +336,7 @@ const complement = (fn) => (...args) => {
|
|
|
336
336
|
return !f || f && out.$args_left <= 0 ? not(out) : complement(out);
|
|
337
337
|
};
|
|
338
338
|
const sizeof = (s) => {
|
|
339
|
-
if (
|
|
339
|
+
if (isObj(s)) {
|
|
340
340
|
let len = 0;
|
|
341
341
|
for (let _k in s)
|
|
342
342
|
len++;
|
|
@@ -592,6 +592,33 @@ const getTmpl = (tmpl) => {
|
|
|
592
592
|
};
|
|
593
593
|
};
|
|
594
594
|
|
|
595
|
+
const debounce = (time, fn) => {
|
|
596
|
+
let queue = [];
|
|
597
|
+
let to;
|
|
598
|
+
return ((...args) => new Promise((ff) => {
|
|
599
|
+
clearTimeout(to);
|
|
600
|
+
to = setTimeout(async () => {
|
|
601
|
+
const res = await fn(...args);
|
|
602
|
+
for (ff of queue)
|
|
603
|
+
ff(res);
|
|
604
|
+
queue.splice(0);
|
|
605
|
+
}, time);
|
|
606
|
+
queue.push(ff);
|
|
607
|
+
}));
|
|
608
|
+
};
|
|
609
|
+
// export const debouncePrepared =
|
|
610
|
+
const throttle = (time, fn) => {
|
|
611
|
+
let on = true;
|
|
612
|
+
return (...args) => {
|
|
613
|
+
if (on) {
|
|
614
|
+
on = false;
|
|
615
|
+
setTimeout(() => on = true, time);
|
|
616
|
+
return fn(...args);
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
};
|
|
620
|
+
const wait = (time) => new Promise((ff) => setTimeout(ff, time));
|
|
621
|
+
|
|
595
622
|
/** One promise waits for another. */
|
|
596
623
|
const forEachSerial = (() => {
|
|
597
624
|
const pipe = async (fn, items, i) => {
|
|
@@ -618,4 +645,4 @@ const composeAsync = (() => {
|
|
|
618
645
|
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
619
646
|
})();
|
|
620
647
|
|
|
621
|
-
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, 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, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqWith, values, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
|
|
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 };
|
package/package.json
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"type": "module",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
+
"types": "./dist/bundle.d.ts",
|
|
24
25
|
"import": "./dist/bundle.mjs",
|
|
25
26
|
"require": "./dist/bundle.cjs"
|
|
26
27
|
}
|
|
@@ -32,9 +33,6 @@
|
|
|
32
33
|
},
|
|
33
34
|
"scripts": {
|
|
34
35
|
"lint": "tslint src/*.ts",
|
|
35
|
-
"test": "npm run gentypes && npm run prod:es && ava",
|
|
36
|
-
"test:report": "nyc npm test && nyc report --reporter=text-lcov > coverage.lcov && codecov",
|
|
37
|
-
"test:lazy": "ava",
|
|
38
36
|
"gentypes": "dts-bundle-generator --no-check --export-referenced-types=false -o dist/bundle.d.ts src/index.ts",
|
|
39
37
|
"dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
|
|
40
38
|
"prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
|
|
@@ -42,37 +40,19 @@
|
|
|
42
40
|
"prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
|
|
43
41
|
"all": "npm run dev && npm run prod"
|
|
44
42
|
},
|
|
45
|
-
"version": "1.6.
|
|
46
|
-
"ava": {
|
|
47
|
-
"files": [
|
|
48
|
-
"./test/specs/*.ts"
|
|
49
|
-
],
|
|
50
|
-
"failFast": true,
|
|
51
|
-
"timeout": "2m",
|
|
52
|
-
"extensions": [
|
|
53
|
-
"ts"
|
|
54
|
-
],
|
|
55
|
-
"require": [
|
|
56
|
-
"ts-node/register"
|
|
57
|
-
]
|
|
58
|
-
},
|
|
43
|
+
"version": "1.6.3",
|
|
59
44
|
"devDependencies": {
|
|
60
|
-
"@rollup/plugin-commonjs": "^
|
|
61
|
-
"@rollup/plugin-node-resolve": "^
|
|
62
|
-
"@rollup/plugin-replace": "^
|
|
63
|
-
"@types/node": "^
|
|
64
|
-
"ava": "^6.1.2",
|
|
65
|
-
"codecov": "^3.8.3",
|
|
45
|
+
"@rollup/plugin-commonjs": "^28.0.3",
|
|
46
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
47
|
+
"@rollup/plugin-replace": "^6.0.2",
|
|
48
|
+
"@types/node": "^22.13.10",
|
|
66
49
|
"cross-env": "^7.0.3",
|
|
67
50
|
"dts-bundle-generator": "^9.5.1",
|
|
68
|
-
"
|
|
69
|
-
"prepend": "^1.0.2",
|
|
70
|
-
"rollup": "^4.17.0",
|
|
51
|
+
"rollup": "^4.35.0",
|
|
71
52
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
72
53
|
"ts-node": "^10.9.2",
|
|
73
54
|
"tslint": "^6.1.3",
|
|
74
|
-
"typescript": "^5.
|
|
55
|
+
"typescript": "^5.8.2"
|
|
75
56
|
},
|
|
76
|
-
"types": "./dist/bundle.d.ts",
|
|
77
57
|
"sideEffects": false
|
|
78
58
|
}
|
package/src/index.ts
CHANGED
package/src/quick.ts
CHANGED
|
@@ -110,6 +110,7 @@ export const qfreeze = <T extends AnyObject>(o: T): Readonly<T> => {
|
|
|
110
110
|
}
|
|
111
111
|
export const qfreezeShallow = <T extends AnyObject>(o: T): Readonly<T> => Object.freeze(o)
|
|
112
112
|
export const qprepend = curry2((x: any, xs: any[]) => xs.unshift(x))
|
|
113
|
+
export const qsort = curry2((sortFn: (a: any, b: any) => number , xs: any[]) => xs.sort(sortFn))
|
|
113
114
|
export const qassocPath = curry3((_path: string[], v: any, o: AnyObject) => {
|
|
114
115
|
const first = _path[0]
|
|
115
116
|
return qassoc(first, _path.length<2
|
package/src/safe.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __, curry, curry2, curry3 } from './curry'
|
|
2
2
|
import { isNum, undef, isArray, isFunc, isObj, inf } from './utils'
|
|
3
|
-
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj } from './quick'
|
|
3
|
+
import { qmergeDeep, qreduce, qappend, qmapKeys, qmergeDeepX, qmergeDeepAdd, qfilter, qfreeze, qfreezeShallow, qmapObj, qsort } from './quick'
|
|
4
4
|
import { AnyFunc, Cond, AnyObject, Reducer } from './types'
|
|
5
5
|
import { symbol, type, length, equals, includes, isNil, qstartsWithWith, eq } from './common'
|
|
6
6
|
import { Split, AnyArray, IndexesOfArray } from './internal_types'
|
|
@@ -97,7 +97,7 @@ export const lt = curry2( (a: number, b: number) => a>b )
|
|
|
97
97
|
export const gte = curry2( (a: number, b: number) => a<=b )
|
|
98
98
|
/** @param a @param b @returns a≥b */
|
|
99
99
|
export const lte = curry2( (a: number, b: number) => a>=b )
|
|
100
|
-
export const sort = curry2((sortFn: (a:
|
|
100
|
+
export const sort = curry2(<T extends any>(sortFn: (a: T, b: T) => number , xs: T[]) => [...xs].sort(sortFn))
|
|
101
101
|
export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
|
|
102
102
|
export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
|
|
103
103
|
export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
|
|
@@ -145,7 +145,7 @@ export const complement = (fn: AnyFunc) => (...args: any) => {
|
|
|
145
145
|
return !f || f&&out.$args_left<=0 ? not(out) : complement(out)
|
|
146
146
|
}
|
|
147
147
|
export const sizeof = (s: any[] | string | AnyObject) => {
|
|
148
|
-
if(
|
|
148
|
+
if(isObj(s)) {
|
|
149
149
|
let len = 0
|
|
150
150
|
for(let _k in s as AnyObject) len++
|
|
151
151
|
return len
|
|
@@ -317,7 +317,7 @@ export const map = curry2(
|
|
|
317
317
|
(pipe: (s: any, i?: number, list?: any[]) => any, arr: any[]) => arr.map(pipe)
|
|
318
318
|
)
|
|
319
319
|
export const mapObj = curry2(
|
|
320
|
-
(pipe: (s: any, i?: string, list?: any[]) => any, o: AnyObject) => qmapObj(pipe,
|
|
320
|
+
(pipe: (s: any, i?: string, list?: any[]) => any, o: AnyObject) => qmapObj(pipe, {...o})
|
|
321
321
|
)
|
|
322
322
|
export const join = curry2((delimeter: string, arr: string[]) => arr.join(delimeter))
|
|
323
323
|
export const forEach = curry2((pipe: (s: any) => any, arr: any[]) => arr.forEach(pipe))
|
package/src/timers.ts
CHANGED
|
@@ -4,15 +4,24 @@ export const debounce = <T extends AnyFunc>(time: number, fn: T) => {
|
|
|
4
4
|
let queue: AnyFunc[] = []
|
|
5
5
|
let to: NodeJS.Timeout
|
|
6
6
|
return ((...args: Parameters<T>) => new Promise<ReturnType<T>>((ff) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
queue.splice(0)
|
|
15
|
-
queue.push(qel)
|
|
16
|
-
qel()
|
|
7
|
+
clearTimeout(to)
|
|
8
|
+
to = setTimeout(async () => {
|
|
9
|
+
const res = await fn(...args)
|
|
10
|
+
for(ff of queue) ff(res)
|
|
11
|
+
queue.splice(0)
|
|
12
|
+
}, time)
|
|
13
|
+
queue.push(ff)
|
|
17
14
|
}))
|
|
18
|
-
}
|
|
15
|
+
}
|
|
16
|
+
// export const debouncePrepared =
|
|
17
|
+
export const throttle = <T extends AnyFunc>(time: number, fn: T) => {
|
|
18
|
+
let on = true
|
|
19
|
+
return (...args: Parameters<T>) => {
|
|
20
|
+
if(on) {
|
|
21
|
+
on = false
|
|
22
|
+
setTimeout(() => on = true, time)
|
|
23
|
+
return fn(...args)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export const wait = (time: number) => new Promise((ff) => setTimeout(ff, time))
|