How to use parse-domain - 8 common examples

To help you get started, we’ve selected a few parse-domain examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Automattic / delphin / app / lib / domains / index.js View on Github external
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;
github SUI-Components / sui / packages / sui-ssr / server / index.js View on Github external
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
            )
    })
github Automattic / delphin / app / lib / domains / index.js View on Github external
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;
}
github Automattic / delphin / app / lib / domains / nameservers.js View on Github external
export const isNameserverValid = value => {
	const { subdomain, domain, tld } = parseDomain( value ) || {};

	return compact( [ subdomain, domain, tld ] ).join( '.' ) === value;
};
github jeffcousins / postbrew / client / components / PostItem.jsx View on Github external
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>
      );
    }
  }
github DIYgod / RSSHub-Radar / src / js / background / utils.js View on Github external
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) {
github DIYgod / RSSHub-Radar / src / js / background / utils.js View on Github external
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 [];
github Automattic / delphin / app / lib / domains / index.js View on Github external
export function secondLevelDomainOf( validDomain ) {
	const parsedDomain = parseDomain( validDomain );
	return parsedDomain && parsedDomain.domain || '';
}

parse-domain

Splits a hostname into subdomains, domain and (effective) top-level domains

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis

Popular parse-domain functions