Gathering detailed insights and metrics for qnton-tld-extract
Gathering detailed insights and metrics for qnton-tld-extract
Gathering detailed insights and metrics for qnton-tld-extract
Gathering detailed insights and metrics for qnton-tld-extract
Simple npm package that allows to extract the TLD, domain, and subdomain.
npm install qnton-tld-extract
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,204
Last Day
27
Last Week
129
Last Month
259
Last Year
527
MIT License
4 Stars
14 Commits
1 Watchers
1 Branches
1 Contributors
Updated on May 14, 2024
Minified
Minified + Gzipped
Latest Version
2.0.2
Package Id
qnton-tld-extract@2.0.2
Unpacked Size
204.99 kB
Size
45.10 kB
File Count
8
NPM Version
9.5.1
Node Version
19.7.0
Published on
Jun 14, 2023
Cumulative downloads
Total Downloads
Last Day
575%
27
Compared to previous day
Last Week
26.5%
129
Compared to previous week
Last Month
600%
259
Compared to previous month
Last Year
-22.2%
527
Compared to previous year
5
qnton-tld-extract
is a simple npm package that allows you to extract the top-level domain (TLD), domain, and subdomain from a given URL.
You can install the qnton-tld-extract
package using npm:
1npm install qnton-tld-extract
To use the qnton-tld-extract
package, you can import it in your JavaScript or TypeScript code:
1const parseUrl = require('qnton-tld-extract'); 2 3const url = 'https://www.example.com/'; 4 5const result = parseUrl(url); 6 7console.log(result); 8// Output: { tld: 'com', domain: 'example.com', sub: 'www' }
Or if you're using TypeScript:
1import parseUrl from 'qnton-tld-extract'; 2 3const url = 'https://www.example.com/'; 4 5const result = parseUrl(url); 6 7console.log(result); 8// Output: { tld: 'com', domain: 'example.com', sub: 'www' }
By default, parseUrl extracts the TLD, domain, and subdomain from the given URL. You can also extract the TLD, domain, and subdomain from just the hostname of a URL using the parse_host function:
1const { parse_host } = require('qnton-tld-extract'); 2 3const host = 'www.example.com'; 4 5const result = parse_host(host); 6 7console.log(result); 8// Output: { tld: 'com', domain: 'example.com', sub: 'www' }
The parse_host function accepts an optional ParseOptions object that allows you to configure how the host is parsed. The available options are:
Private TLDs are supported, see chromium source code for specs
1console.log(parser('http://www.example.com')); 2// Output: { tld : 'com', domain : 'example.com', sub : 'www' }; 3 4console.log(parser('http://www.example.com', { allowPrivateTLD: true })); 5// Output: { tld : 'example.com', domain : 'www.example.com', sub : '' };
By default, unknown TLD throw an exception, you can allow them and use tld-extract as a parser using the allowUnknownTLD
option
1 parse("http://nowhere.local") 2 >> throws /Invalid TLD/ 3 4 parse("http://nowhere.local", {allowUnknownTLD : true}) 5 >> { tld : 'local', domain : 'nowhere.local', sub : '' } 6
Using a tld as a direct domain name, or dotless domain is highly not recommended (ICANN and IAB have spoken out against the practice, classifying it as a security risk among other concerns. ICANN's Security and Stability Advisory Committee (SSAC) additionally claims that SMTP "requires at least two labels in the FQDN of a mail address" and, as such, mail servers would reject emails to addresses with dotless domains), and will throw an error in tld-extract
. You can override this behavior using the allowDotlessTLD
option.
1 parse("http://notaires.fr") 2 >> throws /Invalid TLD/ 3 4 parse("http://notaires.fr", {allowDotlessTLD : true})) 5 >> { tld : 'notaires.fr', domain : 'notaires.fr', sub : '' } 6
No vulnerabilities found.
No security vulnerabilities found.