es-toolkit 1.21.0-dev.668 → 1.21.0-dev.670

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.
@@ -57,6 +57,7 @@ export { MemoizeCache, memoize } from '../function/memoize.mjs';
57
57
  export { unary } from '../function/unary.mjs';
58
58
  export { partial } from '../function/partial.mjs';
59
59
  export { partialRight } from '../function/partialRight.mjs';
60
+ export { flow } from '../function/flow.mjs';
60
61
  export { mean } from '../math/mean.mjs';
61
62
  export { meanBy } from '../math/meanBy.mjs';
62
63
  export { randomInt } from '../math/randomInt.mjs';
@@ -57,6 +57,7 @@ export { MemoizeCache, memoize } from '../function/memoize.js';
57
57
  export { unary } from '../function/unary.js';
58
58
  export { partial } from '../function/partial.js';
59
59
  export { partialRight } from '../function/partialRight.js';
60
+ export { flow } from '../function/flow.js';
60
61
  export { mean } from '../math/mean.js';
61
62
  export { meanBy } from '../math/meanBy.js';
62
63
  export { randomInt } from '../math/randomInt.js';
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const zipWith = require('../_chunk/zipWith-DEcUS4.js');
6
6
  const promise_index = require('../_chunk/index-BGZDR9.js');
7
- const rest$1 = require('../_chunk/rest-pUyjvl.js');
7
+ const flow = require('../_chunk/flow-Au34h2.js');
8
8
  const range = require('../_chunk/range-BXlMmn.js');
9
9
  const randomInt = require('../_chunk/randomInt-CF7bZK.js');
10
10
  const toMerged = require('../_chunk/toMerged-DVBECd.js');
@@ -730,7 +730,7 @@ function ary(func, n = func.length, guard) {
730
730
  if (Number.isNaN(n) || n < 0) {
731
731
  n = 0;
732
732
  }
733
- return rest$1.ary(func, n);
733
+ return flow.ary(func, n);
734
734
  }
735
735
 
