Sha256: 1dceb1da4f87066299be510852a9106b73240df14258385b2ae13255d23c665a

Contents?: true

Size: 1.48 KB

Versions: 101

Compression:

Stored size: 1.48 KB

Contents

var baseTrim = require('./_baseTrim'),
    isObject = require('./isObject'),
    isSymbol = require('./isSymbol');

/** Used as references for various `Number` constants. */
var NAN = 0 / 0;

/** Used to detect bad signed hexadecimal string values. */
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;

/** Used to detect binary string values. */
var reIsBinary = /^0b[01]+$/i;

/** Used to detect octal string values. */
var reIsOctal = /^0o[0-7]+$/i;

/** Built-in method references without a dependency on `root`. */
var freeParseInt = parseInt;

/**
 * Converts `value` to a number.
 *
 * @static
 * @memberOf _
 * @since 4.0.0
 * @category Lang
 * @param {*} value The value to process.
 * @returns {number} Returns the number.
 * @example
 *
 * _.toNumber(3.2);
 * // => 3.2
 *
 * _.toNumber(Number.MIN_VALUE);
 * // => 5e-324
 *
 * _.toNumber(Infinity);
 * // => Infinity
 *
 * _.toNumber('3.2');
 * // => 3.2
 */
function toNumber(value) {
  if (typeof value == 'number') {
    return value;
  }
  if (isSymbol(value)) {
    return NAN;
  }
  if (isObject(value)) {
    var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
    value = isObject(other) ? (other + '') : other;
  }
  if (typeof value != 'string') {
    return value === 0 ? value : +value;
  }
  value = baseTrim(value);
  var isBinary = reIsBinary.test(value);
  return (isBinary || reIsOctal.test(value))
    ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
    : (reIsBadHex.test(value) ? NAN : +value);
}

module.exports = toNumber;

Version data entries

101 entries across 100 versions & 8 rubygems

Version Path
appmap-0.67.0 ./node_modules/lodash/toNumber.js
appmap-0.66.2 ./node_modules/lodash/toNumber.js
trusty-cms-5.0.1 node_modules/lodash/toNumber.js
trusty-cms-4.3.5 node_modules/lodash/toNumber.js
trusty-cms-5.0.0 node_modules/lodash/toNumber.js
appmap-0.66.1 ./node_modules/lodash/toNumber.js
appmap-0.66.0 ./node_modules/lodash/toNumber.js
appmap-0.65.1 ./node_modules/lodash/toNumber.js
appmap-0.65.0 ./node_modules/lodash/toNumber.js
trusty-cms-4.3.4 node_modules/lodash/toNumber.js
appmap-0.64.0 ./node_modules/lodash/toNumber.js
appmap-0.63.0 ./node_modules/lodash/toNumber.js
jekyll-esm-0.0.3 node_modules/lodash/toNumber.js
trusty-cms-4.3.3 node_modules/lodash/toNumber.js
trusty-cms-4.3.2 node_modules/lodash/toNumber.js
trusty-cms-4.3.1 node_modules/lodash/toNumber.js
trusty-cms-4.2.3 node_modules/lodash/toNumber.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/lodash/toNumber.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/lodash/toNumber.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/lodash/toNumber.js