es-toolkit/docs/reference/compat/predicate/isSafeInteger.md
raon0211 06f68c20b9
Some checks are pending
CI / codecov (push) Waiting to run
Release / release (push) Waiting to run
docs: Fix docs style
2024-09-14 14:47:53 +09:00

1.1 KiB
Raw Blame History

isSafeInteger

::: info This function is only available in es-toolkit/compat for compatibility reasons. It either has alternative native JavaScript APIs or isnt fully optimized yet.

When imported from es-toolkit/compat, it behaves exactly like lodash and provides the same functionalities, as detailed here. :::

Checks if value is a safe integer (between -(2^53 1) and (2^53 1), inclusive).

A safe integer is an integer that can be exactly represented as a double precision number, and no other integer rounds to it under any IEEE-754 rounding mode.

This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to number.

Signature

function isSafeInteger(value?: unknown): boolean;

Parameters

  • value (unknown): The value to check

Returns

(boolean): true if value is an integer and between the safe values, otherwise false

Examples

isInteger(3); // Returns: true
isInteger(Number.MIN_SAFE_INTEGER - 1); // Returns: false
isInteger(1n); // Returns: false
isInteger('1'); // Returns: false