You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

15 lines
427 B

var repeat = require('./repeat');
var toStr = require('./toStr');
exports = function(str, len, chars) {
str = toStr(str);
var strLen = str.length;
chars = chars || ' ';
if (strLen < len) {
var padStr = repeat(chars, Math.ceil((len - strLen) / 2));
str = padStr + str + padStr;
str = str.substr(Math.ceil((str.length - len) / 2), len);
}
return str;
};
module.exports = exports;