UNPKG

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