es-toolkit 1.13.1-dev.371 → 1.13.1-dev.373

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.
@@ -55,6 +55,8 @@ export { noop } from '../function/noop.mjs';
55
55
  export { once } from '../function/once.mjs';
56
56
  export { throttle } from '../function/throttle.mjs';
57
57
  export { negate } from '../function/negate.mjs';
58
+ export { ary } from '../function/ary.mjs';
59
+ export { unary } from '../function/unary.mjs';
58
60
  export { bind } from '../function/bind.mjs';
59
61
  export { clamp } from '../math/clamp.mjs';
60
62
  export { inRange } from '../math/inRange.mjs';
@@ -55,6 +55,8 @@ export { noop } from '../function/noop.js';
55
55
  export { once } from '../function/once.js';
56
56
  export { throttle } from '../function/throttle.js';
57
57
  export { negate } from '../function/negate.js';
58
+ export { ary } from '../function/ary.js';
59
+ export { unary } from '../function/unary.js';
58
60
  export { bind } from '../function/bind.js';
59
61
  export { clamp } from '../math/clamp.js';
60
62
  export { inRange } from '../math/inRange.js';
@@ -461,6 +461,7 @@ exports.TimeoutError = promise_index.TimeoutError;
461
461
  exports.delay = promise_index.delay;
462
462
  exports.withTimeout = promise_index.withTimeout;
463
463
  exports.after = function_index.after;
464
+ exports.ary = function_index.ary;
464
465
  exports.before = function_index.before;
465
466
  exports.bind = function_index.bind;
466
467
  exports.debounce = function_index.debounce;
@@ -468,6 +469,7 @@ exports.negate = function_index.negate;
468
469
  exports.noop = function_index.noop;
469
470
  exports.once = function_index.once;
470
471
  exports.throttle = function_index.throttle;
472
+ exports.unary = function_index.unary;
471
473
  exports.clamp = math_index.clamp;
472
474
  exports.inRange = math_index.inRange;
473
475
  exports.mean = math_index.mean;
@@ -55,6 +55,8 @@ export { noop } from '../function/noop.mjs';
55
55
  export { once } from '../function/once.mjs';
56
56
  export { throttle } from '../function/throttle.mjs';
57
57
  export { negate } from '../function/negate.mjs';
58
+ export { ary } from '../function/ary.mjs';
59
+ export { unary } from '../function/unary.mjs';
58
60
  export { bind } from '../function/bind.mjs';
59
61
  export { clamp } from '../math/clamp.mjs';
60
62
  export { inRange } from '../math/inRange.mjs';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
3
+ *
4
+ *
5
+ * @template F - The type of the function.
6
+ * @param {F} func - The function to cap arguments for.
7
+ * @param {number} n - The arity cap.
8
+ * @param {any} guard - Enables use as an iteratee for methods like `map`.
9
+ * @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
10
+ */
11
+ declare const ary: <F extends (...args: any[]) => any>(func: F, n?: number, guard?: any) => ((...args: any[]) => ReturnType<F>);
12
+
13
+ export { ary };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Creates a function that invokes func, with up to n arguments, ignoring any additional arguments.
3
+ *
4
+ *
5
+ * @template F - The type of the function.
6
+ * @param {F} func - The function to cap arguments for.
7
+ * @param {number} n - The arity cap.
8
+ * @param {any} guard - Enables use as an iteratee for methods like `map`.
9
+ * @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
10
+ */
11
+ declare const ary: <F extends (...args: any[]) => any>(func: F, n?: number, guard?: any) => ((...args: any[]) => ReturnType<F>);
12
+
13
+ export { ary };
@@ -0,0 +1,11 @@
1
+ const ary = (func, n = func.length, guard) => {
2
+ n = guard ? func.length : Number.parseInt(n.toString());
3
+ if (Number.isNaN(n) || n < 0) {
4
+ n = 0;
5
+ }
6
+ return function (...args) {
7
+ return func.apply(this, args.slice(0, n));
8
+ };
9
+ };
10
+
11
+ export { ary };
@@ -5,4 +5,6 @@ export { noop } from './noop.mjs';
5
5
  export { once } from './once.mjs';
6
6
  export { throttle } from './throttle.mjs';
7
7
  export { negate } from './negate.mjs';
8
+ export { ary } from './ary.mjs';
9
+ export { unary } from './unary.mjs';
8
10
  export { bind } from './bind.mjs';
@@ -5,4 +5,6 @@ export { noop } from './noop.js';
5
5
  export { once } from './once.js';
6
6
  export { throttle } from './throttle.js';
7
7
  export { negate } from './negate.js';
8
+ export { ary } from './ary.js';
9
+ export { unary } from './unary.js';
8
10
  export { bind } from './bind.js';
@@ -87,6 +87,20 @@ function negate(func) {
87
87
  return ((...args) => !func(...args));
88
88
  }
89
89
 
