Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function extractHostName( url ) {
url = url.trim();
// Prepares the url for parsing by removing or converting invalid characters
if ( url ) {
url = url.replace( /\\/g, '/' );
url = url.replace( /[()]/g, '' );
}
const data = parseDomain( url );
if ( data ) {
const { subdomain, domain, tld } = data;
if ( domain && tld ) {
const parts = [ domain, tld ];
if ( subdomain ) {
parts.unshift( subdomain );
}
return parts.join( '.' );
}
}
return null;
app.use((req, res, next) => {
const parsedUrl = parseDomain(req.hostname, {
customTlds: /localhost|\.local/
})
!parsedUrl || parsedUrl.tld === 'localhost' // eslint-disable-line
? next()
: parsedUrl.subdomain
? next()
: res.redirect(
`${req.protocol}://www.` + req.headers.host + req.url,
301
)
})
export function isDomain( value ) {
// handle special cases first such as '.hello.com' which is parsed to
// { tld: 'com', domain: 'hello', subdomain: '' } by the parse-domain lib
if ( typeof value !== 'string' || value.charAt( 0 ) === '.' ) {
return false;
}
const parsedDomain = parseDomain( value );
// A domain is valid if it can be parsed by the lib and it has a domain, a tld but no subdomain
return !! parsedDomain &&
parsedDomain.tld &&
isValidSecondLevelDomain( parsedDomain.domain ) &&
! parsedDomain.subdomain;
}
export const isNameserverValid = value => {
const { subdomain, domain, tld } = parseDomain( value ) || {};
return compact( [ subdomain, domain, tld ] ).join( '.' ) === value;
};
function urlHandler (providedUrl, title, brew_name, id) {
if (!providedUrl) {
return (
<div>
{title}
</div>
);
} else {
const parsed = parseDomain(providedUrl);
return (
<div>
<a href="{providedUrl}">{title}</a> <span style="{smallGrayStyle}">
[ {parsed.domain}.{parsed.tld} ]
</span>
</div>
);
}
}
function getPageRSSHub(url, tabId, done) {
const parsedDomain = parseDomain(url);
if (parsedDomain) {
const subdomain = parsedDomain.subdomain;
const domain = parsedDomain.domain + '.' + parsedDomain.tld;
if (rules[domain]) {
let rule = rules[domain][subdomain || '.'];
if (!rule) {
if (subdomain === 'www') {
rule = rules[domain]['.'];
} else if (!subdomain) {
rule = rules[domain].www;
}
}
if (rule) {
const recognized = [];
rule.forEach((ru, index) => {
if (ru.source !== undefined) {
function getWebsiteRSSHub(url) {
const parsedDomain = parseDomain(url);
if (parsedDomain) {
const domain = parsedDomain.domain + '.' + parsedDomain.tld;
if (rules[domain]) {
const domainRules = [];
for (const subdomainRules in rules[domain]) {
if (subdomainRules[0] !== '_') {
domainRules.push(...rules[domain][subdomainRules]);
}
}
return domainRules.map((rule) => ({
title: formatBlank(rules[domain]._name, rule.title),
url: rule.docs,
isDocs: true,
}));
} else {
return [];
export function secondLevelDomainOf( validDomain ) {
const parsedDomain = parseDomain( validDomain );
return parsedDomain && parsedDomain.domain || '';
}