|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
792 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 | var isInteger = require('math-intrinsics/isInteger');
|
|---|
| 10 |
|
|---|
| 11 | // https://262.ecma-international.org/11.0/#sec-numbertobigint
|
|---|
| 12 |
|
|---|
| 13 | module.exports = function NumberToBigInt(number) {
|
|---|
| 14 | if (typeof number !== 'number') {
|
|---|
| 15 | throw new $TypeError('Assertion failed: `number` must be a String');
|
|---|
| 16 | }
|
|---|
| 17 | if (!isInteger(number)) {
|
|---|
| 18 | throw new $RangeError('The number ' + number + ' cannot be converted to a BigInt because it is not an integer');
|
|---|
| 19 | }
|
|---|
| 20 | if (!$BigInt) {
|
|---|
| 21 | throw new $SyntaxError('BigInts are not supported in this environment');
|
|---|
| 22 | }
|
|---|
| 23 | return $BigInt(number);
|
|---|
| 24 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.