1 var isIterateeCall = require('../internal/isIterateeCall'),
2 trim = require('./trim');
4 /** Used to detect hexadecimal string values. */
5 var reHasHexPrefix = /^0[xX]/;
7 /* Native method references for those with the same name as other `lodash` methods. */
8 var nativeParseInt = global.parseInt;
11 * Converts `string` to an integer of the specified radix. If `radix` is
12 * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
13 * in which case a `radix` of `16` is used.
15 * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
21 * @param {string} string The string to convert.
22 * @param {number} [radix] The radix to interpret `value` by.
23 * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
24 * @returns {number} Returns the converted integer.
30 * _.map(['6', '08', '10'], _.parseInt);
33 function parseInt(string, radix, guard) {
34 // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
35 // Chrome fails to trim leading <BOM> whitespace characters.
36 // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
37 if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
42 string = trim(string);
43 return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
46 module.exports = parseInt;