lpad.js 388 B

1234567891011121314151617
  1. var toString = require('../lang/toString');
  2. var repeat = require('./repeat');
  3. /**
  4. * Pad string with `char` if its' length is smaller than `minLen`
  5. */
  6. function lpad(str, minLen, ch) {
  7. str = toString(str);
  8. ch = ch || ' ';
  9. return (str.length < minLen) ?
  10. repeat(ch, minLen - str.length) + str : str;
  11. }
  12. module.exports = lpad;