29 lines
487 B
JavaScript
29 lines
487 B
JavaScript
/*!
|
|
* pad-left <https://github.com/jonschlinkert/pad-left>
|
|
*
|
|
* Copyright (c) 2014-2015, Jon Schlinkert.
|
|
* Licensed under the MIT license.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
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;
|
|
};
|