Sha256: 50248f9eab6f7e15e97a69ceca1cdbaab88513b20deebde9ee94a1d87a611e4c

Contents?: true

Size: 1.5 KB

Versions: 153

Compression:

Stored size: 1.5 KB

Contents

var isIterateeCall = require('../internal/isIterateeCall'),
    trim = require('./trim');

/** Used to detect hexadecimal string values. */
var reHasHexPrefix = /^0[xX]/;

/* Native method references for those with the same name as other `lodash` methods. */
var nativeParseInt = global.parseInt;

/**
 * Converts `string` to an integer of the specified radix. If `radix` is
 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
 * in which case a `radix` of `16` is used.
 *
 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
 * of `parseInt`.
 *
 * @static
 * @memberOf _
 * @category String
 * @param {string} string The string to convert.
 * @param {number} [radix] The radix to interpret `value` by.
 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
 * @returns {number} Returns the converted integer.
 * @example
 *
 * _.parseInt('08');
 * // => 8
 *
 * _.map(['6', '08', '10'], _.parseInt);
 * // => [6, 8, 10]
 */
function parseInt(string, radix, guard) {
  // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
  // Chrome fails to trim leading <BOM> whitespace characters.
  // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
  if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
    radix = 0;
  } else if (radix) {
    radix = +radix;
  }
  string = trim(string);
  return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
}

module.exports = parseInt;

Version data entries

153 entries across 80 versions & 8 rubygems

Version Path
ilog-0.4.1 node_modules/contents/node_modules/lodash/string/parseInt.js
ilog-0.4.1 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/string/parseInt.js
ilog-0.4.1 node_modules/babel/node_modules/lodash/string/parseInt.js
ilog-0.4.0 node_modules/babel/node_modules/lodash/string/parseInt.js
ilog-0.4.0 node_modules/contents/node_modules/lodash/string/parseInt.js
ilog-0.4.0 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/string/parseInt.js
ilog-0.3.3 node_modules/babel/node_modules/lodash/string/parseInt.js
ilog-0.3.3 node_modules/contents/node_modules/lodash/string/parseInt.js
ilog-0.3.3 node_modules/babel-plugin-proto-to-assign/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/parseInt.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/configstore/node_modules/js-yaml/node_modules/argparse/node_modules/lodash/string/parseInt.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/inquirer/node_modules/lodash/string/parseInt.js