es-toolkit 1.20.0-dev.648 → 1.20.0-dev.650

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.
@@ -182,3 +182,6 @@ export { inRange } from './math/inRange.mjs';
182
182
  export { random } from './math/random.mjs';
183
183
  export { toPath } from './util/toPath.mjs';
184
184
  export { toString } from './util/toString.mjs';
185
+ export { toNumber } from './util/toNumber.mjs';
186
+ export { toInteger } from './util/toInteger.mjs';
187
+ export { toFinite } from './util/toFinite.mjs';
@@ -182,3 +182,6 @@ export { inRange } from './math/inRange.js';
182
182
  export { random } from './math/random.js';
183
183
  export { toPath } from './util/toPath.js';
184
184
  export { toString } from './util/toString.js';
185
+ export { toNumber } from './util/toNumber.js';
186
+ export { toInteger } from './util/toInteger.js';
187
+ export { toFinite } from './util/toFinite.js';
@@ -1589,6 +1589,31 @@ function random(...args) {
1589
1589
  }
1590
1590
  }
1591
1591
 
1592
+ function toNumber(value) {
1593
+ if (isSymbol(value)) {
1594
+ return NaN;
1595
+ }
1596
+ return Number(value);
1597
+ }
1598
+
1599
+ function toFinite(value) {
1600
+ if (!value) {
1601
+ return value === 0 ? value : 0;
1602
+ }
1603
+ value = toNumber(value);
1604
+ if (value === Infinity || value === -Infinity) {
1605
+ const sign = value < 0 ? -1 : 1;
1606
+ return sign * Number.MAX_VALUE;
1607
+ }
1608
+ return value === value ? value : 0;
1609
+ }
1610
+
1611
+ function toInteger(value) {
1612
+ const finite = toFinite(value);
1613
+ const remainder = finite % 1;
1614
+ return remainder ? finite - remainder : finite;
1615
+ }
1616
+
1592
1617
  exports.at = zipWith.at;
1593
1618
  exports.compact = zipWith.compact;
1594
1619
  exports.countBy = zipWith.countBy;
@@ -1766,6 +1791,9 @@ exports.spread = spread;
1766
1791
  exports.startCase = startCase;
1767
1792
  exports.startsWith = startsWith;
1768
1793
  exports.throttle = throttle;
1794
+ exports.toFinite = toFinite;
1795
+ exports.toInteger = toInteger;
1796
+ exports.toNumber = toNumber;
1769
1797
  exports.toPath = toPath;
1770
1798
  exports.toString = toString;
1771
1799
  exports.trim = trim;
@@ -182,3 +182,6 @@ export { inRange } from './math/inRange.mjs';
182
182
  export { random } from './math/random.mjs';
183
183
  export { toPath } from './util/toPath.mjs';
184
184
  export { toString } from './util/toString.mjs';
