UNPKG

1.5 kBTypeScriptView Raw
1type Wrap = (text: string) => string;
2
3/**
4 * Wrap lines until column `stop`. If a word is longer than `stop` characters
5 * it will overflow.
6 */
7declare function wordwrap(stop: number, params?: { mode?: wordwrap.Mode | undefined }): Wrap;
8
9/**
10 * Pad out lines with spaces out to column `start` and then wrap until column
11 * `stop`. If a word is longer than `stop - start` characters it will overflow.
12 */
13declare function wordwrap(start: number, stop: number, params?: { mode?: wordwrap.Mode | undefined }): Wrap;
14
15/**
16 * Pad out lines with spaces out to column `start` and then wrap until column
17 * `stop`. If a word is longer than `stop - start` characters it will overflow.
18 */
19declare function wordwrap(params: wordwrap.Options): Wrap;
20
21declare namespace wordwrap {
22 interface Options {
23 stop: number;
24 start: number;
25 mode?: Mode | undefined;
26 }
27
28 /**
29 * Wrap lines until column `stop`. Break up chunks longer than `stop`.
30 */
31 function hard(stop: number): Wrap;
32
33 /**
34 * Wrap lines until column `stop`. Break up chunks longer than `stop - start`.
35 */
36 function hard(start: number, stop: number): Wrap; // tslint:disable-line:unified-signatures
37
38 /**
39 * In "soft" mode, split chunks by `/(\S+\s+/` and don't break up chunks
40 * which are longer than `stop - start`, in "hard" mode, split chunks with
41 * `/\b/` and break up chunks longer than `stop - start`.
42 */
43 type Mode = "soft" | "hard";
44}
45
46export = wordwrap;