es-toolkit 1.21.0-dev.679 → 1.21.0-dev.681

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.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Reverses the order of arguments for a given function.
3
+ *
4
+ * @template F - The type of the function being flipped.
5
+ * @param {F} func - The function whose arguments will be reversed.
6
+ * @returns {(...args: Reversed<Parameters<F>>) => ReturnType<F>} A new function that takes the
7
+ * reversed arguments and returns the result of calling `func`.
8
+ *
9
+ * @example
10
+ * function fn(a: string, b: string, c: string, d: string) {
11
+ * return [a, b, c, d];
12
+ * }
13
+ *
14
+ * const flipped = flip(fn);
15
+ * flipped('a', 'b', 'c', 'd'); // => ['d', 'c', 'b', 'a']
16
+ */
17
+ declare function flip<F extends (...args: any[]) => any>(func: F): (...args: Reversed<Parameters<F>>) => ReturnType<F>;
18
+ type Reversed<T extends any[]> = T extends [infer First, ...infer Rest] ? [...Reversed<Rest>, First] : [];
19
+
20
+ export { flip };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Reverses the order of arguments for a given function.
3
+ *
4
+ * @template F - The type of the function being flipped.
5
+ * @param {F} func - The function whose arguments will be reversed.
6
+ * @returns {(...args: Reversed<Parameters<F>>) => ReturnType<F>} A new function that takes the
7
+ * reversed arguments and returns the result of calling `func`.
8
+ *
9
+ * @example
10
+ * function fn(a: string, b: string, c: string, d: string) {
11
+ * return [a, b, c, d];
12
+ * }
13
+ *
14
+ * const flipped = flip(fn);
15
+ * flipped('a', 'b', 'c', 'd'); // => ['d', 'c', 'b', 'a']
16
+ */
17
+ declare function flip<F extends (...args: any[]) => any>(func: F): (...args: Reversed<Parameters<F>>) => ReturnType<F>;
18
+ type Reversed<T extends any[]> = T extends [infer First, ...infer Rest] ? [...Reversed<Rest>, First] : [];
19
+
20
+ export { flip };
@@ -0,0 +1,7 @@
1
+ function flip(func) {
2
+ return function (...args) {
3
+ return func.apply(this, args.reverse());
4
+ };
5
+ }
6
+
7
+ export { flip };
@@ -123,6 +123,7 @@ export { rearg } from './function/rearg.mjs';
123
123
  export { curry } from './function/curry.mjs';
124
124
  export { debounce } from './function/debounce.mjs';
125
125
  export { throttle } from './function/throttle.mjs';
126
+ export { flip } from './function/flip.mjs';
126
127
  export { get } from './object/get.mjs';
127
128
  export { set } from './object/set.mjs';
128
129
  export { pick } from './object/pick.mjs';
@@ -123,6 +123,7 @@ export { rearg } from './function/rearg.js';
123
123
  export { curry } from './function/curry.js';
124
124
  export { debounce } from './function/debounce.js';
125
125
  export { throttle } from './function/throttle.js';
126
+ export { flip } from './function/flip.js';
126
127
  export { get } from './object/get.js';
127
128
  export { set } from './object/set.js';
128
129
  export { pick } from './object/pick.js';
@@ -1008,6 +1008,12 @@ function throttle(func, throttleMs = 0, options = {}) {
1008
1008
  return debounce(func, throttleMs, { leading, trailing, signal, maxWait: throttleMs });
1009
1009
  }
1010
1010
 
1011
+ function flip(func) {
1012
+ return function (...args) {
1013
+ return func.apply(this, args.reverse());
1014
+ };
1015
+ }
1016
+
1011
1017
  function isNil(x) {
1012
1018
  return x == null;
1013
1019
  }
@@ -1835,6 +1841,7 @@ exports.findLastIndex = findLastIndex;
1835
1841
  exports.flatten = flatten;
1836
1842
  exports.flattenDeep = flattenDeep;
1837
1843
  exports.flattenDepth = flattenDepth;
1844
+ exports.flip = flip;
1838
1845
  exports.floor = floor;
1839
1846
  exports.fromPairs = fromPairs;
1840
1847
  exports.get = get;
@@ -124,6 +124,7 @@ export { rearg } from './function/rearg.mjs';
124
124
  export { curry } from './function/curry.mjs';
125
125
  export { debounce } from './function/debounce.mjs';
126
126
  export { throttle } from './function/throttle.mjs';
127
+ export { flip } from './function/flip.mjs';
127
128
  export { get } from './object/get.mjs';
128
129
  export { set } from './object/set.mjs';
129
130
  export { pick } from './object/pick.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.679+efe79322",
4
+ "version": "1.21.0-dev.681+7eed956e",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {