UNPKG

1.27 kBTypeScriptView Raw
1export type Options = {
2 /**
3 By default the wrap is soft, meaning long words may extend past the column width. Setting this to `true` will make it hard wrap at the column width.
4
5 @default false
6 */
7 readonly hard?: boolean;
8
9 /**
10 By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary.
11
12 @default true
13 */
14 readonly wordWrap?: boolean;
15
16 /**
17 Whitespace on all lines is removed by default. Set this option to `false` if you don't want to trim.
18
19 @default true
20 */
21 readonly trim?: boolean;
22};
23
24/**
25Wrap words to the specified column width.
26
27@param string - A string with ANSI escape codes, like one styled by [`chalk`](https://github.com/chalk/chalk). Newline characters will be normalized to `\n`.
28@param columns - The number of columns to wrap the text to.
29
30@example
31```
32import chalk from 'chalk';
33import wrapAnsi from 'wrap-ansi';
34
35const input = 'The quick brown ' + chalk.red('fox jumped over ') +
36 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
37
38console.log(wrapAnsi(input, 20));
39```
40*/
41export default function wrapAnsi(string: string, columns: number, options?: Options): string;