pepka 1.6.1 → 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 +37 -3
- package/dist/bundle.d.ts +34 -32
- package/dist/bundle.mjs +35 -4
- package/package.json +8 -28
- package/src/index.ts +1 -0
- package/src/quick.ts +5 -1
- package/src/safe.ts +4 -4
- package/src/timers.ts +20 -11
- package/src/types.ts +1 -1
package/dist/bundle.cjs
CHANGED
|
@@ -199,7 +199,11 @@ const qmap = curry2((pipe, arr) => {
|
|
|
199
199
|
arr[i] = pipe(arr[i], +i, arr);
|
|
200
200
|
return arr;
|
|
201
201
|
});
|
|
202
|
-
const qmapObj = curry2((pipe, o) =>
|
|
202
|
+
const qmapObj = curry2((pipe, o) => {
|
|
203
|
+
for (const k in o)
|
|
204
|
+
o[k] = pipe(o[k], k, o);
|
|
205
|
+
return o;
|
|
206
|
+
});
|
|
203
207
|
const qfilter = curry2((cond, data) => {
|
|
204
208
|
const isArr = isArray(data);
|
|
205
209
|
let indicies_offset, indicies2rm;
|
|
@@ -297,7 +301,7 @@ const lt = curry2((a, b) => a > b);
|
|
|
297
301
|
const gte = curry2((a, b) => a <= b);
|
|
298
302
|
/** @param a @param b @returns a≥b */
|
|
299
303
|
const lte = curry2((a, b) => a >= b);
|
|
300
|
-
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
304
|
+
const sort = curry2((sortFn, xs) => xs.sort(sortFn)); // TODO: make it shallow cloning.
|
|
301
305
|
const find = curry2((fn, s) => s.find(fn));
|
|
302
306
|
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
303
307
|
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
@@ -334,7 +338,7 @@ const complement = (fn) => (...args) => {
|
|
|
334
338
|
return !f || f && out.$args_left <= 0 ? not(out) : complement(out);
|
|
335
339
|
};
|
|
336
340
|
const sizeof = (s) => {
|
|
337
|
-
if (
|
|
341
|
+
if (isObj(s)) {
|
|
338
342
|
let len = 0;
|
|
339
343
|
for (let _k in s)
|
|
340
344
|
len++;
|
|
@@ -590,6 +594,33 @@ const getTmpl = (tmpl) => {
|
|
|
590
594
|
};
|
|
591
595
|
};
|
|
592
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
|
+
|
|
593
624
|
/** One promise waits for another. */
|
|
594
625
|
const forEachSerial = (() => {
|
|
595
626
|
const pipe = async (fn, items, i) => {
|
|
@@ -642,6 +673,7 @@ exports.cond = cond;
|
|
|
642
673
|
exports.curry = curry;
|
|
643
674
|
exports.curry2 = curry2;
|
|
644
675
|
exports.curry3 = curry3;
|
|
676
|
+
exports.debounce = debounce;
|
|
645
677
|
exports.diff = diff;
|
|
646
678
|
exports.divide = divide;
|
|
647
679
|
exports.echo = echo;
|
|
@@ -747,6 +779,7 @@ exports.tail = tail;
|
|
|
747
779
|
exports.take = take;
|
|
748
780
|
exports.tap = tap;
|
|
749
781
|
exports.test = test;
|
|
782
|
+
exports.throttle = throttle;
|
|
750
783
|
exports.toLower = toLower;
|
|
751
784
|
exports.toPairs = toPairs;
|
|
752
785
|
exports.toUpper = toUpper;
|
|
@@ -757,6 +790,7 @@ exports.uncurry = uncurry;
|
|
|
757
790
|
exports.uniq = uniq;
|
|
758
791
|
exports.uniqWith = uniqWith;
|
|
759
792
|
exports.values = values;
|
|
793
|
+
exports.wait = wait;
|
|
760
794
|
exports.waitAll = waitAll;
|
|
761
795
|
exports.waitTap = waitTap;
|
|
762
796
|
exports.weakEq = weakEq;
|
package/dist/bundle.d.ts
CHANGED
|
@@ -15,8 +15,7 @@ type StrLen<S extends string, Acc extends 0[] = [
|
|
|
15
15
|
0
|
|
16
16
|
]> : Acc["length"];
|
|
17
17
|
export type Cond = (x1?: any, x2?: any, x3?: any) => boolean;
|
|
18
|
-
export interface AnyObject {
|
|
19
|
-
[k: string]: any;
|
|
18
|
+
export interface AnyObject extends Record<any, any> {
|
|
20
19
|
}
|
|
21
20
|
export type Reducer<T = any> = (accum: T, cur: any, index: number) => T;
|
|
22
21
|
export type AnyFunc<ReturnT = any, Args extends AnyArgs = AnyArgs> = (...args: Args) => ReturnT;
|
|
@@ -44,7 +43,7 @@ export declare const typeIs: {
|
|
|
44
43
|
(a: string): (b: any) => boolean;
|
|
45
44
|
(a: string, b: any): boolean;
|
|
46
45
|
};
|
|
47
|
-
declare const length$1: <T extends
|
|
46
|
+
declare const length$1: <T extends AnyArray | string>(s: T) => T extends string ? StrLen<T> : T["length"];
|
|
48
47
|
export declare const isNil: (s: any) => boolean;
|
|
49
48
|
export declare const eq: {
|
|
50
49
|
(a: symbol, b: any): (a: any) => boolean;
|
|
@@ -210,8 +209,8 @@ export declare const divide: {
|
|
|
210
209
|
(a: number): (b: number) => number;
|
|
211
210
|
(a: number, b: number): number;
|
|
212
211
|
};
|
|
213
|
-
export declare const always: <T extends
|
|
214
|
-
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;
|
|
215
214
|
export declare const trim: (s: string) => string;
|
|
216
215
|
/** @param start string | any[] @param s string | any[] */
|
|
217
216
|
export declare const startsWith: {
|
|
@@ -289,7 +288,7 @@ export declare const noop: (...args: any[]) => any;
|
|
|
289
288
|
* @param {string} fnName - property name of the function.
|
|
290
289
|
* @param {AnyObject} o - the object with the function. */
|
|
291
290
|
export declare const callFrom: (...args: AnyArgs) => any;
|
|
292
|
-
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);
|
|
293
292
|
export declare const sizeof: (s: any[] | string | AnyObject) => number;
|
|
294
293
|
export declare const range: {
|
|
295
294
|
(a: symbol, b: number): (a: number) => any[];
|
|
@@ -325,7 +324,7 @@ export declare const genBy: {
|
|
|
325
324
|
(a: (i: number) => any, b: number): any[];
|
|
326
325
|
};
|
|
327
326
|
export declare const once: <Func extends AnyFunc>(fn: Func) => (...args: Parameters<Func>) => any;
|
|
328
|
-
export declare const reverse: <T extends
|
|
327
|
+
export declare const reverse: <T extends any>(xs: T[]) => T[];
|
|
329
328
|
export declare const explore: (caption: string, level?: string) => (b: any) => any;
|
|
330
329
|
export declare const cond: {
|
|
331
330
|
(a: symbol, b: any): (a: [
|
|
@@ -351,7 +350,7 @@ export declare const cond: {
|
|
|
351
350
|
* @param object AnyObject
|
|
352
351
|
*/
|
|
353
352
|
export declare const assoc: (...args: AnyArgs) => any;
|
|
354
|
-
export declare const assocPath: any;
|
|
353
|
+
export declare const assocPath: (...args: AnyArgs) => any;
|
|
355
354
|
export declare const all: {
|
|
356
355
|
(a: symbol, b: any[]): (a: Cond) => boolean;
|
|
357
356
|
(a: Cond, b: symbol): (b: any[]) => boolean;
|
|
@@ -387,7 +386,7 @@ export declare const prop: {
|
|
|
387
386
|
export declare const propEq: (...args: AnyArgs) => any;
|
|
388
387
|
/** @param key string @param o1 AnyObject @param o2 AnyObject @returns o₁[key] equals o₂[key] */
|
|
389
388
|
export declare const propsEq: (...args: AnyArgs) => any;
|
|
390
|
-
export declare const pathOr: any;
|
|
389
|
+
export declare const pathOr: (...args: AnyArgs) => any;
|
|
391
390
|
export declare const path: any;
|
|
392
391
|
export declare const pathEq: (...args: AnyArgs) => any;
|
|
393
392
|
export declare const pathsEq: (...args: AnyArgs) => any;
|
|
@@ -415,10 +414,10 @@ export declare const pickBy: {
|
|
|
415
414
|
(a: Cond, b: AnyObject): any;
|
|
416
415
|
};
|
|
417
416
|
export declare const omit: {
|
|
418
|
-
(a: symbol, b: AnyObject): (a: string[]) => any;
|
|
419
|
-
(a: string[], b: symbol): (b: AnyObject) => any;
|
|
420
|
-
(a: string[]): (b: AnyObject) => any;
|
|
421
|
-
(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;
|
|
422
421
|
};
|
|
423
422
|
export declare const fromPairs: (pairs: [
|
|
424
423
|
string,
|
|
@@ -439,10 +438,10 @@ export declare const map: {
|
|
|
439
438
|
(a: (s: any, i?: number, list?: any[]) => any, b: any[]): any[];
|
|
440
439
|
};
|
|
441
440
|
export declare const mapObj: {
|
|
442
|
-
(a: symbol, b: AnyObject): (a: (s: any, i?: string, list?: any[]) => any) => (b: AnyObject) =>
|
|
443
|
-
(a: (s: any, i?: string, list?: any[]) => any, b: symbol): (b: AnyObject) => (b: AnyObject) =>
|
|
444
|
-
(a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) => (b: AnyObject) =>
|
|
445
|
-
(a: (s: any, i?: string, list?: any[]) => any, b: AnyObject): (b: AnyObject) =>
|
|
441
|
+
(a: symbol, b: AnyObject): (a: (s: any, i?: string, list?: any[]) => any) => (b: AnyObject) => AnyObject;
|
|
442
|
+
(a: (s: any, i?: string, list?: any[]) => any, b: symbol): (b: AnyObject) => (b: AnyObject) => AnyObject;
|
|
443
|
+
(a: (s: any, i?: string, list?: any[]) => any): (b: AnyObject) => (b: AnyObject) => AnyObject;
|
|
444
|
+
(a: (s: any, i?: string, list?: any[]) => any, b: AnyObject): (b: AnyObject) => AnyObject;
|
|
446
445
|
};
|
|
447
446
|
export declare const join: {
|
|
448
447
|
(a: symbol, b: string[]): (a: string) => string;
|
|
@@ -461,20 +460,20 @@ export declare const isEmpty: (s: any) => boolean | null;
|
|
|
461
460
|
export declare const empty: (s: any) => {} | undefined;
|
|
462
461
|
export declare const replace: (...args: AnyArgs) => any;
|
|
463
462
|
export declare const filter: {
|
|
464
|
-
(a: symbol, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any;
|
|
465
|
-
(a: (v: any, k: string | number) => boolean, b: symbol): (b: any[] | AnyObject) => any;
|
|
466
|
-
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any;
|
|
467
|
-
(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;
|
|
468
467
|
};
|
|
469
468
|
/** Saves result of a function with given key and avoids calling it again.
|
|
470
469
|
* @param {(...args: Args) string} keyGen that takes the same args and returns a key for the cache.
|
|
471
470
|
* @param {(...args: Args) any} fn to be cached.
|
|
472
471
|
*/
|
|
473
472
|
export declare const memoize: {
|
|
474
|
-
(a: symbol, b: AnyFunc<any, any[]>): (a: (...args: any[]) => string) => (...args: any[]) => any
|
|
475
|
-
(a: (...args: any[]) => string, b: symbol): (b: AnyFunc<any, any[]>) => (...args: any[]) => any
|
|
476
|
-
(a: (...args: any[]) => string): (b: AnyFunc<any, any[]>) => (...args: any[]) => any
|
|
477
|
-
(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[]>>;
|
|
478
477
|
};
|
|
479
478
|
export declare const mergeShallow: {
|
|
480
479
|
(a: symbol, b: AnyObject): (a: AnyObject) => AnyObject;
|
|
@@ -539,7 +538,7 @@ export declare const zipWith: (...args: AnyArgs) => any;
|
|
|
539
538
|
export declare const mirror: <T extends unknown>(s: T) => T;
|
|
540
539
|
export declare const reflect: <T extends unknown>(s: T) => T;
|
|
541
540
|
export declare const echo: <T extends unknown>(s: T) => T;
|
|
542
|
-
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);
|
|
543
542
|
export declare const push: {
|
|
544
543
|
(a: symbol, b: any[]): (a: any) => any[];
|
|
545
544
|
(a: any, b: symbol): (b: any[]) => any[];
|
|
@@ -612,10 +611,10 @@ export declare const qmap: {
|
|
|
612
611
|
(a: (s: any, i?: number, list?: any[]) => any, b: any[]): any[];
|
|
613
612
|
};
|
|
614
613
|
export declare const qmapObj: {
|
|
615
|
-
(a: symbol, b: AnyObject): (a: (s: any, k?: string,
|
|
616
|
-
(a: (s: any, k?: string,
|
|
617
|
-
(a: (s: any, k?: string,
|
|
618
|
-
(a: (s: any, k?: string,
|
|
614
|
+
(a: symbol, b: AnyObject): (a: (s: any, k?: string, o?: AnyObject) => any) => AnyObject;
|
|
615
|
+
(a: (s: any, k?: string, o?: AnyObject) => any, b: symbol): (b: AnyObject) => AnyObject;
|
|
616
|
+
(a: (s: any, k?: string, o?: AnyObject) => any): (b: AnyObject) => AnyObject;
|
|
617
|
+
(a: (s: any, k?: string, o?: AnyObject) => any, b: AnyObject): AnyObject;
|
|
619
618
|
};
|
|
620
619
|
export declare const qfilter: {
|
|
621
620
|
(a: symbol, b: any[] | AnyObject): (a: (v: any, k: string | number) => boolean) => any[] | AnyObject;
|
|
@@ -623,7 +622,7 @@ export declare const qfilter: {
|
|
|
623
622
|
(a: (v: any, k: string | number) => boolean): (b: any[] | AnyObject) => any[] | AnyObject;
|
|
624
623
|
(a: (v: any, k: string | number) => boolean, b: any[] | AnyObject): any[] | AnyObject;
|
|
625
624
|
};
|
|
626
|
-
export declare const qempty: <T extends any[]
|
|
625
|
+
export declare const qempty: <T extends AnyObject | any[]>(o: T) => T extends any[] ? [
|
|
627
626
|
] : {};
|
|
628
627
|
export declare const qfreeze: <T extends AnyObject>(o: T) => Readonly<T>;
|
|
629
628
|
export declare const qfreezeShallow: <T extends AnyObject>(o: T) => Readonly<T>;
|
|
@@ -633,7 +632,7 @@ export declare const qprepend: {
|
|
|
633
632
|
(a: any): (b: any[]) => number;
|
|
634
633
|
(a: any, b: any[]): number;
|
|
635
634
|
};
|
|
636
|
-
export declare const qassocPath: any;
|
|
635
|
+
export declare const qassocPath: (...args: AnyArgs) => any;
|
|
637
636
|
export declare const qreverse: (arr: any[]) => any[];
|
|
638
637
|
export declare const qomit: {
|
|
639
638
|
(a: symbol, b: AnyObject): (a: string[]) => any[] | AnyObject;
|
|
@@ -655,6 +654,9 @@ type StrTmpl = ((data: AnyObject) => string);
|
|
|
655
654
|
/** Supports ecrans: '\\{"json": {yes} \\}'
|
|
656
655
|
@returns getTmpl('one{meme}two')({meme: 42}) -> one42two */
|
|
657
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>;
|
|
658
660
|
/** One promise waits for another. */
|
|
659
661
|
export declare const forEachSerial: {
|
|
660
662
|
(a: symbol, b: any[]): (a: AnyFunc) => Promise<void>;
|
package/dist/bundle.mjs
CHANGED
|
@@ -197,7 +197,11 @@ const qmap = curry2((pipe, arr) => {
|
|
|
197
197
|
arr[i] = pipe(arr[i], +i, arr);
|
|
198
198
|
return arr;
|
|
199
199
|
});
|
|
200
|
-
const qmapObj = curry2((pipe, o) =>
|
|
200
|
+
const qmapObj = curry2((pipe, o) => {
|
|
201
|
+
for (const k in o)
|
|
202
|
+
o[k] = pipe(o[k], k, o);
|
|
203
|
+
return o;
|
|
204
|
+
});
|
|
201
205
|
const qfilter = curry2((cond, data) => {
|
|
202
206
|
const isArr = isArray(data);
|
|
203
207
|
let indicies_offset, indicies2rm;
|
|
@@ -295,7 +299,7 @@ const lt = curry2((a, b) => a > b);
|
|
|
295
299
|
const gte = curry2((a, b) => a <= b);
|
|
296
300
|
/** @param a @param b @returns a≥b */
|
|
297
301
|
const lte = curry2((a, b) => a >= b);
|
|
298
|
-
const sort = curry2((sortFn, xs) => xs.sort(sortFn));
|
|
302
|
+
const sort = curry2((sortFn, xs) => xs.sort(sortFn)); // TODO: make it shallow cloning.
|
|
299
303
|
const find = curry2((fn, s) => s.find(fn));
|
|
300
304
|
const findIndex = curry2((fn, s) => s.findIndex(fn));
|
|
301
305
|
const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
|
|
@@ -332,7 +336,7 @@ const complement = (fn) => (...args) => {
|
|
|
332
336
|
return !f || f && out.$args_left <= 0 ? not(out) : complement(out);
|
|
333
337
|
};
|
|
334
338
|
const sizeof = (s) => {
|
|
335
|
-
if (
|
|
339
|
+
if (isObj(s)) {
|
|
336
340
|
let len = 0;
|
|
337
341
|
for (let _k in s)
|
|
338
342
|
len++;
|
|
@@ -588,6 +592,33 @@ const getTmpl = (tmpl) => {
|
|
|
588
592
|
};
|
|
589
593
|
};
|
|
590
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
|
+
|
|
591
622
|
/** One promise waits for another. */
|
|
592
623
|
const forEachSerial = (() => {
|
|
593
624
|
const pipe = async (fn, items, i) => {
|
|
@@ -614,4 +645,4 @@ const composeAsync = (() => {
|
|
|
614
645
|
return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
|
|
615
646
|
})();
|
|
616
647
|
|
|
617
|
-
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
|
@@ -69,7 +69,10 @@ export const qmap = curry2(
|
|
|
69
69
|
}
|
|
70
70
|
)
|
|
71
71
|
export const qmapObj = curry2(
|
|
72
|
-
(pipe: (s: any, k?: string,
|
|
72
|
+
(pipe: (s: any, k?: string, o?: AnyObject) => any, o: AnyObject) => {
|
|
73
|
+
for(const k in o) o[k] = pipe(o[k], k, o)
|
|
74
|
+
return o
|
|
75
|
+
}
|
|
73
76
|
)
|
|
74
77
|
export const qfilter = curry2(
|
|
75
78
|
<T extends any[] | AnyObject>(
|
|
@@ -107,6 +110,7 @@ export const qfreeze = <T extends AnyObject>(o: T): Readonly<T> => {
|
|
|
107
110
|
}
|
|
108
111
|
export const qfreezeShallow = <T extends AnyObject>(o: T): Readonly<T> => Object.freeze(o)
|
|
109
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))
|
|
110
114
|
export const qassocPath = curry3((_path: string[], v: any, o: AnyObject) => {
|
|
111
115
|
const first = _path[0]
|
|
112
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))
|
package/src/types.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnyArgs } from "./internal_types"
|
|
2
2
|
|
|
3
3
|
export type Cond = (x1?: any, x2?: any, x3?: any) => boolean
|
|
4
|
-
export interface AnyObject
|
|
4
|
+
export interface AnyObject extends Record<any, any> {}
|
|
5
5
|
export type Reducer<T=any> = (accum: T, cur: any, index: number) => T
|
|
6
6
|
export type AnyFunc<ReturnT = any, Args extends AnyArgs = AnyArgs> = (...args: Args) => ReturnT
|
|
7
7
|
export type Curried<Args extends AnyArgs = AnyArgs, ReturnT = any> = (arg: Args[number]) => Curried<Args> | ReturnT
|