UNPKG

stylesh

Version:

A powerful and elegant terminal styling library with colors, gradients, borders, themes, and animations for Node.js

36 lines 1.14 kB
"use strict"; /** * Text alignment utilities */ Object.defineProperty(exports, "__esModule", { value: true }); exports.padText = padText; exports.alignLines = alignLines; const textWidth_1 = require("./textWidth"); /** * Pad text to align it within a given width */ function padText(text, totalWidth, alignment = 'center') { const visibleWidth = (0, textWidth_1.getVisibleWidth)(text); const paddingNeeded = totalWidth - visibleWidth; if (paddingNeeded <= 0) { return text; } switch (alignment) { case 'left': return text + ' '.repeat(paddingNeeded); case 'right': return ' '.repeat(paddingNeeded) + text; case 'center': default: const leftPadding = Math.floor(paddingNeeded / 2); const rightPadding = Math.ceil(paddingNeeded / 2); return ' '.repeat(leftPadding) + text + ' '.repeat(rightPadding); } } /** * Align multiple lines of text */ function alignLines(lines, maxWidth, alignment = 'center') { return lines.map(line => padText(line, maxWidth, alignment)); } //# sourceMappingURL=textAlign.js.map