diff --git a/types/balanced-match/balanced-match-tests.ts b/types/balanced-match/balanced-match-tests.ts index c0edcc89a8..8690fdf27f 100644 --- a/types/balanced-match/balanced-match-tests.ts +++ b/types/balanced-match/balanced-match-tests.ts @@ -1,8 +1,6 @@ -import Balanced = require("balanced-match"); +import balanced = require('balanced-match'); -const balanced = new Balanced(); - -balanced.balanced('{', '}', 'pre{in{nested}}post'); -balanced.balanced('{', '}', 'pre{first}between{second}post'); -balanced.balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'); +balanced('{', '}', 'pre{in{nested}}post'); +balanced('{', '}', 'pre{first}between{second}post'); +balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'); balanced.range('{', '}', 'pre{in{nested}}post'); diff --git a/types/balanced-match/index.d.ts b/types/balanced-match/index.d.ts index 952eba8ffa..d6de0e3e73 100644 --- a/types/balanced-match/index.d.ts +++ b/types/balanced-match/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for balanced-match 1.0 // Project: https://github.com/juliangruber/balanced-match // Definitions by: Adam Zerella +// Piotr Błażejewicz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped interface Output { @@ -26,10 +27,27 @@ interface Output { post: string; } -declare class Balanced { - balanced(a: string|RegExp, b: string|RegExp, str: string): Output|void; +/** + * + * For the first non-nested matching pair of a and b in str, return an object with those keys: + * start the index of the first match of + * `end` the index of the matching b + * `pre` the preamble, a and b not included + * `body` the match, a and b not included + * `post` the postscript, a and b not included + * If there's no match, `undefined` will be returned. + * If the `str` contains more a than b / there are unmatched pairs, + * the first match that was closed will be used. + * For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']` + */ +declare function balanced(a: string | RegExp, b: string | RegExp, str: string): Output | void; - range(a: string|RegExp, b: string|RegExp, str: string): Output|void; +declare namespace balanced { + /** + * For the first non-nested matching pair of `a` and `b` in `str`, + * return an array with indexes: `[ , ]`. + */ + function range(a: string | RegExp, b: string | RegExp, str: string): Output | void; } -export = Balanced; +export = balanced; diff --git a/types/balanced-match/tsconfig.json b/types/balanced-match/tsconfig.json index d91bbdd539..6dd016abd3 100644 --- a/types/balanced-match/tsconfig.json +++ b/types/balanced-match/tsconfig.json @@ -1,25 +1,23 @@ { "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../", - "typeRoots": [ - "../" - ], - "types": [ - - ], - "noEmit": true, - "forceConsistentCasingInFileNames": true + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts", - "balanced-match-tests.ts" + "index.d.ts", + "balanced-match-tests.ts" ] } diff --git a/types/balanced-match/tslint.json b/types/balanced-match/tslint.json index e60c15844f..3db14f85ea 100644 --- a/types/balanced-match/tslint.json +++ b/types/balanced-match/tslint.json @@ -1,3 +1 @@ -{ - "extends": "dtslint/dt.json" -} \ No newline at end of file +{ "extends": "dtslint/dt.json" }