Socket
Socket
Sign inDemoInstall

parse-domain

Package Overview
Dependencies
0
Maintainers
1
Versions
53
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    parse-domain

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


Version published
Weekly downloads
129K
increased by13.8%
Maintainers
1
Install size
230 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 20 May 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc