JSPM

  • Created
  • Published
  • Downloads 217720
  • Score
    100M100P100Q173989F
  • License Unlicense

Finds the sub-domain, domain and top-level-domain from an url

Package Exports

  • parse-domain

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-domain) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

parse-domain

Splits an url into sub-domain, domain and top-level-domain.

Since domains are handled differently across different countries and organizations, splitting an url into sub-domain, domain and top-level-domain is not a simple regexp. parse-domain uses a large list of known tlds (borrowed from http://publicsuffix.org) to recognize different parts of the domain.

var parseDomain = require("parse-domain");

expect(parseDomain("www.example.co.uk")).to.eql({
    subdomain: "www",
    domain: "example",
    tld: "co.uk"
});

expect(parseDomain("https://user@www.some.other.subdomain.example.co.uk"
    + ":8080/some/path?and&query#hash")).to.eql({
    subdomain: "www.some.other.subdomain",
    domain: "example",
    tld: "co.uk"
});

Setup

npm status

build status dependencies devDependencies

browser support


API

parseDomain(url: String): ParsedDomain

ParsedDomain

{
    tld: String,
    domain: String,
    subdomain: String
}

License

MIT