Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / string / parseInt.js
1 var isIterateeCall = require('../internal/isIterateeCall'),
2     trim = require('./trim');
3
4 /** Used to detect hexadecimal string values. */
5 var reHasHexPrefix = /^0[xX]/;
6
7 /* Native method references for those with the same name as other `lodash` methods. */
8 var nativeParseInt = global.parseInt;
9
10 /**
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.
14  *
15  * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
16  * of `parseInt`.
17  *
18  * @static
19  * @memberOf _
20  * @category String
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.
25  * @example
26  *
27  * _.parseInt('08');
28  * // => 8
29  *
30  * _.map(['6', '08', '10'], _.parseInt);
31  * // => [6, 8, 10]
32  */
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) {
38     radix = 0;
39   } else if (radix) {
40     radix = +radix;
41   }
42   string = trim(string);
43   return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
44 }
45
46 module.exports = parseInt;