185
+ export { toNumber } from './util/toNumber.mjs';
186
+ export { toInteger } from './util/toInteger.mjs';
187
+ export { toFinite } from './util/toFinite.mjs';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts `value` to a finite number.
3
+ *
4
+ * @param {unknown} value - The value to convert.
5
+ * @returns {number} Returns the number.
6
+ *
7
+ * @example
8
+ * toNumber(3.2); // => 3.2
9
+ * toNumber(Number.MIN_VALUE); // => 5e-324
10
+ * toNumber(Infinity); // => 1.7976931348623157e+308
11
+ * toNumber('3.2'); // => 3.2
12
+ * toNumber(Symbol.iterator); // => 0
13
+ * toNumber(NaN); // => 0
14
+ */
15
+ declare function toFinite(value?: unknown): number;
16
+
17
+ export { toFinite };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts `value` to a finite number.
3
+ *
4
+ * @param {unknown} value - The value to convert.
5
+ * @returns {number} Returns the number.
6
+ *
7
+ * @example
8
+ * toNumber(3.2); // => 3.2
9
+ * toNumber(Number.MIN_VALUE); // => 5e-324
10
+ * toNumber(Infinity); // => 1.7976931348623157e+308
11
+ * toNumber('3.2'); // => 3.2
12
+ * toNumber(Symbol.iterator); // => 0
13
+ * toNumber(NaN); // => 0
14
+ */
15
+ declare function toFinite(value?: unknown): number;
16
+
17
+ export { toFinite };
@@ -0,0 +1,15 @@
1
+ import { toNumber } from './toNumber.mjs';
2
+
3
+ function toFinite(value) {
4
+ if (!value) {
5
+ return value === 0 ? value : 0;
6
+ }
7
+ value = toNumber(value);
8
+ if (value === Infinity || value === -Infinity) {
9
+ const sign = value < 0 ? -1 : 1;
10
+ return sign * Number.MAX_VALUE;
11
+ }
12
+ return value === value ? value : 0;
13
+ }
14
+
15
+ export { toFinite };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts `value` to an integer.
3
+ *
4
+ * @param {unknown} value - The value to convert.
5
+ * @returns {number} Returns the number.
6
+ *
7
+ * @example
8
+ * toInteger(3.2); // => 3
9
+ * toInteger(Number.MIN_VALUE); // => 0
10
+ * toInteger(Infinity); // => 1.7976931348623157e+308
11
+ * toInteger('3.2'); // => 3
12
+ * toInteger(Symbol.iterator); // => 0
13
+ * toInteger(NaN); // => 0
14
+ */
15
+ declare function toInteger(value?: unknown): number;
16
+
17
+ export { toInteger };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Converts `value` to an integer.
3
+ *
4
+ * @param {unknown} value - The value to convert.
5
+ * @returns {number} Returns the number.
6
+ *
7
+ * @example
8
+ * toInteger(3.2); // => 3
9
+ * toInteger(Number.MIN_VALUE); // => 0
10
+ * toInteger(Infinity); // => 1.7976931348623157e+308
11
+ * toInteger('3.2'); // => 3
12
+ * toInteger(Symbol.iterator); // => 0
13
+ * toInteger(NaN); // => 0
14
+ */
15
+ declare function toInteger(value?: unknown): number;
16
+
17
+ export { toInteger };
@@ -0,0 +1,9 @@
1
+ import { toFinite } from './toFinite.mjs';
2
+
3
+ function toInteger(value) {
4
+ const finite = toFinite(value);
5
+ const remainder = finite % 1;
6
+ return remainder ? finite - remainder : finite;
7
+ }
8
+
9
+ export { toInteger };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Converts `value` to a number.
3
+ *
4
+ * Unlike `Number()`, this function returns `NaN` for symbols.
5
+ *
6
+ * @param {unknown} value - The value to convert.
7
+ * @returns {number} Returns the number.
8
+ *
9
+ * @example
10
+ * toNumber(3.2); // => 3.2
11
+ * toNumber(Number.MIN_VALUE); // => 5e-324
12
+ * toNumber(Infinity); // => Infinity
13
+ * toNumber('3.2'); // => 3.2
14
+ * toNumber(Symbol.iterator); // => NaN
15
+ * toNumber(NaN); // => NaN
16
+ */
17
+ declare function toNumber(value?: unknown): number;
18
+
19
+ export { toNumber };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Converts `value` to a number.
3
+ *
4
+ * Unlike `Number()`, this function returns `NaN` for symbols.
5
+ *
6
+ * @param {unknown} value - The value to convert.
7
+ * @returns {number} Returns the number.
8
+ *
9
+ * @example
10
+ * toNumber(3.2); // => 3.2
11
+ * toNumber(Number.MIN_VALUE); // => 5e-324
12
+ * toNumber(Infinity); // => Infinity
13
+ * toNumber('3.2'); // => 3.2
14
+ * toNumber(Symbol.iterator); // => NaN
15
+ * toNumber(NaN); // => NaN
16
+ */
17
+ declare function toNumber(value?: unknown): number;
18
+
19
+ export { toNumber };
@@ -0,0 +1,10 @@
1
+ import { isSymbol } from '../predicate/isSymbol.mjs';
2
+
3
+ function toNumber(value) {
4
+ if (isSymbol(value)) {
5
+ return NaN;
6
+ }
7
+ return Number(value);
8
+ }
9
+
10
+ export { toNumber };
@@ -48,18 +48,17 @@ declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2:
48
48
  * Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
49
49
  * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
50
50
  *
51
- * @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
52
- * @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
51
+ * @param {(p1: P1, p2: P2, p3: P3) => R} func - The function to curry.
52
+ * @returns {(p1: P1) => (p2: P2) => (p3: P3) => R} A curried function.
53
53
  *
54
54
  * @example
