toString.js 654 B

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