From 2ef1fc0465324d8ef1eefe70e0b265da47b63b61 Mon Sep 17 00:00:00 2001 From: Jamie Kyle Date: Sat, 29 Jun 2019 11:38:26 -0700 Subject: [PATCH] Add TypeScript definition (#8) --- index.d.ts | 16 ++++++++++++++++ index.test-d.ts | 8 ++++++++ package.json | 11 +++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 index.d.ts create mode 100644 index.test-d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..985e809 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,16 @@ +export interface Options { + /** + * Only match an exact string. + * + * @default false + */ + exact?: boolean +} + +/** + * Returns a regex for matching email addresses. + * + * @param options - Configure the generated regular expression + * @returns Regex for matching email addresses. + */ +export default function emailRegex(options?: Options): RegExp; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..99e36b0 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,8 @@ +import {expectType} from 'tsd-check'; +import emailRegex from '.'; + +(async () => { + expectType(emailRegex()); + expectType(emailRegex({})); + expectType(emailRegex({ exact: true })); +})(); diff --git a/package.json b/package.json index aac6571..bc9d97c 100644 --- a/package.json +++ b/package.json @@ -13,10 +13,11 @@ "node": ">=6" }, "scripts": { - "test": "xo && ava" + "test": "xo && ava && tsd-check" }, "files": [ - "index.js" + "index.js", + "index.d.ts" ], "keywords": [ "text", @@ -34,6 +35,12 @@ ], "devDependencies": { "ava": "*", + "tsd-check": "^0.3.0", "xo": "*" + }, + "xo": { + "ignores": [ + "*.ts" + ] } }