mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Perf: faster is-domain-loose check
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
const rDomain = /^(((?!\-))(xn\-\-)?[a-z0-9\-_]{0,61}[a-z0-9]{1,1}\.)*(xn\-\-)?([a-z0-9\-]{1,61}|[a-z0-9\-]{1,30})\.[a-z]{2,}$/m;
|
||||
const { parse } = require('tldts');
|
||||
|
||||
module.exports.isDomainLoose = (domain) => rDomain.test(domain);
|
||||
module.exports.isDomainLoose = (domain) => {
|
||||
const { isIcann, isPrivate, isIp } = parse(domain, { allowPrivateDomains: true });
|
||||
return !!(!isIp && (isIcann || isPrivate));
|
||||
};
|
||||
|
||||
module.exports.normalizeDomain = (domain) => {
|
||||
const { isIcann, isPrivate, hostname, isIp } = parse(domain, { allowPrivateDomains: true });
|
||||
if (isIp) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isIcann || isPrivate) {
|
||||
return hostname;
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user