@visulima/string
Version:
Functions for manipulating strings.
46 lines (45 loc) • 1.29 kB
TypeScript
import { StringWidthOptions } from "./get-string-width.js";
import "./get-string-truncated-width.js";
/**
* Options for controlling the text alignment.
*/
type AlignTextOptions = {
/**
* The alignment direction.
* @default "center"
*/
align?: "center" | "left" | "right";
/**
* Character used for padding when aligning text.
* @default " "
*/
pad?: string;
/**
* The character to split the input string by, if it's a single string.
* @default "\n"
*/
split?: string;
/**
* Options to pass to `getStringWidth` for calculating the width of each line.
*/
stringWidthOptions?: StringWidthOptions;
};
/**
* Aligns text (including multi-line strings with ANSI escape codes) to the left, center, or right.
* @example
* ```typescript
* alignText("Hello\nWorld!", { align: "right" });
* // => " Hello\nWorld!"
*
* alignText(["Beep", "Boop\nBop"], { align: "center" });
* // => [
* // " Beep",
* // "Boop\n Bop"
* // ]
* ```
* @param text The string or array of strings to align.
* @param options Options for controlling the alignment.
* @returns The aligned string or array of strings, matching the input type.
*/
declare const alignText: (text: string[] | string, options?: AlignTextOptions) => string[] | string;
export { AlignTextOptions, alignText };