main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
800 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 |
|
---|
5 | var $BigInt = GetIntrinsic('%BigInt%', true);
|
---|
6 | var $RangeError = require('es-errors/range');
|
---|
7 | var $SyntaxError = require('es-errors/syntax');
|
---|
8 | var $TypeError = require('es-errors/type');
|
---|
9 |
|
---|
10 | var IsIntegralNumber = require('./IsIntegralNumber');
|
---|
11 |
|
---|
12 | // https://262.ecma-international.org/12.0/#sec-numbertobigint
|
---|
13 |
|
---|
14 | module.exports = function NumberToBigInt(number) {
|
---|
15 | if (typeof number !== 'number') {
|
---|
16 | throw new $TypeError('Assertion failed: `number` must be a String');
|
---|
17 | }
|
---|
18 | if (!IsIntegralNumber(number)) {
|
---|
19 | throw new $RangeError('The number ' + number + ' cannot be converted to a BigInt because it is not an integer');
|
---|
20 | }
|
---|
21 | if (!$BigInt) {
|
---|
22 | throw new $SyntaxError('BigInts are not supported in this environment');
|
---|
23 | }
|
---|
24 | return $BigInt(number);
|
---|
25 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.