BrowserpassURL
This package is an extension of the built-in URL class, which adds some additional properties based on the domain.
The TLD list used by this module is downloaded from publicsuffix.org when building, if it's older than one day.
Usage
const BrowserpassURL = require("@browserpass/url");
var url = new BrowserpassURL("http://www.example.com/test");
console.log(url.validDomain); // true
console.log(url.tld); // com
console.log(url.domain); // example.com
console.log(url.subdomain); // www
console.log(url.hostname); // www.example.com
// parse a raw hostname (with optional port), rather than a full URL
var urlDomainOnly = BrowserpassURL.parseHost("www.example.com:8080");
console.log(urlDomainOnly);
/* {
* hostname: 'www.example.com',
* tld: 'com',
* domain: 'example.com',
* subdomain: 'www',
* validDomain: true,
* port: '8080'
* }
*/
Extra Properties
Property | Description |
---|---|
validDomain | Whether the URL contains a valid, public domain |
tld | The public TLD component of the domain |
domain | The registered domain root |
subdomain | The subdomain portion of the hostname |