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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $TypeError = require('es-errors/type');
|
---|
| 6 | var $Number = GetIntrinsic('%Number%');
|
---|
| 7 | var isPrimitive = require('../helpers/isPrimitive');
|
---|
| 8 |
|
---|
| 9 | var ToPrimitive = require('./ToPrimitive');
|
---|
| 10 | var StringToNumber = require('./StringToNumber');
|
---|
| 11 |
|
---|
| 12 | // https://262.ecma-international.org/13.0/#sec-tonumber
|
---|
| 13 |
|
---|
| 14 | module.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.