es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
13 lines (10 loc) • 342 B
JavaScript
import { toInteger } from './toInteger.mjs';
import { MAX_SAFE_INTEGER } from '../_internal/MAX_SAFE_INTEGER.mjs';
import { clamp } from '../math/clamp.mjs';
function toSafeInteger(value) {
if (value == null) {
return 0;
}
return clamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
}
export { toSafeInteger };