UNPKG

1.32 kBTypeScriptView Raw
1export interface Output {
2 /**
3 * The index of the first match of a
4 */
5 start: number;
6 /**
7 * The index of the matching b
8 */
9 end: number;
10 /**
11 * The preamble, a and b not included
12 */
13 pre: string;
14 /**
15 * The match, a and b not included
16 */
17 body: string;
18 /**
19 * The postscript, a and b not included
20 */
21 post: string;
22}
23
24/**
25 * For the first non-nested matching pair of a and b in str, return an object with those keys:
26 * start the index of the first match of
27 * `end` the index of the matching b
28 * `pre` the preamble, a and b not included
29 * `body` the match, a and b not included
30 * `post` the postscript, a and b not included
31 * If there's no match, `undefined` will be returned.
32 * If the `str` contains more a than b / there are unmatched pairs,
33 * the first match that was closed will be used.
34 * For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`
35 */
36export default function balanced(a: string | RegExp, b: string | RegExp, str: string): Output | undefined;
37
38/**
39 * For the first non-nested matching pair of `a` and `b` in `str`,
40 * return an array with indexes: `[ <a index>, <b index> ]`.
41 */
42export function range(a: string | RegExp, b: string | RegExp, str: string): [number, number] | undefined;