From cace6bbe760585213f4a44451b0599a0403de523 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:46:56 +0000 Subject: [PATCH 1/2] feat: add TS type declarations --- package.json | 1 + typings/index.d.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 typings/index.d.ts diff --git a/package.json b/package.json index 8f39be4..2982d2d 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.1.2", "description": "detect possibly catastrophic, exponential-time regular expressions", "main": "dist/index.js", + "types": "typings/index.d.ts", "dependencies": { "babel-jest": "^26.3.0", "regexp-tree": "~0.1.1" diff --git a/typings/index.d.ts b/typings/index.d.ts new file mode 100644 index 0000000..2e03384 --- /dev/null +++ b/typings/index.d.ts @@ -0,0 +1,12 @@ +/** + * Checks if a regex is safe to use in order to prevent catastrophic backtracking. + * @param regex can be a RegExp object or just a string. + * @param options Options for the check. + * `limit` - maximum number of allowed repetitions in the entire regex. Default: `25`. + */ +export default function safe(regex: string | RegExp, options?: Options): boolean; + +export type Options = Partial<{ + /** Maximum number of allowed repetitions in the entire regex. Default `25` */ + limit: number +}> \ No newline at end of file From de9d7fb3bd97905f55670a3b797820bbfb7ecb80 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:52:14 +0000 Subject: [PATCH 2/2] types: update function name to match code --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 2e03384..4fce967 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4,7 +4,7 @@ * @param options Options for the check. * `limit` - maximum number of allowed repetitions in the entire regex. Default: `25`. */ -export default function safe(regex: string | RegExp, options?: Options): boolean; +export default function safeRegex(regex: string | RegExp, options?: Options): boolean; export type Options = Partial<{ /** Maximum number of allowed repetitions in the entire regex. Default `25` */