55
- * function fourArgFunc(a: number, b: number, c: number, d: number) {
56
- * return a + b + c + d;
55
+ * function threeArgFunc(a: number, b: number, c: number) {
56
+ * return a + b + c;
57
57
  * }
58
- * const curriedFourArgFunc = curry(fourArgFunc);
59
- * const add1 = curriedFourArgFunc(1);
60
- * const add2 = add1(2);
61
- * const add3 = add2(3);
62
- * console.log(add3(4)); // 10
58
+ * const curriedThreeArgFunc = curry(threeArgFunc);
59
+ * const add1 = curriedThreeArgFunc(1);
60
+ * const add3 = add1(2);
61
+ * console.log(add3(3)); // 6
63
62
  */
64
63
  declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
65
64
  /**
@@ -75,9 +74,9 @@ declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1:
75
74
  * }
76
75
  * const curriedFourArgFunc = curry(fourArgFunc);
77
76
  * const add1 = curriedFourArgFunc(1);
78
- * const add2 = add1(2);
79
- * const add3 = add2(3);
80
- * console.log(add3(4)); // 10
77
+ * const add3 = add1(2);
78
+ * const add6 = add3(3);
79
+ * console.log(add6(4)); // 10
81
80
  */
82
81
  declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
83
82
  /**
@@ -93,10 +92,10 @@ declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4)
93
92
  * }
94
93
  * const curriedFiveArgFunc = curry(fiveArgFunc);
95
94
  * const add1 = curriedFiveArgFunc(1);
96
- * const add2 = add1(2);
97
- * const add3 = add2(3);
98
- * const add4 = add3(4);
99
- * console.log(add4(5)); // 15
95
+ * const add3 = add1(2);
96
+ * const add6 = add3(3);
97
+ * const add10 = add6(4);
98
+ * console.log(add10(5)); // 15
100
99
  */
101
100
  declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
102
101
  /**
@@ -114,13 +113,13 @@ declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4:
114
113
  * const curriedSum = curry(sum);
115
114
  *
116
115
  * // The parameter `a` should be given the value `10`.
117
- * const sum10 = curriedSum(10);
116
+ * const add10 = curriedSum(10);
118
117
  *
119
118
  * // The parameter `b` should be given the value `15`.
120
- * const sum25 = sum10(15);
119
+ * const add25 = add10(15);
121
120
  *
122
121
  * // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
123
- * const result = sum25(5);
122
+ * const result = add25(5);
124
123
  */
125
124
  declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
126
125
 
@@ -48,18 +48,17 @@ declare function curry<P1, P2, R>(func: (p1: P1, p2: P2) => R): (p1: P1) => (p2:
48
48
  * Curries a function, allowing it to be called with a single argument at a time and returning a new function that takes the next argument.
49
49
  * This process continues until all arguments have been provided, at which point the original function is called with all accumulated arguments.
50
50
  *
51
- * @param {(p1: P1, p2: P2, p3: P3, p4: P4) => R} func - The function to curry.
52
- * @returns {(p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R} A curried function.
51
+ * @param {(p1: P1, p2: P2, p3: P3) => R} func - The function to curry.
52
+ * @returns {(p1: P1) => (p2: P2) => (p3: P3) => R} A curried function.
53
53
  *
54
54
  * @example
55
- * function fourArgFunc(a: number, b: number, c: number, d: number) {
56
- * return a + b + c + d;
55
+ * function threeArgFunc(a: number, b: number, c: number) {
56
+ * return a + b + c;
57
57
  * }
58
- * const curriedFourArgFunc = curry(fourArgFunc);
59
- * const add1 = curriedFourArgFunc(1);
60
- * const add2 = add1(2);
61
- * const add3 = add2(3);
62
- * console.log(add3(4)); // 10
58
+ * const curriedThreeArgFunc = curry(threeArgFunc);
59
+ * const add1 = curriedThreeArgFunc(1);
60
+ * const add3 = add1(2);
61
+ * console.log(add3(3)); // 6
63
62
  */
64
63
  declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1: P1) => (p2: P2) => (p3: P3) => R;
65
64
  /**
@@ -75,9 +74,9 @@ declare function curry<P1, P2, P3, R>(func: (p1: P1, p2: P2, p3: P3) => R): (p1:
75
74
  * }
76
75
  * const curriedFourArgFunc = curry(fourArgFunc);
77
76
  * const add1 = curriedFourArgFunc(1);
78
- * const add2 = add1(2);
79
- * const add3 = add2(3);
80
- * console.log(add3(4)); // 10
77
+ * const add3 = add1(2);
78
+ * const add6 = add3(3);
79
+ * console.log(add6(4)); // 10
81
80
  */
82
81
  declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => R;
83
82
  /**
@@ -93,10 +92,10 @@ declare function curry<P1, P2, P3, P4, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4)
93
92
  * }
94
93
  * const curriedFiveArgFunc = curry(fiveArgFunc);
95
94
  * const add1 = curriedFiveArgFunc(1);
96
- * const add2 = add1(2);
97
- * const add3 = add2(3);
98
- * const add4 = add3(4);
99
- * console.log(add4(5)); // 15
95
+ * const add3 = add1(2);
96
+ * const add6 = add3(3);
97
+ * const add10 = add6(4);
98
+ * console.log(add10(5)); // 15
100
99
  */
101
100
  declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) => R): (p1: P1) => (p2: P2) => (p3: P3) => (p4: P4) => (p5: P5) => R;
102
101
  /**
@@ -114,13 +113,13 @@ declare function curry<P1, P2, P3, P4, P5, R>(func: (p1: P1, p2: P2, p3: P3, p4:
114
113
  * const curriedSum = curry(sum);
115
114
  *
116
115
  * // The parameter `a` should be given the value `10`.
117
- * const sum10 = curriedSum(10);
116
+ * const add10 = curriedSum(10);
118
117
  *
119
118
  * // The parameter `b` should be given the value `15`.
120
- * const sum25 = sum10(15);
119
+ * const add25 = add10(15);
121
120
  *
122
121
  * // The parameter `c` should be given the value `5`. The function 'sum' has received all its arguments and will now return a value.
123
- * const result = sum25(5);
122
+ * const result = add25(5);
124
123
  */
125
124
  declare function curry(func: (...args: any[]) => any): (...args: any[]) => any;
126
125
 
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.20.0-dev.648+60e4ba38",
4
+ "version": "1.20.0-dev.650+d47ee5f4",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {