ToZeroPaddedDecimalString.js 586 B

12345678910111213141516171819
  1. 'use strict';
  2. var GetIntrinsic = require('get-intrinsic');
  3. var $String = GetIntrinsic('%String%');
  4. var $RangeError = GetIntrinsic('%RangeError%');
  5. var IsIntegralNumber = require('./IsIntegralNumber');
  6. var StringPad = require('./StringPad');
  7. // https://ecma-international.org/ecma-262/13.0/#sec-tozeropaddeddecimalstring
  8. module.exports = function ToZeroPaddedDecimalString(n, minLength) {
  9. if (!IsIntegralNumber(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. };