mailsure 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/LICENSE +21 -0
- package/README.md +261 -2
- package/dist/chunk-Y3744BYV.js +1043 -0
- package/dist/dns.cjs +1018 -0
- package/dist/dns.d.cts +40 -0
- package/dist/dns.d.ts +40 -0
- package/dist/dns.js +73 -0
- package/dist/index.cjs +1065 -0
- package/dist/index.d.cts +92 -0
- package/dist/index.d.ts +92 -0
- package/dist/index.js +28 -0
- package/package.json +80 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Why an address was rejected. */
|
|
2
|
+
type Reason = "empty" | "syntax" | "too-long" | "domain" | "tld" | "disposable" | "role" | "mx";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Damerau-Levenshtein distance (optimal string alignment): insertions,
|
|
6
|
+
* deletions, substitutions and swaps of two neighbouring characters each
|
|
7
|
+
* cost 1. Returns `max + 1` early once the distance must exceed `max`.
|
|
8
|
+
*/
|
|
9
|
+
declare function editDistance(a: string, b: string, max?: number): number;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Popular mailbox domains used for typo suggestions, most popular first.
|
|
13
|
+
* Order matters: on a tie, the earlier domain wins.
|
|
14
|
+
*/
|
|
15
|
+
declare const POPULAR_DOMAINS: readonly string[];
|
|
16
|
+
/** Free mailbox providers (consumer webmail and large ISPs). */
|
|
17
|
+
declare const FREE_DOMAINS: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* Well-known disposable and temporary email domains. Subdomains match too.
|
|
20
|
+
* Only services that exist to hand out throwaway inboxes are listed.
|
|
21
|
+
*/
|
|
22
|
+
declare const DISPOSABLE_DOMAINS: readonly string[];
|
|
23
|
+
/** Local parts that belong to a role or team, not a person. */
|
|
24
|
+
declare const ROLE_LOCAL_PARTS: readonly string[];
|
|
25
|
+
|
|
26
|
+
interface CheckOptions {
|
|
27
|
+
/** Accept disposable addresses (they are still flagged). Default `true`. */
|
|
28
|
+
allowDisposable?: boolean;
|
|
29
|
+
/** Accept role addresses such as admin@ or support@ (still flagged). Default `true`. */
|
|
30
|
+
allowRole?: boolean;
|
|
31
|
+
/** Accept IP address domains such as `user@[192.0.2.1]`. Default `false`. */
|
|
32
|
+
allowIp?: boolean;
|
|
33
|
+
/** Accept Unicode in the local part and domain (`用户@例え.jp`). Default `true`. */
|
|
34
|
+
allowUnicode?: boolean;
|
|
35
|
+
/** Extra domains to suggest when a user mistypes them, such as your company domain. */
|
|
36
|
+
domains?: readonly string[];
|
|
37
|
+
/** Extra disposable domains. Subdomains match too. */
|
|
38
|
+
disposableDomains?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
interface CheckResult {
|
|
41
|
+
/** True when the address passed every check you asked for. */
|
|
42
|
+
valid: boolean;
|
|
43
|
+
/** The address, trimmed, with the domain lowercased. */
|
|
44
|
+
email: string;
|
|
45
|
+
/** The part before the @. */
|
|
46
|
+
local: string;
|
|
47
|
+
/** The part after the @, lowercased. */
|
|
48
|
+
domain: string;
|
|
49
|
+
/** Why the address is invalid. Only set when `valid` is false. */
|
|
50
|
+
reason?: Reason;
|
|
51
|
+
/** The full corrected address when the domain looks like a typo, such as "ana@gmail.com". */
|
|
52
|
+
suggestion?: string;
|
|
53
|
+
/** The domain is a known disposable (throwaway) email service. */
|
|
54
|
+
disposable: boolean;
|
|
55
|
+
/** The local part names a role or team (admin, support, info...) rather than a person. */
|
|
56
|
+
role: boolean;
|
|
57
|
+
/** The domain is a free mailbox provider (gmail.com, outlook.com...). */
|
|
58
|
+
free: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface NormalizeOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Provider-aware canonical form for finding duplicate accounts: lowercases
|
|
63
|
+
* the address, removes +tags (and dots for Gmail), and maps googlemail.com
|
|
64
|
+
* to gmail.com. Use it to compare addresses, not to send mail.
|
|
65
|
+
*/
|
|
66
|
+
canonical?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks an email address: syntax, typo suggestion, disposable, role and free
|
|
70
|
+
* flags. Never throws.
|
|
71
|
+
*/
|
|
72
|
+
declare function check(email: unknown, options?: CheckOptions): CheckResult;
|
|
73
|
+
/** True when `check(email, options).valid` is true. */
|
|
74
|
+
declare function isEmail(email: unknown, options?: CheckOptions): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the corrected address when the domain looks like a typo
|
|
77
|
+
* ("ana@gmial.com" -> "ana@gmail.com"), otherwise undefined.
|
|
78
|
+
*/
|
|
79
|
+
declare function suggest(email: unknown, options?: Pick<CheckOptions, "domains" | "disposableDomains">): string | undefined;
|
|
80
|
+
/** True when the address (or bare domain) belongs to a known disposable email service. */
|
|
81
|
+
declare function isDisposable(emailOrDomain: unknown, options?: Pick<CheckOptions, "disposableDomains">): boolean;
|
|
82
|
+
/** True when the local part names a role or team (admin@, support@, noreply@...). */
|
|
83
|
+
declare function isRole(email: unknown): boolean;
|
|
84
|
+
/** True when the address (or bare domain) belongs to a free mailbox provider. */
|
|
85
|
+
declare function isFree(emailOrDomain: unknown): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Trims the address and lowercases the domain. With `canonical: true`,
|
|
88
|
+
* returns a provider-aware form for spotting duplicate sign-ups. Never throws.
|
|
89
|
+
*/
|
|
90
|
+
declare function normalize(email: unknown, options?: NormalizeOptions): string;
|
|
91
|
+
|
|
92
|
+
export { type CheckOptions, type CheckResult, DISPOSABLE_DOMAINS, FREE_DOMAINS, type NormalizeOptions, POPULAR_DOMAINS, ROLE_LOCAL_PARTS, type Reason, check, editDistance, isDisposable, isEmail, isFree, isRole, normalize, suggest };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Why an address was rejected. */
|
|
2
|
+
type Reason = "empty" | "syntax" | "too-long" | "domain" | "tld" | "disposable" | "role" | "mx";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Damerau-Levenshtein distance (optimal string alignment): insertions,
|
|
6
|
+
* deletions, substitutions and swaps of two neighbouring characters each
|
|
7
|
+
* cost 1. Returns `max + 1` early once the distance must exceed `max`.
|
|
8
|
+
*/
|
|
9
|
+
declare function editDistance(a: string, b: string, max?: number): number;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Popular mailbox domains used for typo suggestions, most popular first.
|
|
13
|
+
* Order matters: on a tie, the earlier domain wins.
|
|
14
|
+
*/
|
|
15
|
+
declare const POPULAR_DOMAINS: readonly string[];
|
|
16
|
+
/** Free mailbox providers (consumer webmail and large ISPs). */
|
|
17
|
+
declare const FREE_DOMAINS: readonly string[];
|
|
18
|
+
/**
|
|
19
|
+
* Well-known disposable and temporary email domains. Subdomains match too.
|
|
20
|
+
* Only services that exist to hand out throwaway inboxes are listed.
|
|
21
|
+
*/
|
|
22
|
+
declare const DISPOSABLE_DOMAINS: readonly string[];
|
|
23
|
+
/** Local parts that belong to a role or team, not a person. */
|
|
24
|
+
declare const ROLE_LOCAL_PARTS: readonly string[];
|
|
25
|
+
|
|
26
|
+
interface CheckOptions {
|
|
27
|
+
/** Accept disposable addresses (they are still flagged). Default `true`. */
|
|
28
|
+
allowDisposable?: boolean;
|
|
29
|
+
/** Accept role addresses such as admin@ or support@ (still flagged). Default `true`. */
|
|
30
|
+
allowRole?: boolean;
|
|
31
|
+
/** Accept IP address domains such as `user@[192.0.2.1]`. Default `false`. */
|
|
32
|
+
allowIp?: boolean;
|
|
33
|
+
/** Accept Unicode in the local part and domain (`用户@例え.jp`). Default `true`. */
|
|
34
|
+
allowUnicode?: boolean;
|
|
35
|
+
/** Extra domains to suggest when a user mistypes them, such as your company domain. */
|
|
36
|
+
domains?: readonly string[];
|
|
37
|
+
/** Extra disposable domains. Subdomains match too. */
|
|
38
|
+
disposableDomains?: readonly string[];
|
|
39
|
+
}
|
|
40
|
+
interface CheckResult {
|
|
41
|
+
/** True when the address passed every check you asked for. */
|
|
42
|
+
valid: boolean;
|
|
43
|
+
/** The address, trimmed, with the domain lowercased. */
|
|
44
|
+
email: string;
|
|
45
|
+
/** The part before the @. */
|
|
46
|
+
local: string;
|
|
47
|
+
/** The part after the @, lowercased. */
|
|
48
|
+
domain: string;
|
|
49
|
+
/** Why the address is invalid. Only set when `valid` is false. */
|
|
50
|
+
reason?: Reason;
|
|
51
|
+
/** The full corrected address when the domain looks like a typo, such as "ana@gmail.com". */
|
|
52
|
+
suggestion?: string;
|
|
53
|
+
/** The domain is a known disposable (throwaway) email service. */
|
|
54
|
+
disposable: boolean;
|
|
55
|
+
/** The local part names a role or team (admin, support, info...) rather than a person. */
|
|
56
|
+
role: boolean;
|
|
57
|
+
/** The domain is a free mailbox provider (gmail.com, outlook.com...). */
|
|
58
|
+
free: boolean;
|
|
59
|
+
}
|
|
60
|
+
interface NormalizeOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Provider-aware canonical form for finding duplicate accounts: lowercases
|
|
63
|
+
* the address, removes +tags (and dots for Gmail), and maps googlemail.com
|
|
64
|
+
* to gmail.com. Use it to compare addresses, not to send mail.
|
|
65
|
+
*/
|
|
66
|
+
canonical?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks an email address: syntax, typo suggestion, disposable, role and free
|
|
70
|
+
* flags. Never throws.
|
|
71
|
+
*/
|
|
72
|
+
declare function check(email: unknown, options?: CheckOptions): CheckResult;
|
|
73
|
+
/** True when `check(email, options).valid` is true. */
|
|
74
|
+
declare function isEmail(email: unknown, options?: CheckOptions): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Returns the corrected address when the domain looks like a typo
|
|
77
|
+
* ("ana@gmial.com" -> "ana@gmail.com"), otherwise undefined.
|
|
78
|
+
*/
|
|
79
|
+
declare function suggest(email: unknown, options?: Pick<CheckOptions, "domains" | "disposableDomains">): string | undefined;
|
|
80
|
+
/** True when the address (or bare domain) belongs to a known disposable email service. */
|
|
81
|
+
declare function isDisposable(emailOrDomain: unknown, options?: Pick<CheckOptions, "disposableDomains">): boolean;
|
|
82
|
+
/** True when the local part names a role or team (admin@, support@, noreply@...). */
|
|
83
|
+
declare function isRole(email: unknown): boolean;
|
|
84
|
+
/** True when the address (or bare domain) belongs to a free mailbox provider. */
|
|
85
|
+
declare function isFree(emailOrDomain: unknown): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Trims the address and lowercases the domain. With `canonical: true`,
|
|
88
|
+
* returns a provider-aware form for spotting duplicate sign-ups. Never throws.
|
|
89
|
+
*/
|
|
90
|
+
declare function normalize(email: unknown, options?: NormalizeOptions): string;
|
|
91
|
+
|
|
92
|
+
export { type CheckOptions, type CheckResult, DISPOSABLE_DOMAINS, FREE_DOMAINS, type NormalizeOptions, POPULAR_DOMAINS, ROLE_LOCAL_PARTS, type Reason, check, editDistance, isDisposable, isEmail, isFree, isRole, normalize, suggest };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DISPOSABLE_DOMAINS,
|
|
3
|
+
FREE_DOMAINS,
|
|
4
|
+
POPULAR_DOMAINS,
|
|
5
|
+
ROLE_LOCAL_PARTS,
|
|
6
|
+
check,
|
|
7
|
+
editDistance,
|
|
8
|
+
isDisposable,
|
|
9
|
+
isEmail,
|
|
10
|
+
isFree,
|
|
11
|
+
isRole,
|
|
12
|
+
normalize,
|
|
13
|
+
suggest
|
|
14
|
+
} from "./chunk-Y3744BYV.js";
|
|
15
|
+
export {
|
|
16
|
+
DISPOSABLE_DOMAINS,
|
|
17
|
+
FREE_DOMAINS,
|
|
18
|
+
POPULAR_DOMAINS,
|
|
19
|
+
ROLE_LOCAL_PARTS,
|
|
20
|
+
check,
|
|
21
|
+
editDistance,
|
|
22
|
+
isDisposable,
|
|
23
|
+
isEmail,
|
|
24
|
+
isFree,
|
|
25
|
+
isRole,
|
|
26
|
+
normalize,
|
|
27
|
+
suggest
|
|
28
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,82 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mailsure",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight, zero-dependency library to check email addresses at signup: syntax, typo suggestions (gmial.com → gmail.com), disposable, role and free addresses, and optional MX checks.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"email",
|
|
7
|
+
"validate",
|
|
8
|
+
"validator",
|
|
9
|
+
"email-validator",
|
|
10
|
+
"email-validation",
|
|
11
|
+
"typo",
|
|
12
|
+
"mailcheck",
|
|
13
|
+
"did-you-mean",
|
|
14
|
+
"disposable",
|
|
15
|
+
"temporary-email",
|
|
16
|
+
"role-account",
|
|
17
|
+
"mx",
|
|
18
|
+
"signup",
|
|
19
|
+
"form",
|
|
20
|
+
"verify",
|
|
21
|
+
"normalize",
|
|
22
|
+
"react",
|
|
23
|
+
"nextjs"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "CK Giri <ckgdev@gmail.com>",
|
|
27
|
+
"homepage": "https://github.com/ckgiri/mailsure",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/ckgiri/mailsure.git"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/ckgiri/mailsure/issues"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"main": "./dist/index.cjs",
|
|
38
|
+
"module": "./dist/index.js",
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"exports": {
|
|
41
|
+
".": {
|
|
42
|
+
"import": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"default": "./dist/index.js"
|
|
45
|
+
},
|
|
46
|
+
"require": {
|
|
47
|
+
"types": "./dist/index.d.cts",
|
|
48
|
+
"default": "./dist/index.cjs"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"./dns": {
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./dist/dns.d.ts",
|
|
54
|
+
"default": "./dist/dns.js"
|
|
55
|
+
},
|
|
56
|
+
"require": {
|
|
57
|
+
"types": "./dist/dns.d.cts",
|
|
58
|
+
"default": "./dist/dns.cjs"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"./package.json": "./package.json"
|
|
62
|
+
},
|
|
63
|
+
"files": [
|
|
64
|
+
"dist",
|
|
65
|
+
"CHANGELOG.md"
|
|
66
|
+
],
|
|
67
|
+
"engines": {
|
|
68
|
+
"node": ">=18"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "tsup",
|
|
72
|
+
"test": "vitest run",
|
|
73
|
+
"typecheck": "tsc -p .",
|
|
74
|
+
"prepublishOnly": "npm run typecheck && npm test && npm run build"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@types/node": "^20.14.0",
|
|
78
|
+
"tsup": "^8.3.0",
|
|
79
|
+
"typescript": "^5.6.0",
|
|
80
|
+
"vitest": "^2.1.0"
|
|
81
|
+
}
|
|
82
|
+
}
|