@lacspace/email-validate 1.0.0 → 1.0.1
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/README.md +97 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# @lacspace/email-validate
|
|
4
|
+
|
|
5
|
+
**Email validation that goes beyond a regex — disposable detection, typo suggestions, normalization.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@lacspace/email-validate)
|
|
8
|
+
[](https://packagephobia.com/result?p=@lacspace/email-validate)
|
|
9
|
+
[](https://bundlephobia.com/package/@lacspace/email-validate)
|
|
10
|
+
[](https://www.npmjs.com/package/@lacspace/email-validate)
|
|
11
|
+
[](https://github.com/lacspace/npm-packages/blob/main/LICENSE)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
> A regex tells you an address is *shaped* right. This tells you it's a **mailinator throwaway**, that `gmial.com` should be `gmail.com`, that `info@` is a role mailbox, and gives you a normalized canonical form for de-duping users.
|
|
16
|
+
|
|
17
|
+
- ✅ Robust syntax + length checks (RFC-5321-ish)
|
|
18
|
+
- 🗑️ **Disposable / temp-mail** detection
|
|
19
|
+
- 💡 **"Did you mean?"** typo suggestions (`gmial.com` → `gmail.com`)
|
|
20
|
+
- 👥 Role-address (`info@`, `admin@`) & free-provider flags
|
|
21
|
+
- 🔤 `normalizeEmail` — Gmail dots/`+tags` stripped, lowercased (great for de-dupe)
|
|
22
|
+
- ⚡ Zero dependencies · 🌍 isomorphic · 📦 ESM + CJS · fully typed
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install @lacspace/email-validate # or pnpm add / yarn add / bun add
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## One call, everything you need
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { validateEmail } from "@lacspace/email-validate";
|
|
34
|
+
|
|
35
|
+
validateEmail("john.doe+news@gmial.com");
|
|
36
|
+
// {
|
|
37
|
+
// valid: true,
|
|
38
|
+
// normalized: "john.doe@gmial.com",
|
|
39
|
+
// local: "john.doe+news",
|
|
40
|
+
// domain: "gmial.com",
|
|
41
|
+
// disposable: false,
|
|
42
|
+
// role: false,
|
|
43
|
+
// free: false,
|
|
44
|
+
// suggestion: "john.doe+news@gmail.com" // ← typo caught
|
|
45
|
+
// }
|
|
46
|
+
|
|
47
|
+
validateEmail("test@mailinator.com").disposable; // true
|
|
48
|
+
validateEmail("info@lacspace.com").role; // true
|
|
49
|
+
validateEmail("nope@@bad").valid; // false
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Individual helpers
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import {
|
|
56
|
+
isValidEmail, normalizeEmail, isDisposable, isRoleAddress, isFreeProvider, suggestEmail,
|
|
57
|
+
} from "@lacspace/email-validate";
|
|
58
|
+
|
|
59
|
+
isValidEmail("a@b.co"); // true
|
|
60
|
+
normalizeEmail("John.Doe+promo@GMAIL.com"); // "johndoe@gmail.com"
|
|
61
|
+
isDisposable("guerrillamail.com"); // true
|
|
62
|
+
isRoleAddress("support"); // true
|
|
63
|
+
isFreeProvider("yahoo.com"); // true
|
|
64
|
+
suggestEmail("me@yahho.com"); // "me@yahoo.com"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Real-world: clean a signup form
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const r = validateEmail(input);
|
|
71
|
+
if (!r.valid) return fail("Please enter a valid email.");
|
|
72
|
+
if (r.suggestion) return confirm(`Did you mean ${r.suggestion}?`);
|
|
73
|
+
if (r.disposable) return fail("Please use a permanent email address.");
|
|
74
|
+
await createUser({ email: r.normalized }); // store the canonical form
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Customize
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
validateEmail(input, {
|
|
81
|
+
extraDisposable: ["mycompany-temp.com"], // add your own throwaway domains
|
|
82
|
+
suggestions: false, // turn off typo suggestions
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
You can also read/extend the exported sets: `DISPOSABLE_DOMAINS`, `FREE_PROVIDERS`, `ROLE_LOCALS`.
|
|
87
|
+
|
|
88
|
+
## The Lacspace MailKit
|
|
89
|
+
|
|
90
|
+
| Package | For |
|
|
91
|
+
| --- | --- |
|
|
92
|
+
| [`@lacspace/mailer`](https://www.npmjs.com/package/@lacspace/mailer) | Send email over SMTP |
|
|
93
|
+
| [`@lacspace/email-templates`](https://www.npmjs.com/package/@lacspace/email-templates) | Build responsive HTML emails |
|
|
94
|
+
| **`@lacspace/email-validate`** | Validate & normalize addresses (this package) |
|
|
95
|
+
| [`@lacspace/email-verify`](https://www.npmjs.com/package/@lacspace/email-verify) | MX + SMTP deliverability checks |
|
|
96
|
+
|
|
97
|
+
<div align="center"><sub>Built with care by <a href="https://lacspace.com">Lacspace</a> · MIT licensed · <a href="https://github.com/lacspace/npm-packages">source</a></sub></div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lacspace/email-validate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Smart email validation — syntax, disposable/temp-mail detection, role & free-provider flags, Gmail normalization and 'did you mean?' typo suggestions. Zero-dependency, isomorphic.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|