toString.js 733 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $TypeError = GetIntrinsic('%TypeError%');
  4. var callBound = require('call-bind/callBound');
  5. var $numberToString = callBound('Number.prototype.toString');
  6. var Type = require('../Type');
  7. var isInteger = require('../../helpers/isInteger');
  8. // https://262.ecma-international.org/14.0/#sec-numeric-types-number-tostring
  9. module.exports = function NumberToString(x, radix) {
  10. if (Type(x) !== 'Number') {
  11. throw new $TypeError('Assertion failed: `x` must be a Number');
  12. }
  13. if (!isInteger(radix) || radix < 2 || radix > 36) {
  14. throw new $TypeError('Assertion failed: `radix` must be an integer >= 2 and <= 36');
  15. }
  16. return $numberToString(x, radix); // steps 1 - 12
  17. };