Name Last Update
..
lib Loading commit data...
test Loading commit data...
.jshintignore Loading commit data...
.jshintrc Loading commit data...
.npmignore Loading commit data...
.travis.yml Loading commit data...
LICENSE Loading commit data...
README.md Loading commit data...
package.json Loading commit data...

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("some.subdomain.example.co.uk")).to.eql({
    subdomain: "some.subdomain",
    domain: "example",
    tld: "co.uk"
});

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

expect(parseDomain("unknown.tld.kk")).to.equal(null);
expect(parseDomain("invalid url")).to.equal(null);
expect(parseDomain({})).to.equal(null);


Setup

npm status

Build Status Dependency Status Coverage Status

browser support


API

parseDomain(url: String): ParsedDomain|null

Returns null if url has an unknown tld or if it's not a valid url.

ParsedDomain

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


License

Unlicense