pad.js 402 B

123456789101112131415
  1. 'use strict';
  2. var pad = require('../../string/#/pad')
  3. , toPosInt = require('../to-pos-integer')
  4. , toFixed = Number.prototype.toFixed;
  5. module.exports = function (length/*, precision*/) {
  6. var precision;
  7. length = toPosInt(length);
  8. precision = toPosInt(arguments[1]);
  9. return pad.call(precision ? toFixed.call(this, precision) : this,
  10. '0', length + (precision ? (1 + precision) : 0));
  11. };