UNPKG

tty-strings

Version:

Tools for working with strings displayed in the terminal

38 lines 1.5 kB
export interface WordWrapOptions { /** * By default, words that are longer than the specified column width will not be broken and will therefore * extend past the specified column width. Setting this to `true` will enable hard wrapping, in which * words longer than the column width will be broken and wrapped across multiple rows. * @defaultValue `false` */ hard?: boolean; /** * Trim leading whitespace from the beginning of each line. Setting this to `false` will preserve any * leading whitespace found before each line in the input string. * @defaultValue `true` */ trimLeft?: boolean; } /** * Word wrap text to a specified column width. * * @remarks * Input string may contain ANSI escape codes. Style and hyperlink sequences will be wrapped, while all * other types of control sequences will be ignored and will not be included in the output string. * * @example * ```ts * import { wordWrap } from 'tty-strings'; * import chalk from 'chalk'; * * const text = 'The ' + chalk.bgGreen.magenta('quick brown 🦊 jumps over') + ' the 😴 🐶.'; * console.log(wordWrap(text, 20)); * ``` * * @param string - Input text to word wrap. * @param columns - Column width to wrap text to. * @param options - Word wrap options object. * @returns The word wrapped string. */ export default function wordWrap(string: string, columns: number, { hard, trimLeft, }?: WordWrapOptions): string; //# sourceMappingURL=wordWrap.d.ts.map