@yarigai/iana-tlds 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/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/index.cjs +1471 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +1466 -0
- package/dist/index.js.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yarigai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @yarigai/iana-tlds
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@yarigai/iana-tlds)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://gitlab.com/yarigai/packages/iana-tlds/-/pipelines)
|
|
6
|
+
[](https://data.iana.org/TLD/tlds-alpha-by-domain.txt)
|
|
7
|
+
|
|
8
|
+
Always up-to-date IANA TLD list for domain validation in production systems.
|
|
9
|
+
|
|
10
|
+
Data is sourced directly from the [IANA root zone database](https://data.iana.org/TLD/tlds-alpha-by-domain.txt) and bundled at publish time. Zero runtime dependencies — all validation calls are synchronous.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @yarigai/iana-tlds
|
|
16
|
+
# or
|
|
17
|
+
yarn add @yarigai/iana-tlds
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @yarigai/iana-tlds
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Validate an email's TLD
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { validateEmail, isValidEmail } from "@yarigai/iana-tlds";
|
|
28
|
+
|
|
29
|
+
// Detailed result — discriminate on `valid`
|
|
30
|
+
const result = validateEmail("user@example.com");
|
|
31
|
+
if (result.valid) {
|
|
32
|
+
console.log(result.tld); // "com"
|
|
33
|
+
} else {
|
|
34
|
+
console.log(result.reason); // "invalid_format" | "unknown_tld"
|
|
35
|
+
console.log(result.tld); // string if parsed, null if format was invalid
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Boolean shorthand
|
|
39
|
+
console.log(isValidEmail("user@example.com")); // true
|
|
40
|
+
console.log(isValidEmail("user@example.xyzzy")); // false
|
|
41
|
+
console.log(isValidEmail("not-an-email")); // false
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Work with the raw TLD list
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { tldsList, lastUpdated } from "@yarigai/iana-tlds";
|
|
48
|
+
|
|
49
|
+
// tldsList → string[] of lowercase TLDs, e.g. ["aaa", "aarp", ..., "zw"]
|
|
50
|
+
// lastUpdated → ISO 8601 timestamp of the IANA source file bundled in this release
|
|
51
|
+
|
|
52
|
+
console.log(tldsList.includes("com")); // true
|
|
53
|
+
console.log(lastUpdated); // "2026-05-19T07:07:02.000Z"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Named imports
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { tldsList, lastUpdated, validateEmail, isValidEmail } from "@yarigai/iana-tlds";
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## API Reference
|
|
63
|
+
|
|
64
|
+
### `validateEmail(email: string): EmailValidation`
|
|
65
|
+
|
|
66
|
+
Validates whether an email address has a valid IANA-registered TLD. Only the
|
|
67
|
+
TLD portion of the domain is checked — local-part syntax and DNS resolution
|
|
68
|
+
are outside the scope of this function.
|
|
69
|
+
|
|
70
|
+
Returns an `EmailValidation` discriminated union:
|
|
71
|
+
|
|
72
|
+
| Shape | When |
|
|
73
|
+
| ---------------------------------------------------------------------- | ------------------------------- |
|
|
74
|
+
| `{ valid: true; email: string; tld: string }` | TLD is recognised by IANA |
|
|
75
|
+
| `{ valid: false; email: string; tld: string; reason: "unknown_tld" }` | TLD parsed but not in IANA list |
|
|
76
|
+
| `{ valid: false; email: string; tld: null; reason: "invalid_format" }` | No TLD could be extracted |
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
validateEmail("user@example.com");
|
|
80
|
+
// { valid: true, email: "user@example.com", tld: "com" }
|
|
81
|
+
|
|
82
|
+
validateEmail("user@example.xyzzy");
|
|
83
|
+
// { valid: false, email: "user@example.xyzzy", tld: "xyzzy", reason: "unknown_tld" }
|
|
84
|
+
|
|
85
|
+
validateEmail("not-an-email");
|
|
86
|
+
// { valid: false, email: "not-an-email", tld: null, reason: "invalid_format" }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `isValidEmail(email: string): boolean`
|
|
90
|
+
|
|
91
|
+
Convenience wrapper around `validateEmail` that returns `true` when the
|
|
92
|
+
email has a valid IANA TLD, `false` otherwise.
|
|
93
|
+
|
|
94
|
+
### Types
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
type EmailValidationReason = "invalid_format" | "unknown_tld";
|
|
98
|
+
|
|
99
|
+
type EmailValidation =
|
|
100
|
+
| { valid: true; email: string; tld: string }
|
|
101
|
+
| { valid: false; email: string; tld: string | null; reason: EmailValidationReason };
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Data exports
|
|
105
|
+
|
|
106
|
+
| Export | Type | Description |
|
|
107
|
+
| ------------- | ---------- | --------------------------------------- |
|
|
108
|
+
| `tldsList` | `string[]` | Array of all valid TLDs in lowercase |
|
|
109
|
+
| `lastUpdated` | `string` | ISO 8601 timestamp from the IANA source |
|
|
110
|
+
|
|
111
|
+
## Data source & sync
|
|
112
|
+
|
|
113
|
+
The TLD list is sourced directly from IANA's root zone database:
|
|
114
|
+
`https://data.iana.org/TLD/tlds-alpha-by-domain.txt`
|
|
115
|
+
|
|
116
|
+
A scheduled CI/CD pipeline runs daily. If IANA publishes an updated list, the
|
|
117
|
+
pipeline automatically:
|
|
118
|
+
|
|
119
|
+
1. Fetches the new list and compares it against the bundled version.
|
|
120
|
+
2. Rebuilds and tests the package.
|
|
121
|
+
3. Bumps the patch version, commits, tags, and pushes back to the repository.
|
|
122
|
+
4. Publishes the new release to npm.
|
|
123
|
+
|
|
124
|
+
To sync locally:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
pnpm run update-tlds
|
|
128
|
+
pnpm run build
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
Bug reports and pull requests are welcome at
|
|
134
|
+
[gitlab.com/yarigai/packages/iana-tlds](https://gitlab.com/yarigai/packages/iana-tlds).
|
|
135
|
+
|
|
136
|
+
Please open an issue first for non-trivial changes.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
|
|
140
|
+
MIT — see [LICENSE](LICENSE).
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
Maintained by [Yarigai](https://yarigai.com) — Enterprise Technology Architecture & Strategic IT Consulting.
|