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.
21 lines
566 B
21 lines
566 B
var longest = require('./longest'); |
|
var isArr = require('./isArr'); |
|
var isUndef = require('./isUndef'); |
|
var map = require('./map'); |
|
var lpad = require('./lpad'); |
|
exports = function(str, width) { |
|
var ret = str; |
|
if (!isArr(ret)) { |
|
ret = ret.split(regLineBreak); |
|
} |
|
if (isUndef(width)) width = longest(str); |
|
ret = map(ret, function(str) { |
|
var len = str.length; |
|
return lpad(str, floor((width - len) / 2) + len); |
|
}); |
|
return ret.join('\n'); |
|
}; |
|
var regLineBreak = /\n/g; |
|
var floor = Math.floor; |
|
|
|
module.exports = exports;
|
|
|