number-parse-float.js 945 B

12345678910111213141516171819202122
  1. var global = require('../internals/global');
  2. var fails = require('../internals/fails');
  3. var uncurryThis = require('../internals/function-uncurry-this');
  4. var toString = require('../internals/to-string');
  5. var trim = require('../internals/string-trim').trim;
  6. var whitespaces = require('../internals/whitespaces');
  7. var charAt = uncurryThis(''.charAt);
  8. var $parseFloat = global.parseFloat;
  9. var Symbol = global.Symbol;
  10. var ITERATOR = Symbol && Symbol.iterator;
  11. var FORCED = 1 / $parseFloat(whitespaces + '-0') !== -Infinity
  12. // MS Edge 18- broken with boxed symbols
  13. || (ITERATOR && !fails(function () { $parseFloat(Object(ITERATOR)); }));
  14. // `parseFloat` method
  15. // https://tc39.es/ecma262/#sec-parsefloat-string
  16. module.exports = FORCED ? function parseFloat(string) {
  17. var trimmedString = trim(toString(string));
  18. var result = $parseFloat(trimmedString);
  19. return result === 0 && charAt(trimmedString, 0) == '-' ? -0 : result;
  20. } : $parseFloat;