15 lines
585 B
JavaScript
15 lines
585 B
JavaScript
|
var global = require('../internals/global');
|
||
|
var trim = require('../internals/string-trim').trim;
|
||
|
var whitespaces = require('../internals/whitespaces');
|
||
|
|
||
|
var nativeParseInt = global.parseInt;
|
||
|
var hex = /^[+-]?0[Xx]/;
|
||
|
var FORCED = nativeParseInt(whitespaces + '08') !== 8 || nativeParseInt(whitespaces + '0x16') !== 22;
|
||
|
|
||
|
// `parseInt` method
|
||
|
// https://tc39.github.io/ecma262/#sec-parseint-string-radix
|
||
|
module.exports = FORCED ? function parseInt(string, radix) {
|
||
|
var S = trim(String(string));
|
||
|
return nativeParseInt(S, (radix >>> 0) || (hex.test(S) ? 16 : 10));
|
||
|
} : nativeParseInt;
|