Security update for permissions_by_term
[yaffs-website] / node_modules / uncss / node_modules / lodash / parseInt.js
1 var toString = require('./toString');
2
3 /** Used to match leading and trailing whitespace. */
4 var reTrim = /^\s+|\s+$/g;
5
6 /** Used to detect hexadecimal string values. */
7 var reHasHexPrefix = /^0x/i;
8
9 /* Built-in method references for those with the same name as other `lodash` methods. */
10 var nativeParseInt = global.parseInt;
11
12 /**
13  * Converts `string` to an integer of the specified radix. If `radix` is
14  * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
15  * in which case a `radix` of `16` is used.
16  *
17  * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#x15.1.2.2)
18  * of `parseInt`.
19  *
20  * @static
21  * @memberOf _
22  * @category String
23  * @param {string} string The string to convert.
24  * @param {number} [radix] The radix to interpret `value` by.
25  * @param- {Object} [guard] Enables use as an iteratee for functions like `_.map`.
26  * @returns {number} Returns the converted integer.
27  * @example
28  *
29  * _.parseInt('08');
30  * // => 8
31  *
32  * _.map(['6', '08', '10'], _.parseInt);
33  * // => [6, 8, 10]
34  */
35 function parseInt(string, radix, guard) {
36   // Chrome fails to trim leading <BOM> whitespace characters.
37   // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
38   if (guard || radix == null) {
39     radix = 0;
40   } else if (radix) {
41     radix = +radix;
42   }
43   string = toString(string).replace(reTrim, '');
44   return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
45 }
46
47 module.exports = parseInt;