aboutsummaryrefslogtreecommitdiffstats
path: root/vanilla/node_modules/tldts-core/src/subdomain.ts
blob: bbb9c970bd2aa8149cc82661f25b12cce0b3838f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
/**
 * Returns the subdomain of a hostname string
 */
export default function getSubdomain(hostname: string, domain: string): string {
  // If `hostname` and `domain` are the same, then there is no sub-domain
  if (domain.length === hostname.length) {
    return '';
  }

  return hostname.slice(0, -domain.length - 1);
}