From d8e0586da4304684c07043ffc5fab69812fb2a45 Mon Sep 17 00:00:00 2001 From: Adam Zerella Date: Mon, 29 Apr 2019 16:55:41 +1000 Subject: [PATCH] Added type defs for balanced-match (#35051) --- types/balanced-match/balanced-match-tests.ts | 8 +++++ types/balanced-match/index.d.ts | 35 ++++++++++++++++++++ types/balanced-match/tsconfig.json | 25 ++++++++++++++ types/balanced-match/tslint.json | 3 ++ 4 files changed, 71 insertions(+) create mode 100644 types/balanced-match/balanced-match-tests.ts create mode 100644 types/balanced-match/index.d.ts create mode 100644 types/balanced-match/tsconfig.json create mode 100644 types/balanced-match/tslint.json diff --git a/types/balanced-match/balanced-match-tests.ts b/types/balanced-match/balanced-match-tests.ts new file mode 100644 index 0000000000..c0edcc89a8 --- /dev/null +++ b/types/balanced-match/balanced-match-tests.ts @@ -0,0 +1,8 @@ +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.range('{', '}', 'pre{in{nested}}post'); diff --git a/types/balanced-match/index.d.ts b/types/balanced-match/index.d.ts new file mode 100644 index 0000000000..952eba8ffa --- /dev/null +++ b/types/balanced-match/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for balanced-match 1.0 +// Project: https://github.com/juliangruber/balanced-match +// Definitions by: Adam Zerella +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +interface Output { + /** + * The index of the first match of a + */ + start: number; + /** + * The index of the matching b + */ + end: number; + /** + * The preamble, a and b not included + */ + pre: string; + /** + * The match, a and b not included + */ + body: string; + /** + * The postscript, a and b not included + */ + post: string; +} + +declare class Balanced { + balanced(a: string|RegExp, b: string|RegExp, str: string): Output|void; + + range(a: string|RegExp, b: string|RegExp, str: string): Output|void; +} + +export = Balanced; diff --git a/types/balanced-match/tsconfig.json b/types/balanced-match/tsconfig.json new file mode 100644 index 0000000000..d91bbdd539 --- /dev/null +++ b/types/balanced-match/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [ + + ], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "balanced-match-tests.ts" + ] +} diff --git a/types/balanced-match/tslint.json b/types/balanced-match/tslint.json new file mode 100644 index 0000000000..e60c15844f --- /dev/null +++ b/types/balanced-match/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} \ No newline at end of file