UNPKG

@n3okill/utils

Version:
20 lines 946 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.pad = pad; const detectEncoding_1 = require("./detectEncoding"); const toString_1 = require("./toString"); const pad_1 = require("../string/pad"); /** * Pads the current Buffer with string (repeated, if needed) so that the resulting Buffer reaches the given length * The padding is applied form the start (left) if "start" is true or the end (right) if is false * @param str Buffer to be padded * @param length Final size of the Buffer * @param addString String to be added to the Buffer * @param start Pad from the start of the Buffer or from the end * @returns Padded Buffer */ function pad(str, length, addString = " ", start = true) { const encoding = (0, detectEncoding_1.detectEncoding)(str); return Buffer.from((0, pad_1.pad)((0, toString_1.toString)(str, encoding), length, addString, start), encoding); } //# sourceMappingURL=pad.js.map