pepka 1.6.2 → 1.6.4

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 CHANGED
@@ -71,6 +71,9 @@ 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;
@@ -100,7 +103,7 @@ 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
@@ -301,7 +305,7 @@ const lt = curry2((a, b) => a > b);
301
305
  const gte = curry2((a, b) => a <= b);
302
306
  /** @param a @param b @returns a≥b */
303
307
  const lte = curry2((a, b) => a >= b);
304
- const sort = curry2((sortFn, xs) => xs.sort(sortFn));
308
+ const sort = curry2((sortFn, xs) => [...xs].sort(sortFn));
305
309
  const find = curry2((fn, s) => s.find(fn));
306
310
  const findIndex = curry2((fn, s) => s.findIndex(fn));
307
311
  const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
@@ -338,7 +342,7 @@ const complement = (fn) => (...args) => {
338
342
  return !f || f && out.$args_left <= 0 ? not(out) : complement(out);
339
343
  };
340
344
  const sizeof = (s) => {
341
- if (type(s) === 'Object') {
345
+ if (isObj(s)) {
342
346
  let len = 0;
343
347
  for (let _k in s)
344
348
  len++;
@@ -426,7 +430,6 @@ const path = pathOr(undef);
426
430
  const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
427
431
  const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
428
432
  const pathExists = compose(ifElse(equals(symbol), F, T), pathOr(symbol));
429
- const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
430
433
  const clone = (s, shallow = false) => {
431
434
  const t = type(s);
432
435
  switch (t) {
@@ -445,7 +448,7 @@ const clone = (s, shallow = false) => {
445
448
  case 'Symbol':
446
449
  return s;
447
450
  default:
448
- return typed_arr_re.test(t) ? s.constructor.from(s) : s;
451
+ return is_typed_arr(t) ? s.constructor.from(s) : s;
449
452
  }
450
453
  };
451
454
  const cloneShallow = (s) => clone(s, true);
@@ -469,7 +472,7 @@ const omit = curry2((props, o) => filter((_, k) => !includes(k, props), o));
469
472
  const fromPairs = (pairs) => Object.fromEntries(pairs);
470
473
  const concat = curry2(((a, b) => b.concat(a)));
471
474
  const map = curry2((pipe, arr) => arr.map(pipe));
472
- const mapObj = curry2((pipe, o) => qmapObj(pipe, cloneShallow(o)));
475
+ const mapObj = curry2((pipe, o) => qmapObj(pipe, { ...o }));
473
476
  const join = curry2((delimeter, arr) => arr.join(delimeter));
474
477
  const forEach = curry2((pipe, arr) => arr.forEach(pipe));
475
478
  const both = curry3((cond1, cond2, s) => cond2(s) && cond1(s));
@@ -594,6 +597,33 @@ const getTmpl = (tmpl) => {
594
597
  };
595
598
  };
596
599
 
600
+ const debounce = (time, fn) => {
601
+ let queue = [];
602
+ let to;
603
+ return ((...args) => new Promise((ff) => {
604
+ clearTimeout(to);
605
+ to = setTimeout(async () => {
606
+ const res = await fn(...args);
607
+ for (ff of queue)
608
+ ff(res);
609
+ queue.splice(0);
610
+ }, time);
611
+ queue.push(ff);
612
+ }));
613
+ };
614
+ // export const debouncePrepared =
615
+ const throttle = (time, fn) => {
616
+ let on = true;
617
+ return (...args) => {
618
+ if (on) {
619
+ on = false;
620
+ setTimeout(() => on = true, time);
621
+ return fn(...args);
622
+ }
623
+ };
624
+ };
625
+ const wait = (time) => new Promise((ff) => setTimeout(ff, time));
626
+
597
627
  /** One promise waits for another. */
598
628
  const forEachSerial = (() => {
599
629
  const pipe = async (fn, items, i) => {
@@ -646,6 +676,7 @@ exports.cond = cond;
646
676
  exports.curry = curry;
647
677
  exports.curry2 = curry2;
648
678
  exports.curry3 = curry3;
679
+ exports.debounce = debounce;
649
680
  exports.diff = diff;
650
681
  exports.divide = divide;
651
682
  exports.echo = echo;
@@ -732,6 +763,7 @@ exports.qoverProp = qoverProp;
732
763
  exports.qprepend = qprepend;
733
764
  exports.qreduce = qreduce;
734
765
  exports.qreverse = qreverse;
766
+ exports.qsort = qsort;
735
767
  exports.qstartsWith = qstartsWith;
736
768
  exports.qstartsWithWith = qstartsWithWith;
737
769
  exports.range = range;
@@ -751,6 +783,7 @@ exports.tail = tail;
751
783
  exports.take = take;
752
784
  exports.tap = tap;
753
785
  exports.test = test;
786
+ exports.throttle = throttle;
754
787
  exports.toLower = toLower;
755
788
  exports.toPairs = toPairs;
756
789
  exports.toUpper = toUpper;
@@ -761,6 +794,7 @@ exports.uncurry = uncurry;
761
794
  exports.uniq = uniq;
762
795
  exports.uniqWith = uniqWith;
763
796
  exports.values = values;
797
+ exports.wait = wait;
764
798
  exports.waitAll = waitAll;
765
799
  exports.waitTap = waitTap;
766
800
  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 string | AnyArray>(s: T) => T extends string ? StrLen<T> : T["length"];
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;
@@ -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: any[]): (a: (a: any, b: any) => number) => any[];
184
- (a: (a: any, b: any) => number, b: symbol): (b: any[]) => any[];
185
- (a: (a: any, b: any) => number): (b: any[]) => any[];
186
- (a: (a: any, b: any) => number, b: any[]): any[];
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;
@@ -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 unknown>(s: T) => () => T;
213
- export declare const identity: <T extends unknown>(s: T) => T;
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 unknown>(xs: T[]) => T[];
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,
@@ -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) => (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;
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,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[] | AnyObject>(o: T) => 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,13 @@ 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 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
+ };
641
+ export declare const qassocPath: (...args: AnyArgs) => any;
636
642
  export declare const qreverse: (arr: any[]) => any[];
637
643
  export declare const qomit: {
638
644
  (a: symbol, b: AnyObject): (a: string[]) => any[] | AnyObject;
@@ -654,6 +660,9 @@ type StrTmpl = ((data: AnyObject) => string);
654
660
  /** Supports ecrans: '\\{"json": {yes} \\}'
655
661
  @returns getTmpl('one{meme}two')({meme: 42}) -> one42two */
656
662
  export declare const getTmpl: (tmpl: string) => StrTmpl;
663
+ export declare const debounce: <T extends AnyFunc>(time: number, fn: T) => (...args: Parameters<T>) => Promise<ReturnType<T>>;
664
+ export declare const throttle: <T extends AnyFunc>(time: number, fn: T) => (...args: Parameters<T>) => any;
665
+ export declare const wait: (time: number) => Promise<unknown>;
657
666
  /** One promise waits for another. */
658
667
  export declare const forEachSerial: {
659
668
  (a: symbol, b: any[]): (a: AnyFunc) => Promise<void>;
package/dist/bundle.mjs CHANGED
@@ -69,6 +69,9 @@ 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;
@@ -98,7 +101,7 @@ 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
@@ -299,7 +303,7 @@ const lt = curry2((a, b) => a > b);
299
303
  const gte = curry2((a, b) => a <= b);
300
304
  /** @param a @param b @returns a≥b */
301
305
  const lte = curry2((a, b) => a >= b);
302
- const sort = curry2((sortFn, xs) => xs.sort(sortFn));
306
+ const sort = curry2((sortFn, xs) => [...xs].sort(sortFn));
303
307
  const find = curry2((fn, s) => s.find(fn));
304
308
  const findIndex = curry2((fn, s) => s.findIndex(fn));
305
309
  const indexOf = curry2((x, xs) => findIndex(equals(x), xs));
@@ -336,7 +340,7 @@ const complement = (fn) => (...args) => {
336
340
  return !f || f && out.$args_left <= 0 ? not(out) : complement(out);
337
341
  };
338
342
  const sizeof = (s) => {
339
- if (type(s) === 'Object') {
343
+ if (isObj(s)) {
340
344
  let len = 0;
341
345
  for (let _k in s)
342
346
  len++;
@@ -424,7 +428,6 @@ const path = pathOr(undef);
424
428
  const pathEq = curry3((_path, value, o) => equals(path(_path, o), value));
425
429
  const pathsEq = curry3((_path, o1, o2) => equals(path(_path, o1), path(_path, o2)));
426
430
  const pathExists = compose(ifElse(equals(symbol), F, T), pathOr(symbol));
427
- const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/;
428
431
  const clone = (s, shallow = false) => {
429
432
  const t = type(s);
430
433
  switch (t) {
@@ -443,7 +446,7 @@ const clone = (s, shallow = false) => {
443
446
  case 'Symbol':
444
447
  return s;
445
448
  default:
446
- return typed_arr_re.test(t) ? s.constructor.from(s) : s;
449
+ return is_typed_arr(t) ? s.constructor.from(s) : s;
447
450
  }
448
451
  };
449
452
  const cloneShallow = (s) => clone(s, true);
@@ -467,7 +470,7 @@ const omit = curry2((props, o) => filter((_, k) => !includes(k, props), o));
467
470
  const fromPairs = (pairs) => Object.fromEntries(pairs);
468
471
  const concat = curry2(((a, b) => b.concat(a)));
469
472
  const map = curry2((pipe, arr) => arr.map(pipe));
470
- const mapObj = curry2((pipe, o) => qmapObj(pipe, cloneShallow(o)));
473
+ const mapObj = curry2((pipe, o) => qmapObj(pipe, { ...o }));
471
474
  const join = curry2((delimeter, arr) => arr.join(delimeter));
472
475
  const forEach = curry2((pipe, arr) => arr.forEach(pipe));
473
476
  const both = curry3((cond1, cond2, s) => cond2(s) && cond1(s));
@@ -592,6 +595,33 @@ const getTmpl = (tmpl) => {
592
595
  };
593
596
  };
594
597
 
598
+ const debounce = (time, fn) => {
599
+ let queue = [];
600
+ let to;
601
+ return ((...args) => new Promise((ff) => {
602
+ clearTimeout(to);
603
+ to = setTimeout(async () => {
604
+ const res = await fn(...args);
605
+ for (ff of queue)
606
+ ff(res);
607
+ queue.splice(0);
608
+ }, time);
609
+ queue.push(ff);
610
+ }));
611
+ };
612
+ // export const debouncePrepared =
613
+ const throttle = (time, fn) => {
614
+ let on = true;
615
+ return (...args) => {
616
+ if (on) {
617
+ on = false;
618
+ setTimeout(() => on = true, time);
619
+ return fn(...args);
620
+ }
621
+ };
622
+ };
623
+ const wait = (time) => new Promise((ff) => setTimeout(ff, time));
624
+
595
625
  /** One promise waits for another. */
596
626
  const forEachSerial = (() => {
597
627
  const pipe = async (fn, items, i) => {
@@ -618,4 +648,4 @@ const composeAsync = (() => {
618
648
  return (...fns) => (...input) => pipe(fns, input, fns.length - 1);
619
649
  })();
620
650
 
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 };
651
+ export { F, T, __, add, all, allPass, always, any, anyPass, append, assoc, assocPath, bind, both, callFrom, callWith, clone, cloneShallow, complement, compose, composeAsync, concat, cond, curry, curry2, curry3, debounce, diff, divide, echo, empty, eq, equals, explore, filter, find, findIndex, flat, flatShallow, flatTo, flip, forEach, forEachAsync, forEachSerial, freeze, freezeShallow, fromPairs, genBy, getTmpl, gt, gte, head, identity, ifElse, includes, indexOf, intersection, isEmpty, isNil, join, keys, last, length, lt, lte, map, mapKeys, mapObj, memoize, mergeDeep, mergeDeepAdd, mergeDeepX, mergeShallow, mirror, multiply, noop, not, notf, nth, omit, once, overProp, path, pathEq, pathExists, pathOr, pathsEq, pick, pickBy, prepend, prop, propEq, propsEq, push, qappend, qassoc, qassocPath, qempty, qfilter, qfreeze, qfreezeShallow, qmap, qmapKeys, qmapObj, qmergeDeep, qmergeDeepAdd, qmergeDeepX, qmergeShallow, qomit, qoverProp, qprepend, qreduce, qreverse, qsort, qstartsWith, qstartsWithWith, range, reduce, reflect, replace, reverse, sizeof, slice, some, sort, split, startsWith, subtract, symbol, tail, take, tap, test, throttle, toLower, toPairs, toUpper, trim, type, typeIs, uncurry, uniq, uniqWith, values, wait, waitAll, waitTap, weakEq, when, zip, zipObj, zipWith };
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",
@@ -21,6 +22,7 @@
21
22
  "type": "module",
22
23
  "exports": {
23
24
  ".": {
25
+ "types": "./dist/bundle.d.ts",
24
26
  "import": "./dist/bundle.mjs",
25
27
  "require": "./dist/bundle.cjs"
26
28
  }
@@ -32,9 +34,6 @@
32
34
  },
33
35
  "scripts": {
34
36
  "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
37
  "gentypes": "dts-bundle-generator --no-check --export-referenced-types=false -o dist/bundle.d.ts src/index.ts",
39
38
  "dev": "cross-env NODE_ENV=development BUILD=es rollup -c",
40
39
  "prod:cjs": "cross-env NODE_ENV=production BUILD=cjs rollup -c",
@@ -42,37 +41,19 @@
42
41
  "prod": "npm run gentypes && npm run prod:es && npm run prod:cjs",
43
42
  "all": "npm run dev && npm run prod"
44
43
  },
45
- "version": "1.6.2",
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
- },
44
+ "version": "1.6.4",
59
45
  "devDependencies": {
60
- "@rollup/plugin-commonjs": "^25.0.7",
61
- "@rollup/plugin-node-resolve": "^15.2.3",
62
- "@rollup/plugin-replace": "^5.0.5",
63
- "@types/node": "^20.12.7",
64
- "ava": "^6.1.2",
65
- "codecov": "^3.8.3",
46
+ "@rollup/plugin-commonjs": "^28.0.3",
47
+ "@rollup/plugin-node-resolve": "^16.0.0",
48
+ "@rollup/plugin-replace": "^6.0.2",
49
+ "@types/node": "^22.13.10",
66
50
  "cross-env": "^7.0.3",
67
51
  "dts-bundle-generator": "^9.5.1",
68
- "nyc": "^15.1.0",
69
- "prepend": "^1.0.2",
70
- "rollup": "^4.17.0",
52
+ "rollup": "^4.35.0",
71
53
  "rollup-plugin-typescript2": "^0.36.0",
72
54
  "ts-node": "^10.9.2",
73
55
  "tslint": "^6.1.3",
74
- "typescript": "^5.4.5"
56
+ "typescript": "^5.8.2"
75
57
  },
76
- "types": "./dist/bundle.d.ts",
77
58
  "sideEffects": false
78
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
 
@@ -21,7 +22,7 @@ export const isNil = (s: any) => isNull(s) || isUndef(s)
21
22
  export const eq = curry2((a: any, b: any) => a===b)
22
23
  export const equals = curry2((a: any, b: any) => {
23
24
  const typea = type(a)
24
- if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array'))) {
25
+ if(eq(typea, type(b)) && (eq(typea, 'Object') || eq(typea, 'Array') || is_typed_arr(typea))) {
25
26
  if(isNull(a) || isNull(b)) return eq(a, b)
26
27
  if(eq(a, b)) return true
27
28
  for(const v of [a, b])
package/src/index.ts CHANGED
@@ -5,5 +5,6 @@ export * from './common'
5
5
  export * from './safe'
6
6
  export * from './quick'
7
7
  export * from './strings'
8
+ export * from './timers'
8
9
  export * from './async'
9
10
  export * from './types'
@@ -0,0 +1,2 @@
1
+ const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/
2
+ export const is_typed_arr = (t: string) => typed_arr_re.test(t)
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,9 +1,10 @@
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'
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]
@@ -97,7 +98,7 @@ export const lt = curry2( (a: number, b: number) => a>b )
97
98
  export const gte = curry2( (a: number, b: number) => a<=b )
98
99
  /** @param a @param b @returns a≥b */
99
100
  export const lte = curry2( (a: number, b: number) => a>=b )
100
- export const sort = curry2((sortFn: (a: any, b: any) => number , xs: any[]) => xs.sort(sortFn))
101
+ export const sort = curry2(<T extends any>(sortFn: (a: T, b: T) => number , xs: T[]) => [...xs].sort(sortFn))
101
102
  export const find = curry2((fn: Cond, s: any[]) => s.find(fn))
102
103
  export const findIndex = curry2((fn: Cond, s: any[]) => s.findIndex(fn))
103
104
  export const indexOf = curry2((x: any, xs: any[]) => findIndex(equals(x), xs))
@@ -145,7 +146,7 @@ export const complement = (fn: AnyFunc) => (...args: any) => {
145
146
  return !f || f&&out.$args_left<=0 ? not(out) : complement(out)
146
147
  }
147
148
  export const sizeof = (s: any[] | string | AnyObject) => {
148
- if(type(s) === 'Object') {
149
+ if(isObj(s)) {
149
150
  let len = 0
150
151
  for(let _k in s as AnyObject) len++
151
152
  return len
@@ -260,7 +261,6 @@ export const pathsEq = curry3(
260
261
  equals(path(_path, o1), path(_path, o2))
261
262
  )
262
263
  export const pathExists = compose(ifElse(equals(symbol), F, T), pathOr(symbol))
263
- const typed_arr_re = /^(.*?)(8|16|32|64)(Clamped)?Array$/
264
264
  export const clone = (s: any, shallow = false) => {
265
265
  const t = type(s)
266
266
  switch(t) {
@@ -275,7 +275,7 @@ export const clone = (s: any, shallow = false) => {
275
275
  case 'Boolean': case 'Symbol':
276
276
  return s
277
277
  default:
278
- return typed_arr_re.test(t) ? s.constructor.from(s) : s
278
+ return is_typed_arr(t) ? s.constructor.from(s) : s
279
279
  }
280
280
  }
281
281
  export const cloneShallow = (s: any) => clone(s, true)
@@ -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, cloneShallow(o))
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
- const qel = async () => {
8
- clearTimeout(to)
9
- to = setTimeout(async () => {
10
- const res = await fn!(...args)
11
- if(queue.includes(qel)) ff(res)
12
- }, time)
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))