react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / js-yaml / node_modules / argparse / node_modules / lodash / string / parseInt.js
80742 viewsvar isIterateeCall = require('../internal/isIterateeCall'),1trim = require('./trim');23/** Used to detect hexadecimal string values. */4var reHasHexPrefix = /^0[xX]/;56/** Used to detect and test for whitespace. */7var whitespace = (8// Basic whitespace characters.9' \t\x0b\f\xa0\ufeff' +1011// Line terminators.12'\n\r\u2028\u2029' +1314// Unicode category "Zs" space separators.15'\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'16);1718/* Native method references for those with the same name as other `lodash` methods. */19var nativeParseInt = global.parseInt;2021/**22* Converts `string` to an integer of the specified radix. If `radix` is23* `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,24* in which case a `radix` of `16` is used.25*26* **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)27* of `parseInt`.28*29* @static30* @memberOf _31* @category String32* @param {string} string The string to convert.33* @param {number} [radix] The radix to interpret `value` by.34* @param- {Object} [guard] Enables use as a callback for functions like `_.map`.35* @returns {number} Returns the converted integer.36* @example37*38* _.parseInt('08');39* // => 840*41* _.map(['6', '08', '10'], _.parseInt);42* // => [6, 8, 10]43*/44function parseInt(string, radix, guard) {45if (guard && isIterateeCall(string, radix, guard)) {46radix = 0;47}48return nativeParseInt(string, radix);49}50// Fallback for environments with pre-ES5 implementations.51if (nativeParseInt(whitespace + '08') != 8) {52parseInt = function(string, radix, guard) {53// Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.54// Chrome fails to trim leading <BOM> whitespace characters.55// See https://code.google.com/p/v8/issues/detail?id=3109 for more details.56if (guard ? isIterateeCall(string, radix, guard) : radix == null) {57radix = 0;58} else if (radix) {59radix = +radix;60}61string = trim(string);62return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));63};64}6566module.exports = parseInt;676869