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:
588 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $BigInt = GetIntrinsic('%BigInt%', true);
|
---|
| 6 | var $TypeError = require('es-errors/type');
|
---|
| 7 | var $SyntaxError = require('es-errors/syntax');
|
---|
| 8 |
|
---|
| 9 | // https://262.ecma-international.org/14.0/#sec-stringtobigint
|
---|
| 10 |
|
---|
| 11 | module.exports = function StringToBigInt(argument) {
|
---|
| 12 | if (typeof argument !== 'string') {
|
---|
| 13 | throw new $TypeError('`argument` must be a string');
|
---|
| 14 | }
|
---|
| 15 | if (!$BigInt) {
|
---|
| 16 | throw new $SyntaxError('BigInts are not supported in this environment');
|
---|
| 17 | }
|
---|
| 18 | try {
|
---|
| 19 | return $BigInt(argument);
|
---|
| 20 | } catch (e) {
|
---|
| 21 | return void undefined;
|
---|
| 22 | }
|
---|
| 23 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.