source: imaps-frontend/node_modules/es-abstract/2022/ToNumber.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 802 bytes
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = require('es-errors/type');
6var $Number = GetIntrinsic('%Number%');
7var isPrimitive = require('../helpers/isPrimitive');
8
9var ToPrimitive = require('./ToPrimitive');
10var StringToNumber = require('./StringToNumber');
11
12// https://262.ecma-international.org/13.0/#sec-tonumber
13
14module.exports = function ToNumber(argument) {
15 var value = isPrimitive(argument) ? argument : ToPrimitive(argument, $Number);
16 if (typeof value === 'symbol') {
17 throw new $TypeError('Cannot convert a Symbol value to a number');
18 }
19 if (typeof value === 'bigint') {
20 throw new $TypeError('Conversion from \'BigInt\' to \'number\' is not allowed.');
21 }
22 if (typeof value === 'string') {
23 return StringToNumber(value);
24 }
25 return $Number(value);
26};
Note: See TracBrowser for help on using the repository browser.