ToZeroPaddedDecimalString.js 568 B

1234567891011121314151617181920
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $String = GetIntrinsic('%String%');
  4. var $RangeError = require('es-errors/range');
  5. var StringPad = require('./StringPad');
  6. var isInteger = require('../helpers/isInteger');
  7. // https://262.ecma-international.org/13.0/#sec-tozeropaddeddecimalstring
  8. module.exports = function ToZeroPaddedDecimalString(n, minLength) {
  9. if (!isInteger(n) || n < 0) {
  10. throw new $RangeError('Assertion failed: `q` must be a non-negative integer');
  11. }
  12. var S = $String(n);
  13. return StringPad(S, minLength, '0', 'start');
  14. };