es-toolkit 1.24.0-dev.768 → 1.24.0-dev.770
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/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/MAX_SAFE_INTEGER.mjs +3 -0
- package/dist/compat/index.d.mts +1 -0
- package/dist/compat/index.d.ts +1 -0
- package/dist/compat/index.js +10 -0
- package/dist/compat/index.mjs +1 -0
- package/dist/compat/util/toSafeInteger.d.mts +20 -0
- package/dist/compat/util/toSafeInteger.d.ts +20 -0
- package/dist/compat/util/toSafeInteger.mjs +12 -0
- package/package.json +1 -1
package/dist/compat/index.d.mts
CHANGED
|
@@ -211,4 +211,5 @@ export { toInteger } from './util/toInteger.mjs';
|
|
|
211
211
|
export { toLength } from './util/toLength.mjs';
|
|
212
212
|
export { toNumber } from './util/toNumber.mjs';
|
|
213
213
|
export { toPath } from './util/toPath.mjs';
|
|
214
|
+
export { toSafeInteger } from './util/toSafeInteger.mjs';
|
|
214
215
|
export { toString } from './util/toString.mjs';
|
package/dist/compat/index.d.ts
CHANGED
|
@@ -211,4 +211,5 @@ export { toInteger } from './util/toInteger.js';
|
|
|
211
211
|
export { toLength } from './util/toLength.js';
|
|
212
212
|
export { toNumber } from './util/toNumber.js';
|
|
213
213
|
export { toPath } from './util/toPath.js';
|
|
214
|
+
export { toSafeInteger } from './util/toSafeInteger.js';
|
|
214
215
|
export { toString } from './util/toString.js';
|
package/dist/compat/index.js
CHANGED
|
@@ -2078,6 +2078,15 @@ function toLength(value) {
|
|
|
2078
2078
|
return clamp(length, 0, MAX_ARRAY_LENGTH);
|
|
2079
2079
|
}
|
|
2080
2080
|
|
|
2081
|
+
const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
2082
|
+
|
|
2083
|
+
function toSafeInteger(value) {
|
|
2084
|
+
if (value == null) {
|
|
2085
|
+
return 0;
|
|
2086
|
+
}
|
|
2087
|
+
return clamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2081
2090
|
exports.at = zipWith.at;
|
|
2082
2091
|
exports.compact = zipWith.compact;
|
|
2083
2092
|
exports.countBy = zipWith.countBy;
|
|
@@ -2286,6 +2295,7 @@ exports.toInteger = toInteger;
|
|
|
2286
2295
|
exports.toLength = toLength;
|
|
2287
2296
|
exports.toNumber = toNumber;
|
|
2288
2297
|
exports.toPath = toPath;
|
|
2298
|
+
exports.toSafeInteger = toSafeInteger;
|
|
2289
2299
|
exports.toString = toString;
|
|
2290
2300
|
exports.trim = trim;
|
|
2291
2301
|
exports.trimEnd = trimEnd;
|
package/dist/compat/index.mjs
CHANGED
|
@@ -211,4 +211,5 @@ export { toInteger } from './util/toInteger.mjs';
|
|
|
211
211
|
export { toLength } from './util/toLength.mjs';
|
|
212
212
|
export { toNumber } from './util/toNumber.mjs';
|
|
213
213
|
export { toPath } from './util/toPath.mjs';
|
|
214
|
+
export { toSafeInteger } from './util/toSafeInteger.mjs';
|
|
214
215
|
export { toString } from './util/toString.mjs';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts `value` to a safe integer.
|
|
3
|
+
*
|
|
4
|
+
* A safe integer can be compared and represented correctly.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to convert.
|
|
7
|
+
* @returns {number} Returns the value converted to a safe integer.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* toSafeInteger(3.2); // => 3
|
|
11
|
+
* toSafeInteger(Number.MAX_VALUE); // => 9007199254740991
|
|
12
|
+
* toSafeInteger(Infinity); // => 9007199254740991
|
|
13
|
+
* toSafeInteger('3.2'); // => 3
|
|
14
|
+
* toSafeInteger(NaN); // => 0
|
|
15
|
+
* toSafeInteger(null); // => 0
|
|
16
|
+
* toSafeInteger(-Infinity); // => -9007199254740991
|
|
17
|
+
*/
|
|
18
|
+
declare function toSafeInteger(value?: unknown): number;
|
|
19
|
+
|
|
20
|
+
export { toSafeInteger };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts `value` to a safe integer.
|
|
3
|
+
*
|
|
4
|
+
* A safe integer can be compared and represented correctly.
|
|
5
|
+
*
|
|
6
|
+
* @param {unknown} value - The value to convert.
|
|
7
|
+
* @returns {number} Returns the value converted to a safe integer.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* toSafeInteger(3.2); // => 3
|
|
11
|
+
* toSafeInteger(Number.MAX_VALUE); // => 9007199254740991
|
|
12
|
+
* toSafeInteger(Infinity); // => 9007199254740991
|
|
13
|
+
* toSafeInteger('3.2'); // => 3
|
|
14
|
+
* toSafeInteger(NaN); // => 0
|
|
15
|
+
* toSafeInteger(null); // => 0
|
|
16
|
+
* toSafeInteger(-Infinity); // => -9007199254740991
|
|
17
|
+
*/
|
|
18
|
+
declare function toSafeInteger(value?: unknown): number;
|
|
19
|
+
|
|
20
|
+
export { toSafeInteger };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { toInteger } from './toInteger.mjs';
|
|
2
|
+
import { MAX_SAFE_INTEGER } from '../_internal/MAX_SAFE_INTEGER.mjs';
|
|
3
|
+
import { clamp } from '../math/clamp.mjs';
|
|
4
|
+
|
|
5
|
+
function toSafeInteger(value) {
|
|
6
|
+
if (value == null) {
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
return clamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { toSafeInteger };
|
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.24.0-dev.
|
|
4
|
+
"version": "1.24.0-dev.770+faa0f2f5",
|
|
5
5
|
"homepage": "https://es-toolkit.slash.page",
|
|
6
6
|
"bugs": "https://github.com/toss/es-toolkit/issues",
|
|
7
7
|
"repository": {
|