diff --git a/types/named-regexp-groups/index.d.ts b/types/named-regexp-groups/index.d.ts new file mode 100644 index 0000000000..19426c352e --- /dev/null +++ b/types/named-regexp-groups/index.d.ts @@ -0,0 +1,38 @@ +// Type definitions for named-regexp-groups 1.0 +// Project: https://github.com/commenthol/named-regexp-groups/ +// Definitions by: Vilim Stubičan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +interface NamedRegExpExecArray extends RegExpExecArray { + groups: { [propName: string]: string }; +} + +declare class NamedRegExp { + constructor(pattern?: string | RegExp, flags?: string); + + /** + * Executes a search on a string using a regular expression pattern, and returns an array containing the results of that search. + * @param string The String object or string literal on which to perform the search. + */ + exec(string: string): NamedRegExpExecArray | null; + + /** + * Returns a Boolean value that indicates whether or not a pattern exists in a searched string. + * @param string String on which to perform the search. + */ + test(string: string): boolean; + + // Non-standard extensions + toString(): string; + + [Symbol.replace](str: string, replacement: string | ((match: string, ...capturedGroups: string[]) => string)): string; + + [Symbol.match](str: string): NamedRegExpExecArray; + + [Symbol.split](str: string): string[]; + + [Symbol.search](str: string): number; +} + +export = NamedRegExp; diff --git a/types/named-regexp-groups/named-regexp-groups-tests.ts b/types/named-regexp-groups/named-regexp-groups-tests.ts new file mode 100644 index 0000000000..cff4cc057e --- /dev/null +++ b/types/named-regexp-groups/named-regexp-groups-tests.ts @@ -0,0 +1,19 @@ +import NamedRegExp = require("named-regexp-groups"); + +// $ExpectType NamedRegExp +new NamedRegExp('aaa', 'gi'); + +// $ExpectType NamedRegExp +new NamedRegExp(/aaa/gi); + +// $ExpectType NamedRegExp +new NamedRegExp(); + +// $ExpectError +new NamedRegExp(1); + +// $ExpectError +new NamedRegExp({}); + +// $ExpectError +new NamedRegExp([]); diff --git a/types/named-regexp-groups/tsconfig.json b/types/named-regexp-groups/tsconfig.json new file mode 100644 index 0000000000..9ce09a5d74 --- /dev/null +++ b/types/named-regexp-groups/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "named-regexp-groups-tests.ts" + ] +} diff --git a/types/named-regexp-groups/tslint.json b/types/named-regexp-groups/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/named-regexp-groups/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }