PageRenderTime 14ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/node_modules/lodash/toFinite.js

https://bitbucket.org/coleman333/smartsite
JavaScript | 42 lines | 15 code | 3 blank | 24 comment | 3 complexity | 9eaaaac9bcd246afb349c4b47ad8527f MD5 | raw file
 1var toNumber = require('./toNumber');
 2
 3/** Used as references for various `Number` constants. */
 4var 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 */
30function 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
42module.exports = toFinite;