ToNumeric.js 550 B

123456789101112131415161718192021
  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. var Type = require('./Type');
  8. // https://262.ecma-international.org/6.0/#sec-tonumber
  9. module.exports = function ToNumeric(argument) {
  10. var primValue = isPrimitive(argument) ? argument : ToPrimitive(argument, $Number);
  11. if (Type(primValue) === 'BigInt') {
  12. return primValue;
  13. }
  14. return ToNumber(primValue);
  15. };