function pad(str, width, char) {
        // undefined inputs always return undefined
        if (typeof str === 'undefined') {
            return undefined;
        }

        if (typeof char === 'undefined' || char.length === 0) {
            char = ' ';
        }

        var result;
        width = Math.trunc(width);
        var padLength = Math.abs(width) - length(str);
        if (padLength > 0) {
            var padding = (new Array(padLength + 1)).join(char);
            if (char.length > 1) {
                padding = substring(padding, 0, padLength);
            }
            if (width > 0) {
                result = str + padding;
            } else {
                result = padding + str;
            }
        } else {
            result = str;
        }
        return result;
    }
Pad a string to a minimum width by adding characters to the start or end
@param {string} str - string to be padded
@param {number} width - the minimum width; +ve pads to the right, -ve pads to the left
@param {string} [char] - the pad character(s); defaults to ' '
@returns {string} - padded string