UNPKG

945 BJavaScriptView Raw
1'use strict';
2var global = require('../internals/global');
3var fails = require('../internals/fails');
4var uncurryThis = require('../internals/function-uncurry-this');
5var toString = require('../internals/to-string');
6var trim = require('../internals/string-trim').trim;
7var whitespaces = require('../internals/whitespaces');
8
9var $parseInt = global.parseInt;
10var Symbol = global.Symbol;
11var ITERATOR = Symbol && Symbol.iterator;
12var hex = /^[+-]?0x/i;
13var exec = uncurryThis(hex.exec);
14var FORCED = $parseInt(whitespaces + '08') !== 8 || $parseInt(whitespaces + '0x16') !== 22
15 // MS Edge 18- broken with boxed symbols
16 || (ITERATOR && !fails(function () { $parseInt(Object(ITERATOR)); }));
17
18// `parseInt` method
19// https://tc39.es/ecma262/#sec-parseint-string-radix
20module.exports = FORCED ? function parseInt(string, radix) {
21 var S = trim(toString(string));
22 return $parseInt(S, (radix >>> 0) || (exec(hex, S) ? 16 : 10));
23} : $parseInt;