-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add TS type declaration and pkg.json types entry (#164)
- Loading branch information
1 parent
4de1bcc
commit e6450a5
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters