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