ToNumeric.js 523 B

1234567891011121314151617181920
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $Number = GetIntrinsic('%Number%');
  4. var isPrimitive = require('../helpers/isPrimitive');
  5. var ToPrimitive = require('./ToPrimitive');
  6. var ToNumber = require('./ToNumber');
  7. // https://262.ecma-international.org/11.0/#sec-tonumeric
  8. module.exports = function ToNumeric(argument) {
  9. var primValue = isPrimitive(argument) ? argument : ToPrimitive(argument, $Number);
  10. if (typeof primValue === 'bigint') {
  11. return primValue;
  12. }
  13. return ToNumber(primValue);
  14. };