1 | // Type definitions for balanced-match 1.0
|
2 | // Project: https://github.com/juliangruber/balanced-match
|
3 | // Definitions by: Adam Zerella <https://github.com/adamzerella>
|
4 | // Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
5 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
6 |
|
7 | interface Output {
|
8 | /**
|
9 | * The index of the first match of a
|
10 | */
|
11 | start: number;
|
12 | /**
|
13 | * The index of the matching b
|
14 | */
|
15 | end: number;
|
16 | /**
|
17 | * The preamble, a and b not included
|
18 | */
|
19 | pre: string;
|
20 | /**
|
21 | * The match, a and b not included
|
22 | */
|
23 | body: string;
|
24 | /**
|
25 | * The postscript, a and b not included
|
26 | */
|
27 | post: string;
|
28 | }
|
29 |
|
30 | /**
|
31 | *
|
32 | * For the first non-nested matching pair of a and b in str, return an object with those keys:
|
33 | * start the index of the first match of
|
34 | * `end` the index of the matching b
|
35 | * `pre` the preamble, a and b not included
|
36 | * `body` the match, a and b not included
|
37 | * `post` the postscript, a and b not included
|
38 | * If there's no match, `undefined` will be returned.
|
39 | * If the `str` contains more a than b / there are unmatched pairs,
|
40 | * the first match that was closed will be used.
|
41 | * For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`
|
42 | */
|
43 | declare function balanced(a: string | RegExp, b: string | RegExp, str: string): Output | void;
|
44 |
|
45 | declare namespace balanced {
|
46 | /**
|
47 | * For the first non-nested matching pair of `a` and `b` in `str`,
|
48 | * return an array with indexes: `[ <a index>, <b index> ]`.
|
49 | */
|
50 | function range(a: string | RegExp, b: string | RegExp, str: string): Output | void;
|
51 | }
|
52 |
|
53 | export = balanced;
|