UNPKG

dop-stick

Version:

Source control tooling for versionable-upgradeable smart contracts

43 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextFormat = void 0; class TextFormat { static truncate(text, length, suffix = '...') { if (text.length <= length) return text; return text.slice(0, length - suffix.length) + suffix; } static pad(text, length, char = ' ') { const padding = Math.max(0, length - text.length); return text + char.repeat(padding); } static center(text, length, char = ' ') { const padding = Math.max(0, length - text.length); const leftPad = Math.floor(padding / 2); const rightPad = padding - leftPad; return char.repeat(leftPad) + text + char.repeat(rightPad); } static indent(text, spaces = 2) { return text.split('\n').map(line => ' '.repeat(spaces) + line).join('\n'); } static wrap(text, width) { const words = text.split(' '); const lines = []; let currentLine = ''; words.forEach(word => { const testLine = currentLine ? currentLine + ' ' + word : word; if (testLine.length <= width) { currentLine = testLine; } else { lines.push(currentLine); currentLine = word; } }); if (currentLine) lines.push(currentLine); return lines; } } exports.TextFormat = TextFormat; //# sourceMappingURL=format.js.map