JavaScript 库用于从复杂 URI 中提取域名、子域名和公共后缀。
tldts 是一个 JavaScript 库,用于从 URL 中提取主机名、域名、公共后缀、顶级域名和子域名。
umd、esm、cjs 组件和 _类型定义_一起提供8. 组件小,占用内存少9. 经过实战测试:全面的测试覆盖和生产使用$ 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": ""
}通过程序化方式:
const { parse } = require('tldts');
// 从给定的 URL 中检索主机名相关信息
parse('http://www.writethedocs.org/conf/eu/2017/'');
// { domain: 'writethedocs.org',
// domainWithoutSuffix: 'writethedocs',
// hostname: 'www.writethedocs.org',
// isIcann: true,
// isIp: false,
// isPrivate: false,
// publicS暂无开放 Issues,或尚未同步最近议题。