90
+ const ary = (func, n = func.length, guard) => {
91
+ n = guard ? func.length : Number.parseInt(n.toString());
92
+ if (Number.isNaN(n) || n < 0) {
93
+ n = 0;
94
+ }
95
+ return function (...args) {
96
+ return func.apply(this, args.slice(0, n));
97
+ };
98
+ };
99
+
100
+ const unary = (func) => {
101
+ return ary(func, 1);
102
+ };
103
+
90
104
  function bind(func, thisArg, ...partials) {
91
105
  const wrapper = function (...args) {
92
106
  let index = 0;
@@ -109,6 +123,7 @@ function bind(func, thisArg, ...partials) {
109
123
  bind.placeholder = Symbol('bind.placeholder');
110
124
 
111
125
  exports.after = after;
126
+ exports.ary = ary;
112
127
  exports.before = before;
113
128
  exports.bind = bind;
114
129
  exports.debounce = debounce;
@@ -116,3 +131,4 @@ exports.negate = negate;
116
131
  exports.noop = noop;
117
132
  exports.once = once;
118
133
  exports.throttle = throttle;
134
+ exports.unary = unary;
@@ -5,4 +5,6 @@ export { noop } from './noop.mjs';
5
5
  export { once } from './once.mjs';
6
6
  export { throttle } from './throttle.mjs';
7
7
  export { negate } from './negate.mjs';
8
+ export { ary } from './ary.mjs';
9
+ export { unary } from './unary.mjs';
8
10
  export { bind } from './bind.mjs';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Creates a function that accepts up to one argument, ignoring any additional arguments.
3
+ *
4
+ * @template F - The type of the function.
5
+ * @param {F} func - The function to cap arguments for.
6
+ * @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
7
+ */
8
+ declare const unary: <F extends (...args: any[]) => any>(func: F) => ((...args: any[]) => ReturnType<F>);
9
+
10
+ export { unary };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Creates a function that accepts up to one argument, ignoring any additional arguments.
3
+ *
4
+ * @template F - The type of the function.
5
+ * @param {F} func - The function to cap arguments for.
6
+ * @returns {(...args: any[]) => ReturnType<F>} Returns the new capped function.
7
+ */
8
+ declare const unary: <F extends (...args: any[]) => any>(func: F) => ((...args: any[]) => ReturnType<F>);
9
+
10
+ export { unary };
@@ -0,0 +1,7 @@
1
+ import { ary } from './ary.mjs';
2
+
3
+ const unary = (func) => {
4
+ return ary(func, 1);
5
+ };
6
+
7
+ export { unary };
package/dist/index.d.mts CHANGED
@@ -60,6 +60,8 @@ export { noop } from './function/noop.mjs';
60
60
  export { once } from './function/once.mjs';
61
61
  export { throttle } from './function/throttle.mjs';
62
62
  export { negate } from './function/negate.mjs';
63
+ export { ary } from './function/ary.mjs';
64
+ export { unary } from './function/unary.mjs';
63
65
  export { bind } from './function/bind.mjs';
64
66
  export { clamp } from './math/clamp.mjs';
65
67
  export { inRange } from './math/inRange.mjs';
package/dist/index.d.ts CHANGED
@@ -60,6 +60,8 @@ export { noop } from './function/noop.js';
60
60
  export { once } from './function/once.js';
61
61
  export { throttle } from './function/throttle.js';
62
62
  export { negate } from './function/negate.js';
63
+ export { ary } from './function/ary.js';
64
+ export { unary } from './function/unary.js';
63
65
  export { bind } from './function/bind.js';
64
66
  export { clamp } from './math/clamp.js';
65
67
  export { inRange } from './math/inRange.js';
package/dist/index.js CHANGED
@@ -75,6 +75,7 @@ exports.TimeoutError = promise_index.TimeoutError;
75
75
  exports.delay = promise_index.delay;
76
76
  exports.withTimeout = promise_index.withTimeout;
77
77
  exports.after = function_index.after;
78
+ exports.ary = function_index.ary;
78
79
  exports.before = function_index.before;
79
80
  exports.bind = function_index.bind;
80
81
  exports.debounce = function_index.debounce;
@@ -82,6 +83,7 @@ exports.negate = function_index.negate;
82
83
  exports.noop = function_index.noop;
83
84
  exports.once = function_index.once;
84
85
  exports.throttle = function_index.throttle;
86
+ exports.unary = function_index.unary;
85
87
  exports.clamp = math_index.clamp;
86
88
  exports.inRange = math_index.inRange;
87
89
  exports.mean = math_index.mean;
package/dist/index.mjs CHANGED
@@ -60,6 +60,8 @@ export { noop } from './function/noop.mjs';
60
60
  export { once } from './function/once.mjs';
61
61
  export { throttle } from './function/throttle.mjs';
62
62
  export { negate } from './function/negate.mjs';
63
+ export { ary } from './function/ary.mjs';
64
+ export { unary } from './function/unary.mjs';
63
65
  export { bind } from './function/bind.mjs';
64
66
  export { clamp } from './math/clamp.mjs';
65
67
  export { inRange } from './math/inRange.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.13.1-dev.371+86fe776f",
4
+ "version": "1.13.1-dev.373+db79ff33",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {