global-tld-list 1.28.16 → 1.28.18
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 +154 -5
- package/dist/cjs/data.js +2093 -0
- package/dist/cjs/details-data.js +2671 -0
- package/dist/cjs/details.js +79 -0
- package/dist/cjs/index.js +176 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/punycode.js +64 -0
- package/dist/esm/data.js +2090 -0
- package/dist/esm/details-data.js +2668 -0
- package/dist/esm/details.js +72 -0
- package/dist/esm/index.js +164 -0
- package/dist/esm/punycode.js +61 -0
- package/dist/types/data.d.ts +168 -0
- package/dist/types/details-data.d.ts +147 -0
- package/dist/types/details.d.ts +46 -0
- package/dist/types/index.d.ts +87 -0
- package/dist/types/punycode.d.ts +9 -0
- package/package.json +73 -39
- package/data/serialized.json +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -14
- package/dist/list.d.ts +0 -6
- package/dist/list.js +0 -55
package/README.md
CHANGED
|
@@ -1,20 +1,169 @@
|
|
|
1
1
|
# Global TLD List
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Every top-level domain in the [IANA root zone](https://www.iana.org/domains/root/db), regenerated daily and published only when the list changes. Validate TLDs and domain names, find the TLD of a hostname, spot special-use names like `.local`, tell country codes from generic and brand TLDs, convert IDN TLDs between Unicode and punycode, and look up registry operators, RDAP servers and removed TLDs.
|
|
4
|
+
|
|
5
|
+
- All ~1,440 TLDs, including internationalized ones (`.рф`, `.भारत`, `.中国`)
|
|
6
|
+
- Forgiving input: any case, a leading dot, Unicode or punycode
|
|
7
|
+
- A `Tld` union type of every TLD for TypeScript, and a `KnownTld` type that never shrinks
|
|
8
|
+
- Zero dependencies, ESM and CommonJS, no Node-specific APIs at runtime
|
|
9
|
+
|
|
10
|
+
Data comes from IANA's [TLD list](https://data.iana.org/TLD/tlds-alpha-by-domain.txt), [RDAP bootstrap file](https://data.iana.org/rdap/dns.json) and [special-use domain names registry](https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml), and ICANN's [gTLD registry](https://www.icann.org/resources/registries/gtlds/v2/gtlds.json).
|
|
4
11
|
|
|
5
12
|
## Installation
|
|
6
13
|
|
|
7
14
|
```sh
|
|
8
|
-
npm install global-tld-list
|
|
15
|
+
npm install global-tld-list
|
|
9
16
|
```
|
|
10
17
|
|
|
11
18
|
## Usage
|
|
12
19
|
|
|
20
|
+
```js
|
|
21
|
+
import { isTld, normalizeTld, getTld, getTldInfo, isCountryCode, listTlds } from 'global-tld-list';
|
|
22
|
+
|
|
23
|
+
isTld('com'); // true
|
|
24
|
+
isTld('.COM'); // true
|
|
25
|
+
isTld('xn--p1ai'); // true (.рф)
|
|
26
|
+
isTld('local'); // false
|
|
27
|
+
|
|
28
|
+
normalizeTld('.COM'); // 'com'
|
|
29
|
+
normalizeTld('xn--p1ai'); // 'рф'
|
|
30
|
+
|
|
31
|
+
getTld('www.Example.co.uk'); // 'uk'
|
|
32
|
+
getTld('shop.xn--p1ai'); // 'рф'
|
|
33
|
+
getTld('printer.local'); // undefined
|
|
34
|
+
|
|
35
|
+
isCountryCode('io'); // true
|
|
36
|
+
isCountryCode('рф'); // true
|
|
37
|
+
isCountryCode('com'); // false
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`getTld` returns the last label only. For the registrable suffix (`co.uk`, `github.io`) use a Public Suffix List library such as [tldts](https://www.npmjs.com/package/tldts).
|
|
41
|
+
|
|
42
|
+
### Domain names
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import { isValidDomain, isSpecialUse } from 'global-tld-list';
|
|
46
|
+
|
|
47
|
+
isValidDomain('example.com'); // true
|
|
48
|
+
isValidDomain('münchen.de'); // true (checked as xn--mnchen-3ya.de)
|
|
49
|
+
isValidDomain('example.com.'); // true (trailing root dot)
|
|
50
|
+
isValidDomain('example.local'); // false: .local is not a TLD
|
|
51
|
+
isValidDomain('exa_mple.com'); // false: _ is not allowed in a hostname
|
|
52
|
+
isValidDomain('example.com:443'); // false: ports, paths, IP addresses and spaces are rejected
|
|
53
|
+
|
|
54
|
+
isSpecialUse('printer.local'); // true (mDNS)
|
|
55
|
+
isSpecialUse('db.internal'); // true (reserved by ICANN for private networks)
|
|
56
|
+
isSpecialUse('www.example.com'); // true (reserved for documentation)
|
|
57
|
+
isSpecialUse('example.net.au'); // false
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`isValidDomain` checks the name: at least two labels, each 1-63 letters, digits or hyphens with no hyphen at either end, at most 253 characters in ASCII form, under a TLD in the root zone. It does not check that the name resolves or is registered.
|
|
61
|
+
|
|
62
|
+
`isSpecialUse` is true for names that never resolve on the public internet: everything in IANA's [special-use registry](https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml) (`localhost`, `local`, `test`, `invalid`, `example`, `onion`, `alt`, `home.arpa`, ...), plus `internal`, and any subdomain of those. Use it to reject such hosts in a form, or to skip them in a crawler.
|
|
63
|
+
|
|
64
|
+
### TLD info
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
getTldInfo('xn--h2brj9c');
|
|
68
|
+
// {
|
|
69
|
+
// tld: 'भारत', canonical lowercase Unicode form
|
|
70
|
+
// ascii: 'xn--h2brj9c', form used in DNS
|
|
71
|
+
// type: 'country-code', 'generic' | 'country-code' | 'infrastructure'
|
|
72
|
+
// idn: true,
|
|
73
|
+
// brand: false, ICANN ".brand" TLD, closed to the public
|
|
74
|
+
// terminated: false, ICANN terminated the registry agreement; being wound down
|
|
75
|
+
// countryCode: 'IN', ccTLDs only, ISO 3166-1 alpha-2
|
|
76
|
+
// }
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`terminated` marks the few gTLDs (such as `.desi`) whose registry agreement ICANN has terminated. They still resolve, but are on their way out of the root zone.
|
|
80
|
+
|
|
81
|
+
`countryCode` works with `Intl.DisplayNames` to get a country name:
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
const { countryCode } = getTldInfo('de');
|
|
85
|
+
new Intl.DisplayNames(['en'], { type: 'region' }).of(countryCode); // 'Germany'
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`.uk` maps to `GB`. ISO's exceptionally reserved codes are used where they apply, e.g. `.eu` is `EU` and `.ac` is `AC`.
|
|
89
|
+
|
|
90
|
+
### Filtering
|
|
91
|
+
|
|
92
|
+
```js
|
|
93
|
+
listTlds(); // every TLD, sorted by ASCII form
|
|
94
|
+
listTlds({ type: 'country-code' }); // 309 ccTLDs
|
|
95
|
+
listTlds({ type: 'generic', brand: false }); // gTLDs anyone can register under
|
|
96
|
+
listTlds({ idn: true }); // internationalized TLDs
|
|
97
|
+
listTlds({ type: 'generic', brand: false, terminated: false }); // gTLDs open to new sign-ups
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### TypeScript
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { normalizeTld, type KnownTld, type Tld } from 'global-tld-list';
|
|
104
|
+
|
|
105
|
+
const tld: Tld | undefined = normalizeTld(input);
|
|
106
|
+
const allowed: KnownTld[] = ['com', 'org', 'in']; // typos are compile errors
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`Tld` is exactly the TLDs in the root zone today, so it loses a member when IANA removes a TLD. `KnownTld` is `Tld` plus every removed TLD and only ever grows, so prefer it for lists written in your own code: a removal then never breaks your build after an update.
|
|
110
|
+
|
|
111
|
+
## Registry details
|
|
112
|
+
|
|
113
|
+
Registry operators, delegation dates, RDAP servers and removed TLDs live in a separate entry point so the main bundle stays small (about 12 KB gzipped for the main entry, plus about 26 KB for details).
|
|
114
|
+
|
|
115
|
+
```js
|
|
116
|
+
import { getTldDetails, getRdapUrl } from 'global-tld-list/details';
|
|
117
|
+
|
|
118
|
+
getTldDetails('com');
|
|
119
|
+
// {
|
|
120
|
+
// ...getTldInfo('com'),
|
|
121
|
+
// registryOperator: 'VeriSign, Inc.', generic TLDs only
|
|
122
|
+
// delegationDate: '1985-01-01', generic TLDs only
|
|
123
|
+
// rdapServers: ['https://rdap.verisign.com/com/v1/'],
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
getRdapUrl('example.com'); // 'https://rdap.verisign.com/com/v1/domain/example.com'
|
|
127
|
+
getRdapUrl('münchen.com'); // 'https://rdap.verisign.com/com/v1/domain/xn--mnchen-3ya.com'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
[RDAP](https://about.rdap.org/) is the JSON successor to WHOIS. A `404` from the URL `getRdapUrl` returns means the domain is not registered, which makes a simple availability check:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
const url = getRdapUrl('my-new-startup.com');
|
|
134
|
+
const available = url !== undefined && (await fetch(url)).status === 404;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
About 1,200 TLDs publish an RDAP server: every gTLD except `.edu` and `.mil`, but only a minority of ccTLDs. `getRdapUrl` returns `undefined` for the rest.
|
|
138
|
+
|
|
139
|
+
### Removed TLDs
|
|
140
|
+
|
|
141
|
+
```js
|
|
142
|
+
import { getRemovedTld, isRemovedTld, listRemovedTlds } from 'global-tld-list/details';
|
|
143
|
+
|
|
144
|
+
isRemovedTld('active'); // true
|
|
145
|
+
getRemovedTld('active');
|
|
146
|
+
// { tld: 'active', ascii: 'active', type: 'generic', removalDate: '2019-02-17' }
|
|
147
|
+
listRemovedTlds(); // every removed TLD, sorted by ASCII form
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Removed gTLDs and their removal dates come from ICANN. Any other TLD that disappears from the root zone is added on the day the daily update first finds it missing. ccTLDs retired before this list existed (such as `.an` and `.tp`) are not included.
|
|
151
|
+
|
|
152
|
+
## 1.x API
|
|
153
|
+
|
|
154
|
+
The original API still works:
|
|
155
|
+
|
|
13
156
|
```js
|
|
14
157
|
import { TLDs } from 'global-tld-list';
|
|
15
158
|
|
|
16
|
-
|
|
159
|
+
TLDs.isValid('com'); // true
|
|
160
|
+
TLDs.tlds; // Map<string, 1> of every TLD in Unicode form
|
|
17
161
|
```
|
|
18
162
|
|
|
19
|
-
|
|
20
|
-
|
|
163
|
+
Since 1.29 `TLDs.isValid` is as forgiving as `isTld` (case, leading dot, punycode). The undocumented `data/serialized.json` file is no longer published; use `listTlds()` or `TLDs.tlds` instead.
|
|
164
|
+
|
|
165
|
+
## Updates
|
|
166
|
+
|
|
167
|
+
A GitHub Action regenerates the data from IANA and ICANN every day. A new version is published only when the data changed, and never when a download fails or looks truncated.
|
|
168
|
+
|
|
169
|
+
Each release's changelog entry says what changed. A TLD added or removed is a minor release (`feat(data): add .foo and remove .bar`); a change to registry details only, such as a renamed operator or new RDAP server, is a patch release (`fix(data): update .foo registry details`). The commit lists every change.
|