pad-left
Version:
Left pad a string with zeros or a specified string. Fastest implementation.
16 lines (12 loc) • 352 B
JavaScript
/*!
* pad-left <https://github.com/jonschlinkert/pad-left>
*
* Copyright (c) 2014-2015, Jon Schlinkert.
* Licensed under the MIT license.
*/
;
var repeat = require('repeat-string');
module.exports = function padLeft(str, num, ch) {
ch = typeof ch !== 'undefined' ? (ch + '') : ' ';
return repeat(ch, num - str.length) + str;
};