number-parse-int.js 553 B

1234567891011121314
  1. var global = require('../internals/global');
  2. var trim = require('../internals/string-trim').trim;
  3. var whitespaces = require('../internals/whitespaces');
  4. var $parseInt = global.parseInt;
  5. var hex = /^[+-]?0[Xx]/;
  6. var FORCED = $parseInt(whitespaces + '08') !== 8 || $parseInt(whitespaces + '0x16') !== 22;
  7. // `parseInt` method
  8. // https://tc39.es/ecma262/#sec-parseint-string-radix
  9. module.exports = FORCED ? function parseInt(string, radix) {
  10. var S = trim(String(string));
  11. return $parseInt(S, (radix >>> 0) || (hex.test(S) ? 16 : 10));
  12. } : $parseInt;