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:
788 bytes
|
Rev | Line | |
---|
[d565449] | 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 isInteger = require('../helpers/isInteger');
|
---|
| 11 |
|
---|
| 12 | // https://262.ecma-international.org/11.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 (!isInteger(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.