JavaScript Library to extract domains, subdomains and public suffixes from complex URIs.
Repository
Current version released
8 months ago
Versions
- v6.1.61Latest
- v6.1.60
- v6.1.59
- v6.1.58
- v6.1.57
- v6.1.56
- v6.1.55
- v6.1.54
- v6.1.53
- v6.1.52
- v6.1.51
- v6.1.50
- v6.1.49
- v6.1.48
- v6.1.47
- v6.1.46
- v6.1.45
- v6.1.44
- v6.1.43
- v6.1.42
- v6.1.41
- v6.1.40
- v6.1.39
- v6.1.38
- v6.1.37
- v6.1.36
- v6.1.35
- v6.1.34
- v6.1.33
- v6.1.32
- v6.1.31
- v6.1.30
- v6.1.29
- v6.1.28
- v6.1.27
- v6.1.26
- v6.1.25
- v6.1.24
- v6.1.23
- v6.1.22
- v6.1.21
- v6.1.20
- v6.1.19
- v6.1.18
- v6.1.17
- v6.1.16
- v6.1.15
- v6.1.14
- v6.1.13
- v6.1.12
- v6.1.11
- v6.1.10
- v6.1.9
- v6.1.8
- v6.1.7
- v6.1.6
- v6.1.5
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1.0
- v6.0.23
- v6.0.22
- v6.0.21
- v6.0.20
- v6.0.19
- v6.0.18
- v6.0.17
- v6.0.16
- v6.0.15
- v6.0.14
- v6.0.13
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v5.7.112
- v5.7.111
- v5.7.110
- v5.7.109
- v5.7.108
- v5.7.107
- v5.7.106
- v5.7.105
- v5.7.104
- v5.7.103
- v5.7.102
- v5.7.101
- v5.7.100
- v5.7.99
- v5.7.98
- v5.7.97
- v5.7.96
- v5.7.95
- v5.7.94
tldts - Blazing Fast URL Parsing
tldts
is a JavaScript library to extract hostnames, domains, public suffixes, top-level domains and subdomains from URLs.
Features:
- Tuned for performance (order of 0.1 to 1 μs per input)
- Handles both URLs and hostnames
- Full Unicode/IDNA support
- Support parsing email addresses
- Detect IPv4 and IPv6 addresses
- Continuously updated version of the public suffix list
- TypeScript, ships with
umd
,esm
,cjs
bundles and type definitions - Small bundles and small memory footprint
- Battle tested: full test coverage and production use
Install
npm install --save tldts
Usage
Using the command-line interface:
$ npx tldts 'http://www.writethedocs.org/conf/eu/2017/'
{
"domain": "writethedocs.org",
"domainWithoutSuffix": "writethedocs",
"hostname": "www.writethedocs.org",
"isIcann": true,
"isIp": false,
"isPrivate": false,
"publicSuffix": "org",
"subdomain": "www"
}
Or from the command-line in batch:
$ echo "http://www.writethedocs.org/\nhttps://example.com" | npx tldts
{
"domain": "writethedocs.org",
"domainWithoutSuffix": "writethedocs",
"hostname": "www.writethedocs.org",
"isIcann": true,
"isIp": false,
"isPrivate": false,
"publicSuffix": "org",
"subdomain": "www"
}
{
"domain": "example.com",
"domainWithoutSuffix": "example",
"hostname": "example.com",
"isIcann": true,
"isIp": false,
"isPrivate": false,
"publicSuffix": "com",
"subdomain": ""
}
Programmatically:
const { parse } = require('tldts');
// Retrieving hostname related informations of a given URL
parse('http://www.writethedocs.org/conf/eu/2017/');
// { domain: 'writethedocs.org',
// domainWithoutSuffix: 'writethedocs',
// hostname: 'www.writethedocs.org',
// isIcann: true,
// isIp: false,
// isPrivate: false,
// publicSuffix: 'org',
// subdomain: 'www' }
Modern ES6 modules import is also supported:
import { parse } from 'tldts';
Alternatively, you can try it directly in your browser here: https://npm.runkit.com/tldts
Check README.md for more details about the API.
Contributors
tldts
is based upon the excellent tld.js
library and would not exist without
the many contributors who worked on the project.
This project would not be possible without the amazing Mozilla’s public suffix list either. Thank you for your hard work!