pad.js 405 B

12345678910111213141516
  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(
  10. precision ? toFixed.call(this, precision) : this, "0",
  11. length + (precision ? 1 + precision : 0)
  12. );
  13. };