main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
866 bytes
|
Rev | Line | |
---|
[d565449] | 1 | import toNumber from './toNumber.js';
|
---|
| 2 |
|
---|
| 3 | /** Used as references for various `Number` constants. */
|
---|
| 4 | var INFINITY = 1 / 0,
|
---|
| 5 | MAX_INTEGER = 1.7976931348623157e+308;
|
---|
| 6 |
|
---|
| 7 | /**
|
---|
| 8 | * Converts `value` to a finite number.
|
---|
| 9 | *
|
---|
| 10 | * @static
|
---|
| 11 | * @memberOf _
|
---|
| 12 | * @since 4.12.0
|
---|
| 13 | * @category Lang
|
---|
| 14 | * @param {*} value The value to convert.
|
---|
| 15 | * @returns {number} Returns the converted number.
|
---|
| 16 | * @example
|
---|
| 17 | *
|
---|
| 18 | * _.toFinite(3.2);
|
---|
| 19 | * // => 3.2
|
---|
| 20 | *
|
---|
| 21 | * _.toFinite(Number.MIN_VALUE);
|
---|
| 22 | * // => 5e-324
|
---|
| 23 | *
|
---|
| 24 | * _.toFinite(Infinity);
|
---|
| 25 | * // => 1.7976931348623157e+308
|
---|
| 26 | *
|
---|
| 27 | * _.toFinite('3.2');
|
---|
| 28 | * // => 3.2
|
---|
| 29 | */
|
---|
| 30 | function toFinite(value) {
|
---|
| 31 | if (!value) {
|
---|
| 32 | return value === 0 ? value : 0;
|
---|
| 33 | }
|
---|
| 34 | value = toNumber(value);
|
---|
| 35 | if (value === INFINITY || value === -INFINITY) {
|
---|
| 36 | var sign = (value < 0 ? -1 : 1);
|
---|
| 37 | return sign * MAX_INTEGER;
|
---|
| 38 | }
|
---|
| 39 | return value === value ? value : 0;
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | export default toFinite;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.