rpad.js 374 B

123456789101112131415
  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 rpad(str, minLen, ch) {
  7. str = toString(str);
  8. ch = ch || ' ';
  9. return (str.length < minLen)? str + repeat(ch, minLen - str.length) : str;
  10. }
  11. module.exports = rpad;