736
736
  function bind(func, thisObj, ...partialArgs) {
@@ -797,7 +797,7 @@ function rest(func, start = func.length - 1) {
797
797
  if (Number.isNaN(start) || start < 0) {
798
798
  start = func.length - 1;
799
799
  }
800
- return rest$1.rest(func, start);
800
+ return flow.rest(func, start);
801
801
  }
802
802
 
803
803
  function spread(func, argsIndex = 0) {
@@ -905,7 +905,7 @@ function debounce(func, debounceMs = 0, options = {}) {
905
905
  }
906
906
  let result = undefined;
907
907
  let pendingAt = null;
908
- const _debounced = rest$1.debounce(function (...args) {
908
+ const _debounced = flow.debounce(function (...args) {
909
909
  result = func.apply(this, args);
910
910
  pendingAt = null;
911
911
  }, debounceMs, { signal, edges });
@@ -1211,7 +1211,7 @@ function mergeWithDeep(target, source, merge, stack) {
1211
1211
  }
1212
1212
 
1213
1213
  function merge(object, ...sources) {
1214
- return mergeWith(object, ...sources, rest$1.noop);
1214
+ return mergeWith(object, ...sources, flow.noop);
1215
1215
  }
1216
1216
 
1217
1217
  function isArrayLike(value) {
@@ -1702,15 +1702,16 @@ exports.TimeoutError = promise_index.TimeoutError;
1702
1702
  exports.delay = promise_index.delay;
1703
1703
  exports.timeout = promise_index.timeout;
1704
1704
  exports.withTimeout = promise_index.withTimeout;
1705
- exports.after = rest$1.after;
1706
- exports.before = rest$1.before;
1707
- exports.memoize = rest$1.memoize;
1708
- exports.negate = rest$1.negate;
1709
- exports.noop = rest$1.noop;
1710
- exports.once = rest$1.once;
1711
- exports.partial = rest$1.partial;
1712
- exports.partialRight = rest$1.partialRight;
1713
- exports.unary = rest$1.unary;
1705
+ exports.after = flow.after;
1706
+ exports.before = flow.before;
1707
+ exports.flow = flow.flow;
1708
+ exports.memoize = flow.memoize;
1709
+ exports.negate = flow.negate;
1710
+ exports.noop = flow.noop;
1711
+ exports.once = flow.once;
1712
+ exports.partial = flow.partial;
1713
+ exports.partialRight = flow.partialRight;
1714
+ exports.unary = flow.unary;
1714
1715
  exports.mean = range.mean;
1715
1716
  exports.meanBy = range.meanBy;
1716
1717
  exports.range = range.range;
@@ -57,6 +57,7 @@ export { memoize } from '../function/memoize.mjs';
57
57
  export { unary } from '../function/unary.mjs';
58
58
  export { partial } from '../function/partial.mjs';
59
59
  export { partialRight } from '../function/partialRight.mjs';
60
+ export { flow } from '../function/flow.mjs';
60
61
  export { mean } from '../math/mean.mjs';
61
62
  export { meanBy } from '../math/meanBy.mjs';
62
63
  export { randomInt } from '../math/randomInt.mjs';
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
3
+ *
4
+ * @param {() => R} f The function to invoke.
5
+ * @returns {() => R} Returns the new composite function.
6
+ *
7
+ * @example
8
+ * function noArgFunc() {
9
+ * return 42;
10
+ * }
11
+ *
12
+ * const combined = flow(noArgFunc);
13
+ * console.log(combined()); // 42
14
+ */
15
+ declare function flow<R>(f: () => R): () => R;
16
+ /**
17
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
18
+ *
19
+ * @param {(...args: A) => R} f1 The function to invoke.
20
+ * @returns {(...args: A) => R} Returns the new composite function.
21
+ *
22
+ * @example
23
+ * function oneArgFunc(a: number) {
24
+ * return a * 2;
25
+ * }
26
+ *
27
+ * const combined = flow(oneArgFunc);
28
+ * console.log(combined(5)); // 10
29
+ */
30
+ declare function flow<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
31
+ /**
32
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
33
+ *
34
+ * @param {(...args: A) => R1} f1 The function to invoke.
35
+ * @param {(a: R1) => R2} f2 The function to invoke.
36
+ * @returns {(...args: A) => R2} Returns the new composite function.
37
+ *
38
+ * @example
39
+ * const add = (x: number, y: number) => x + y;
40
+ * const square = (n: number) => n * n;
41
+ *
42
+ * const combined = flow(add, square);
43
+ * console.log(combined(1, 2)); // 9
44
+ */
45
+ declare function flow<A extends any[], R1, R2>(f1: (...args: A) => R1, f2: (a: R1) => R2): (...args: A) => R2;
46
+ /**
47
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
48
+ *
49
+ * @param {(...args: A) => R1} f1 The function to invoke.
50
+ * @param {(a: R1) => R2} f2 The function to invoke.
51
+ * @param {(a: R2) => R3} f3 The function to invoke.
52
+ * @returns {(...args: A) => R3} Returns the new composite function.
53
+ *
54
+ * @example
55
+ * const add = (x: number, y: number) => x + y;
56
+ * const square = (n: number) => n * n;
57
+ * const double = (n: number) => n * 2;
58
+ *
59
+ * const combined = flow(add, square, double);
60
+ * console.log(combined(1, 2)); // 18
61
+ */
62
+ declare function flow<A extends any[], R1, R2, R3>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: A) => R3;
63
+ /**
64
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
65
+ *
66
+ * @param {(...args: A) => R1} f1 The function to invoke.
67
+ * @param {(a: R1) => R2} f2 The function to invoke.
68
+ * @param {(a: R2) => R3} f3 The function to invoke.
69
+ * @param {(a: R3) => R4} f4 The function to invoke.
70
+ * @returns {(...args: A) => R4} Returns the new composite function.
71
+ *
72
+ * @example
73
+ * const add = (x: number, y: number) => x + y;
74
+ * const square = (n: number) => n * n;
75
+ * const double = (n: number) => n * 2;
76
+ * const toStr = (n: number) => n.toString();
77
+ *
78
+ * const combined = flow(add, square, double, toStr);
79
+ * console.log(combined(1, 2)); // '18'
80
+ */
81
+ declare function flow<A extends any[], R1, R2, R3, R4>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4): (...args: A) => R4;
82
+ /**
83
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
84
+ *
85
+ * @param {(...args: A) => R1} f1 The function to invoke.
86
+ * @param {(a: R1) => R2} f2 The function to invoke.
87
+ * @param {(a: R2) => R3} f3 The function to invoke.
88
+ * @param {(a: R3) => R4} f4 The function to invoke.
89
+ * @param {(a: R4) => R5} f5 The function to invoke.
90
+ * @returns {(...args: A) => R5} Returns the new composite function.
91
+ *
92
+ * @example
93
+ * const add = (x: number, y: number) => x + y;
94
+ * const square = (n: number) => n * n;
95
+ * const double = (n: number) => n * 2;
96
+ * const toStr = (n: number) => n.toString();
97
+ * const split = (s: string) => s.split('');
98
+ *
99
+ * const combined = flow(add, square, double, toStr, split);
100
+ * console.log(combined(1, 2)); // ['1', '8']
101
+ */
102
+ declare function flow<A extends any[], R1, R2, R3, R4, R5>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5): (...args: A) => R5;
103
+ /**
104
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
105
+ *
106
+ * @param {Array<(...args: any[]) => any>} funcs The functions to invoke.
107
+ * @returns {(...args: any[]) => any} Returns the new composite function.
108
+ *
109
+ * @example
110
+ * const add = (x: number, y: number) => x + y;
111
+ * const square = (n: number) => n * n;
112
+ *
113
+ * const combined = flow(add, square);
114
+ * console.log(combined(1, 2)); // 9
115
+ */
116
+ declare function flow(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
117
+
118
+ export { flow };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
3
+ *
4
+ * @param {() => R} f The function to invoke.
5
+ * @returns {() => R} Returns the new composite function.
6
+ *
7
+ * @example
8
+ * function noArgFunc() {
9
+ * return 42;
10
+ * }
11
+ *
12
+ * const combined = flow(noArgFunc);
13
+ * console.log(combined()); // 42
14
+ */
15
+ declare function flow<R>(f: () => R): () => R;
16
+ /**
17
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
18
+ *
19
+ * @param {(...args: A) => R} f1 The function to invoke.
20
+ * @returns {(...args: A) => R} Returns the new composite function.
21
+ *
22
+ * @example
23
+ * function oneArgFunc(a: number) {
24
+ * return a * 2;
25
+ * }
26
+ *
27
+ * const combined = flow(oneArgFunc);
28
+ * console.log(combined(5)); // 10
29
+ */
30
+ declare function flow<A extends any[], R>(f1: (...args: A) => R): (...args: A) => R;
31
+ /**
32
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
33
+ *
34
+ * @param {(...args: A) => R1} f1 The function to invoke.
35
+ * @param {(a: R1) => R2} f2 The function to invoke.
36
+ * @returns {(...args: A) => R2} Returns the new composite function.
37
+ *
38
+ * @example
39
+ * const add = (x: number, y: number) => x + y;
40
+ * const square = (n: number) => n * n;
41
+ *
42
+ * const combined = flow(add, square);
43
+ * console.log(combined(1, 2)); // 9
44
+ */
45
+ declare function flow<A extends any[], R1, R2>(f1: (...args: A) => R1, f2: (a: R1) => R2): (...args: A) => R2;
46
+ /**
47
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
48
+ *
49
+ * @param {(...args: A) => R1} f1 The function to invoke.
50
+ * @param {(a: R1) => R2} f2 The function to invoke.
51
+ * @param {(a: R2) => R3} f3 The function to invoke.
52
+ * @returns {(...args: A) => R3} Returns the new composite function.
53
+ *
54
+ * @example
55
+ * const add = (x: number, y: number) => x + y;
56
+ * const square = (n: number) => n * n;
57
+ * const double = (n: number) => n * 2;
58
+ *
59
+ * const combined = flow(add, square, double);
60
+ * console.log(combined(1, 2)); // 18
61
+ */
62
+ declare function flow<A extends any[], R1, R2, R3>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3): (...args: A) => R3;
63
+ /**
64
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
65
+ *
66
+ * @param {(...args: A) => R1} f1 The function to invoke.
67
+ * @param {(a: R1) => R2} f2 The function to invoke.
68
+ * @param {(a: R2) => R3} f3 The function to invoke.
69
+ * @param {(a: R3) => R4} f4 The function to invoke.
70
+ * @returns {(...args: A) => R4} Returns the new composite function.
71
+ *
72
+ * @example
73
+ * const add = (x: number, y: number) => x + y;
74
+ * const square = (n: number) => n * n;
75
+ * const double = (n: number) => n * 2;
76
+ * const toStr = (n: number) => n.toString();
77
+ *
78
+ * const combined = flow(add, square, double, toStr);
79
+ * console.log(combined(1, 2)); // '18'
80
+ */
81
+ declare function flow<A extends any[], R1, R2, R3, R4>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4): (...args: A) => R4;
82
+ /**
83
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
84
+ *
85
+ * @param {(...args: A) => R1} f1 The function to invoke.
86
+ * @param {(a: R1) => R2} f2 The function to invoke.
87
+ * @param {(a: R2) => R3} f3 The function to invoke.
88
+ * @param {(a: R3) => R4} f4 The function to invoke.
89
+ * @param {(a: R4) => R5} f5 The function to invoke.
90
+ * @returns {(...args: A) => R5} Returns the new composite function.
91
+ *
92
+ * @example
93
+ * const add = (x: number, y: number) => x + y;
94
+ * const square = (n: number) => n * n;
95
+ * const double = (n: number) => n * 2;
96
+ * const toStr = (n: number) => n.toString();
97
+ * const split = (s: string) => s.split('');
98
+ *
99
+ * const combined = flow(add, square, double, toStr, split);
100
+ * console.log(combined(1, 2)); // ['1', '8']
101
+ */
102
+ declare function flow<A extends any[], R1, R2, R3, R4, R5>(f1: (...args: A) => R1, f2: (a: R1) => R2, f3: (a: R2) => R3, f4: (a: R3) => R4, f5: (a: R4) => R5): (...args: A) => R5;
103
+ /**
104
+ * Creates a function that returns the result of invoking the given functions with the `this` binding of the created function, where each successive invocation is supplied the return value of the previous.
105
+ *
106
+ * @param {Array<(...args: any[]) => any>} funcs The functions to invoke.
107
+ * @returns {(...args: any[]) => any} Returns the new composite function.
108
+ *
109
+ * @example
110
+ * const add = (x: number, y: number) => x + y;
111
+ * const square = (n: number) => n * n;
112
+ *
113
+ * const combined = flow(add, square);
114
+ * console.log(combined(1, 2)); // 9
115
+ */
116
+ declare function flow(...funcs: Array<(...args: any[]) => any>): (...args: any[]) => any;
117
+
118
+ export { flow };
@@ -0,0 +1,11 @@
1
+ function flow(...funcs) {
2
+ return function (...args) {
3
+ let result = funcs.length ? funcs[0].apply(this, args) : args[0];
4
+ for (let i = 1; i < funcs.length; i++) {
5
+ result = funcs[i].call(this, result);
6
+ }
7
+ return result;
8
+ };
9
+ }
10
+
11
+ export { flow };
@@ -13,3 +13,4 @@ export { partialRight } from './partialRight.mjs';
13
13
  export { rest } from './rest.mjs';
14
14
  export { curry } from './curry.mjs';
15
15
  export { spread } from './spread.mjs';
16
+ export { flow } from './flow.mjs';
@@ -13,3 +13,4 @@ export { partialRight } from './partialRight.js';
13
13
  export { rest } from './rest.js';
14
14
  export { curry } from './curry.js';
15
15
  export { spread } from './spread.js';
16
+ export { flow } from './flow.js';
@@ -2,11 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
- const rest = require('../_chunk/rest-pUyjvl.js');
5
+ const flow = require('../_chunk/flow-Au34h2.js');
6
6
 
7
7
  function throttle(func, throttleMs, { signal, edges = ['leading', 'trailing'] } = {}) {
8
8
  let pendingAt = null;
9
- const debounced = rest.debounce(func, throttleMs, { signal, edges });
9
+ const debounced = flow.debounce(func, throttleMs, { signal, edges });
10
10
  const throttled = function (...args) {
11
11
  if (pendingAt == null) {
12
12
  pendingAt = Date.now();
@@ -50,18 +50,19 @@ function spread(func) {
50
50
  };
51
51
  }
52
52
 
53
- exports.after = rest.after;
54
- exports.ary = rest.ary;
55
- exports.before = rest.before;
56
- exports.debounce = rest.debounce;
57
- exports.memoize = rest.memoize;
58
- exports.negate = rest.negate;
59
- exports.noop = rest.noop;
60
- exports.once = rest.once;
61
- exports.partial = rest.partial;
62
- exports.partialRight = rest.partialRight;
63
- exports.rest = rest.rest;
64
- exports.unary = rest.unary;
53
+ exports.after = flow.after;
54
+ exports.ary = flow.ary;
55
+ exports.before = flow.before;
56
+ exports.debounce = flow.debounce;
57
+ exports.flow = flow.flow;
58
+ exports.memoize = flow.memoize;
59
+ exports.negate = flow.negate;
60
+ exports.noop = flow.noop;
61
+ exports.once = flow.once;
62
+ exports.partial = flow.partial;
63
+ exports.partialRight = flow.partialRight;
64
+ exports.rest = flow.rest;
65
+ exports.unary = flow.unary;
65
66
  exports.curry = curry;
66
67
  exports.spread = spread;
67
68
  exports.throttle = throttle;
@@ -13,3 +13,4 @@ export { partialRight } from './partialRight.mjs';
13
13
  export { rest } from './rest.mjs';
14
14
  export { curry } from './curry.mjs';
15
15
  export { spread } from './spread.mjs';
16
+ export { flow } from './flow.mjs';
package/dist/index.d.mts CHANGED
@@ -71,6 +71,7 @@ export { partialRight } from './function/partialRight.mjs';
71
71
  export { rest } from './function/rest.mjs';
72
72
  export { curry } from './function/curry.mjs';
73
73
  export { spread } from './function/spread.mjs';
74
+ export { flow } from './function/flow.mjs';
74
75
  export { clamp } from './math/clamp.mjs';
75
76
  export { inRange } from './math/inRange.mjs';
76
77
  export { mean } from './math/mean.mjs';
package/dist/index.d.ts CHANGED
@@ -71,6 +71,7 @@ export { partialRight } from './function/partialRight.js';
71
71
  export { rest } from './function/rest.js';
72
72
  export { curry } from './function/curry.js';
73
73
  export { spread } from './function/spread.js';
74
+ export { flow } from './function/flow.js';
74
75
  export { clamp } from './math/clamp.js';
75
76
  export { inRange } from './math/inRange.js';
76
77
  export { mean } from './math/mean.js';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
  const zipWith = require('./_chunk/zipWith-DEcUS4.js');
6
6
  const array_index = require('./array/index.js');
7
7
  const promise_index = require('./_chunk/index-BGZDR9.js');
8
- const rest = require('./_chunk/rest-pUyjvl.js');
8
+ const flow = require('./_chunk/flow-Au34h2.js');
9
9
  const function_index = require('./function/index.js');
10
10
  const range = require('./_chunk/range-BXlMmn.js');
11
11
  const randomInt = require('./_chunk/randomInt-CF7bZK.js');
@@ -81,18 +81,19 @@ exports.TimeoutError = promise_index.TimeoutError;
81
81
  exports.delay = promise_index.delay;
82
82
  exports.timeout = promise_index.timeout;
83
83
  exports.withTimeout = promise_index.withTimeout;
84
- exports.after = rest.after;
85
- exports.ary = rest.ary;
86
- exports.before = rest.before;
87
- exports.debounce = rest.debounce;
88
- exports.memoize = rest.memoize;
89
- exports.negate = rest.negate;
90
- exports.noop = rest.noop;
91
- exports.once = rest.once;
92
- exports.partial = rest.partial;
93
- exports.partialRight = rest.partialRight;
94
- exports.rest = rest.rest;
95
- exports.unary = rest.unary;
84
+ exports.after = flow.after;
85
+ exports.ary = flow.ary;
86
+ exports.before = flow.before;
87
+ exports.debounce = flow.debounce;
88
+ exports.flow = flow.flow;
89
+ exports.memoize = flow.memoize;
90
+ exports.negate = flow.negate;
91
+ exports.noop = flow.noop;
92
+ exports.once = flow.once;
93
+ exports.partial = flow.partial;
94
+ exports.partialRight = flow.partialRight;
95
+ exports.rest = flow.rest;
96
+ exports.unary = flow.unary;
96
97
  exports.curry = function_index.curry;
97
98
  exports.spread = function_index.spread;
98
99
  exports.throttle = function_index.throttle;
package/dist/index.mjs CHANGED
@@ -71,6 +71,7 @@ export { partialRight } from './function/partialRight.mjs';
71
71
  export { rest } from './function/rest.mjs';
72
72
  export { curry } from './function/curry.mjs';
73
73
  export { spread } from './function/spread.mjs';
74
+ export { flow } from './function/flow.mjs';
74
75
  export { clamp } from './math/clamp.mjs';
75
76
  export { inRange } from './math/inRange.mjs';
76
77
  export { mean } from './math/mean.mjs';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.21.0-dev.668+f70e36bd",
4
+ "version": "1.21.0-dev.670+893ed163",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {