choo-shortcache
Version:
choo nanocomponent cache shortcut
29 lines (22 loc) • 487 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) {
str = str.toString();
if (typeof num === 'undefined') {
return str;
}
if (ch === 0) {
ch = '0';
} else if (ch) {
ch = ch.toString();
} else {
ch = ' ';
}
return repeat(ch, num - str.length) + str;
};