https://github.com/browserpass/browserpass-url
Extended URL class with domain analysis
https://github.com/browserpass/browserpass-url
Last synced: 5 months ago
JSON representation
Extended URL class with domain analysis
- Host: GitHub
- URL: https://github.com/browserpass/browserpass-url
- Owner: browserpass
- License: isc
- Created: 2019-09-29T09:28:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-07-25T20:59:32.000Z (11 months ago)
- Last Synced: 2025-09-19T01:53:07.374Z (9 months ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BrowserpassURL
This package is an extension of the built-in [URL][1] class, which adds some additional properties based on the domain.
The TLD list used by this module is downloaded from [publicsuffix.org][2] when building, if it's older than one day.
[1]: https://developer.mozilla.org/en-US/docs/Web/API/URL
[2]: https://publicsuffix.org/
## Usage
```JS
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 |