Mailcheck: Add support for Synchronous mode (#43144)

* Add support for Synchronous mode

* Update header

* Remove patch from header
This commit is contained in:
Jeffrey Meng 2020-03-17 07:49:01 -07:00 committed by GitHub
parent 80fef04542
commit 2f2b97cd5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 7 deletions

View File

@ -2,7 +2,7 @@
// Project: https://github.com/mailcheck/mailcheck
// Definitions by: Paulo Cesar <https://github.com/pocesar>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// TypeScript Version: 3.8
/// <reference types="jquery" />
@ -46,23 +46,31 @@ declare namespace MailcheckModule {
full: string;
}
export interface IOptions {
export interface IAsynchronousOptions {
email: string;
domains?: string[];
secondLevelDomains?: string[];
topLevelDomains?: string[];
distanceFunction?: IDistanceFunction;
suggested?: ISuggested | IJQuerySuggested;
suggested: ISuggested | IJQuerySuggested;
empty?: IEmpty | IJQueryEmpty;
}
export interface ISynchronousOptions {
email: string;
domains?: string[];
secondLevelDomains?: string[];
topLevelDomains?: string[];
distanceFunction?: IDistanceFunction;
}
export interface Static {
defaultDomains: string[];
defaultSecondLevelDomains: string[];
defaultTopLevelDomains: string[];
domainThreshold: number;
topLevelThreshold: number;
run(opts: IOptions):void;
run(opts: IAsynchronousOptions):void;
run(opts: ISynchronousOptions):ISuggestion | undefined;
suggest: ISuggestFunction;
encodeEmail(email: string): string;
splitEmail(email: string): ISplitEmail;
@ -73,7 +81,8 @@ declare namespace MailcheckModule {
}
interface JQuery {
mailcheck(opts: MailcheckModule.IOptions): void;
mailcheck(opts: MailcheckModule.IAsynchronousOptions):void;
mailcheck(opts: MailcheckModule.ISynchronousOptions):MailcheckModule.ISuggestion | void;
}
declare module 'mailcheck' {

View File

@ -18,6 +18,8 @@ $('#email').on('blur', function() {
distanceFunction: superStringDistance, // optional
suggested: function(element: JQuery, suggestion: MailcheckModule.ISuggestion) {
// callback code
element; // $ExpectType JQuery<HTMLElement>
suggestion; // $ExpectType ISuggestion
},
empty: function(element: JQuery) {
// callback code
@ -33,6 +35,7 @@ Mailcheck.run({
distanceFunction: superStringDistance, // optional
suggested: function(suggestion: MailcheckModule.ISuggestion) {
// callback code
suggestion; // $ExpectType ISuggestion
},
empty: function() {
// callback code
@ -47,9 +50,18 @@ MC.run({
distanceFunction: superStringDistance, // optional
suggested: function(suggested: MailcheckModule.ISuggestion) {
// callback code
suggested.address === '' && suggested.full === '' && suggested.domain === '';
suggested; // $ExpectType ISuggestion
},
empty: function() {
// callback code
}
});
});
const result3 = MC.run({
email: 'nonoptional@example.com',
domains: domains, // optional
secondLevelDomains: secondLevelDomains, // optional
topLevelDomains: topLevelDomains, // optional
distanceFunction: superStringDistance, // optional
});
result3; // $ExpectType ISuggestion | undefined