1 var root = require('./_root'),
2 toString = require('./toString');
4 /** Used to match leading and trailing whitespace. */
5 var reTrim = /^\s+|\s+$/g;
7 /** Used to detect hexadecimal string values. */
8 var reHasHexPrefix = /^0x/i;
10 /* Built-in method references for those with the same name as other `lodash` methods. */
11 var nativeParseInt = root.parseInt;
14 * Converts `string` to an integer of the specified radix. If `radix` is
15 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
16 * in which case a `radix` of `16` is used.
18 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2)
24 * @param {string} string The string to convert.
25 * @param {number} [radix] The radix to interpret `value` by.
26 * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
27 * @returns {number} Returns the converted integer.
33 * _.map(['6', '08', '10'], _.parseInt);
36 function parseInt(string, radix, guard) {
37 // Chrome fails to trim leading <BOM> whitespace characters.
38 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
39 if (guard || radix == null) {
44 string = toString(string).replace(reTrim, '');
45 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
48 module.exports = parseInt;