ToIntegerOrInfinity.js 462 B

12345678910111213141516
  1. 'use strict';
  2. var ToNumber = require('./ToNumber');
  3. var truncate = require('./truncate');
  4. var $isNaN = require('../helpers/isNaN');
  5. var $isFinite = require('../helpers/isFinite');
  6. // https://262.ecma-international.org/14.0/#sec-tointegerorinfinity
  7. module.exports = function ToIntegerOrInfinity(value) {
  8. var number = ToNumber(value);
  9. if ($isNaN(number) || number === 0) { return 0; }
  10. if (!$isFinite(number)) { return number; }
  11. return truncate(number);
  12. };