|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
816 bytes
|
| Rev | Line | |
|---|
| [a762898] | 1 | /**
|
|---|
| 2 | * Checks if `value` is a safe integer (between -(2^53 – 1) and (2^53 – 1), inclusive).
|
|---|
| 3 | *
|
|---|
| 4 | * A safe integer is an integer that can be precisely represented as a `number` in JavaScript,
|
|---|
| 5 | * without any other integer being rounded to it.
|
|---|
| 6 | *
|
|---|
| 7 | * This function also serves as a type predicate in TypeScript,
|
|---|
| 8 | * narrowing the type of the argument to `number`.
|
|---|
| 9 | *
|
|---|
| 10 | * @param {unknown} value - The value to check
|
|---|
| 11 | * @returns {value is number} `true` if `value` is an integer and between the safe values, otherwise `false`
|
|---|
| 12 | *
|
|---|
| 13 | * @example
|
|---|
| 14 | * isSafeInteger(3); // Returns: true
|
|---|
| 15 | * isSafeInteger(Number.MIN_SAFE_INTEGER - 1); // Returns: false
|
|---|
| 16 | * isSafeInteger(1n); // Returns: false
|
|---|
| 17 | * isSafeInteger('1'); // Returns: false
|
|---|
| 18 | */
|
|---|
| 19 | declare function isSafeInteger(value: unknown): value is number;
|
|---|
| 20 |
|
|---|
| 21 | export { isSafeInteger };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.