main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
834 bytes
|
Line | |
---|
1 | import baseClamp from './_baseClamp.js';
|
---|
2 | import toInteger from './toInteger.js';
|
---|
3 |
|
---|
4 | /** Used as references for various `Number` constants. */
|
---|
5 | var MAX_SAFE_INTEGER = 9007199254740991;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Converts `value` to a safe integer. A safe integer can be compared and
|
---|
9 | * represented correctly.
|
---|
10 | *
|
---|
11 | * @static
|
---|
12 | * @memberOf _
|
---|
13 | * @since 4.0.0
|
---|
14 | * @category Lang
|
---|
15 | * @param {*} value The value to convert.
|
---|
16 | * @returns {number} Returns the converted integer.
|
---|
17 | * @example
|
---|
18 | *
|
---|
19 | * _.toSafeInteger(3.2);
|
---|
20 | * // => 3
|
---|
21 | *
|
---|
22 | * _.toSafeInteger(Number.MIN_VALUE);
|
---|
23 | * // => 0
|
---|
24 | *
|
---|
25 | * _.toSafeInteger(Infinity);
|
---|
26 | * // => 9007199254740991
|
---|
27 | *
|
---|
28 | * _.toSafeInteger('3.2');
|
---|
29 | * // => 3
|
---|
30 | */
|
---|
31 | function toSafeInteger(value) {
|
---|
32 | return value
|
---|
33 | ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
|
---|
34 | : (value === 0 ? value : 0);
|
---|
35 | }
|
---|
36 |
|
---|
37 | export default toSafeInteger;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.