UNPKG

2.27 kBMarkdownView Raw
1# Installation
2> `npm install --save @types/balanced-match`
3
4# Summary
5This package contains type definitions for balanced-match (https://github.com/juliangruber/balanced-match).
6
7# Details
8Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/balanced-match.
9## [index.d.ts](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/balanced-match/index.d.ts)
10````ts
11// Type definitions for balanced-match 1.0
12// Project: https://github.com/juliangruber/balanced-match
13// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
14// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
15
16interface Output {
17 /**
18 * The index of the first match of a
19 */
20 start: number;
21 /**
22 * The index of the matching b
23 */
24 end: number;
25 /**
26 * The preamble, a and b not included
27 */
28 pre: string;
29 /**
30 * The match, a and b not included
31 */
32 body: string;
33 /**
34 * The postscript, a and b not included
35 */
36 post: string;
37}
38
39/**
40 *
41 * For the first non-nested matching pair of a and b in str, return an object with those keys:
42 * start the index of the first match of
43 * `end` the index of the matching b
44 * `pre` the preamble, a and b not included
45 * `body` the match, a and b not included
46 * `post` the postscript, a and b not included
47 * If there's no match, `undefined` will be returned.
48 * If the `str` contains more a than b / there are unmatched pairs,
49 * the first match that was closed will be used.
50 * For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`
51 */
52declare function balanced(a: string | RegExp, b: string | RegExp, str: string): Output | void;
53
54declare namespace balanced {
55 /**
56 * For the first non-nested matching pair of `a` and `b` in `str`,
57 * return an array with indexes: `[ <a index>, <b index> ]`.
58 */
59 function range(a: string | RegExp, b: string | RegExp, str: string): Output | void;
60}
61
62export = balanced;
63
64````
65
66### Additional Details
67 * Last updated: Thu, 23 Dec 2021 23:34:18 GMT
68 * Dependencies: none
69 * Global values: none
70
71# Credits
72These definitions were written by [Piotr Błażejewicz](https://github.com/peterblazejewicz).
73
\No newline at end of file