UNPKG

cli-util

Version:
16 lines (14 loc) 425 B
var repeat = require('./repeat'); /** * Pad a string with leading or trailing whitespace. * * Default is to add trailing whitespace. * * @param str The string to pad. * @param width The target character width. * @param leading Pad before the string. */ module.exports = function pad(str, width, leading) { var len = Math.max(0, width - str.length); return leading ? repeat(len) + str : str + repeat(len); }