toString.js 645 B

1234567891011121314151617181920
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var callBound = require('call-bound');
  4. var isInteger = require('math-intrinsics/isInteger');
  5. var $numberToString = callBound('Number.prototype.toString');
  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. };