Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add TS type declaration and pkg.json types entry #164

Merged
merged 2 commits into from
Feb 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Code shows a string is valid,
// but docs require string array or object.
type TLDList = string | string[] | { [topLevelDomain: string]: any };

type BaseOptions = {
tldWhitelist?: TLDList;
tldBlacklist?: TLDList;
minDomainAtoms?: number;
allowUnicode?: boolean;
};

type OptionsWithBool = BaseOptions & {
errorLevel?: false;
};

type OptionsWithNumThreshold = BaseOptions & {
errorLevel?: true | number;
};

interface Validator {
/**
* Check that an email address conforms to RFCs 5321, 5322, 6530 and others.
*
* The callback function will always be called
* with the result of the operation.
*
* ```
* import * as IsEmail from "isemail";
*
* const log = result => console.log(`Result: ${result}`);
* IsEmail.validate("test@e.com");
* // => true
* ```
*/
validate(email: string): boolean;

/**
* Check that an email address conforms to RFCs 5321, 5322, 6530 and others.
*
* The callback function will always be called
* with the result of the operation.
*
* ```
* import * as IsEmail from "isemail";
*
* IsEmail.validate("test@iana.org", { errorLevel: false });
* // => true
* ```
*/
validate(email: string, options: OptionsWithBool): boolean;

/**
* Check that an email address conforms to RFCs 5321, 5322, 6530 and others.
*
* The callback function will always be called
* with the result of the operation.
*
* ```
* import * as IsEmail from "isemail";
*
* IsEmail.validate("test@iana.org", { errorLevel: true });
* // => 0
* IsEmail.validate("test @e.com", { errorLevel: 50 });
* // => 0
* IsEmail.validate('test @e.com', { errorLevel: true })
* // => 49
* ```
*/
validate(email: string, options: OptionsWithNumThreshold): number;
}

declare const IsEmail: Validator;

export = IsEmail;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "3.1.0",
"repository": "git://github.com/hapijs/isemail",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"keywords": [
"isemail",
"validation",
Expand Down