Merge pull request #24640 from jewbre/feature/named-regexp-groups

Types for named regexp group
This commit is contained in:
Nathan Shively-Sanders
2018-03-30 13:19:29 -07:00
committed by GitHub
4 changed files with 81 additions and 0 deletions
+38
View File
@@ -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 <https://github.com/jewbre>
// 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;
@@ -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([]);
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }