https://github.com/doga/dns-domain
A JavaScript library for checking the validity of DNS names.
https://github.com/doga/dns-domain
dns punycode
Last synced: 3 months ago
JSON representation
A JavaScript library for checking the validity of DNS names.
- Host: GitHub
- URL: https://github.com/doga/dns-domain
- Owner: doga
- License: apache-2.0
- Created: 2025-05-16T16:25:46.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-05-16T20:07:54.000Z (7 months ago)
- Last Synced: 2025-06-16T07:11:13.764Z (6 months ago)
- Topics: dns, punycode
- Language: JavaScript
- Homepage:
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dns-domain
A JavaScript library for checking the validity of DNS names.
## Usage example
Basic usage:
description = '''
Create DNS name objects, and list the allowed and disallowed TLDs.
'''
```javascript
import { DnsDomain, effective_toplevel_domains } from 'https://esm.sh/gh/doga/dns-domain@1.0.0/mod.mjs';
// create a domain object under an allowed top-level domain
try{
console.group('Check whether these DNS domain names have an allowed TLD as direct parent:');
[
'vocab.qworum.net', 'qworum.net',
'mañana.rocks', 'xn--maana-pta.rocks', // Unicode and Punycode representations of the same domain name
]
.map(dnsDomainStr => new DnsDomain(dnsDomainStr))
.forEach(
dnsDomain => console.info(`"${dnsDomain}":`, dnsDomain.isDirectTldSubdomain())
);
console.groupEnd();
}catch(error){
// a domain has wrong format or is not under an allowed top-level domain
console.error(`${error}`);
}
// Print out effective_toplevel_domains.
console.group(`All allowed top-level domains:`);
for (const domainStr of effective_toplevel_domains.included) {
console.info(`"${domainStr}"`);
}
console.groupEnd();
console.group(`All disallowed top-level domains:`);
for (const domainStr of effective_toplevel_domains.excluded) {
console.info(`"${domainStr}"`);
}
console.groupEnd();
```
Sample output for the code above:
```text
Check whether these DNS domain names have an allowed TLD as direct parent:
"vocab.qworum.net": false
"qworum.net": true
"mañana.rocks": true
"mañana.rocks": true
All allowed top-level domains:
"ac"
"com.ac"
"edu.ac"
...
"noip.me"
"webhop.me"
"bounceme.net"
"ddns.net"
"eating-organic.net"
"mydissent.net"
"myeffect.net"
"mymediapc.net"
"mypsx.net"
"mysecuritycamera.net"
"nhlfan.net"
"no-ip.net"
"pgafan.net"
"privatizehealthinsurance.net"
"redirectme.net"
"serveblog.net"
"serveminecraft.net"
"sytes.net"
"cable-modem.org"
"collegefan.org"
"couchpotatofries.org"
"hopto.org"
...
All disallowed top-level domains:
...
"sch.uk"
"on-acorn.io"
"dev.adobeaemcloud.com"
"compute.estate"
"alces.network"
"compute.amazonaws.com.cn"
"compute.amazonaws.com"
"compute-1.amazonaws.com"
"cn-north-1.airflow.amazonaws.com.cn"
"cn-northwest-1.airflow.amazonaws.com.cn"
"af-south-1.airflow.amazonaws.com"
"ap-east-1.airflow.amazonaws.com"
"ap-northeast-1.airflow.amazonaws.com"
"ap-northeast-2.airflow.amazonaws.com"
"ap-northeast-3.airflow.amazonaws.com"
"ap-south-1.airflow.amazonaws.com"
"ap-south-2.airflow.amazonaws.com"
"ap-southeast-1.airflow.amazonaws.com"
"ap-southeast-2.airflow.amazonaws.com"
"ap-southeast-3.airflow.amazonaws.com"
"ap-southeast-4.airflow.amazonaws.com"
"ca-central-1.airflow.amazonaws.com"
"ca-west-1.airflow.amazonaws.com"
"eu-central-1.airflow.amazonaws.com"
"eu-central-2.airflow.amazonaws.com"
"eu-north-1.airflow.amazonaws.com"
"eu-south-1.airflow.amazonaws.com"
"eu-south-2.airflow.amazonaws.com"
"eu-west-1.airflow.amazonaws.com"
...
```
### Running the usage example
Run the example above by typing this in your terminal (requires [Deno](https://deno.com/) 2+):
```shell
deno run --allow-net --allow-run --allow-env --allow-read jsr:@andrewbrey/mdrb@3.0.4 --dax=false --mode=isolated https://raw.githubusercontent.com/doga/dns-domain/refs/heads/main/README.md
```
∎