toString.js 791 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. var $SyntaxError = require('es-errors/syntax');
  3. var $TypeError = require('es-errors/type');
  4. var callBound = require('call-bind/callBound');
  5. var $BigIntToString = callBound('BigInt.prototype.toString', true);
  6. var isInteger = require('../../helpers/isInteger');
  7. // https://262.ecma-international.org/14.0/#sec-numeric-types-bigint-tostring
  8. module.exports = function BigIntToString(x, radix) {
  9. if (typeof x !== 'bigint') {
  10. throw new $TypeError('Assertion failed: `x` must be a BigInt');
  11. }
  12. if (!isInteger(radix) || radix < 2 || radix > 36) {
  13. throw new $TypeError('Assertion failed: `radix` must be an integer >= 2 and <= 36');
  14. }
  15. if (!$BigIntToString) {
  16. throw new $SyntaxError('BigInt is not supported');
  17. }
  18. return $BigIntToString(x, radix); // steps 1 - 12
  19. };