whatwg-url
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
tr46 | 3.0.0 | 59.78 kB | MIT | prod | |
webidl-conversions | 7.0.0 | 7.38 kB | BSD-2-Clause | prod |
The whatwg-url package is a complete implementation of the WHATWG URL Standard. This npm package can be used standalone or for integrating a URL parser into a project. The URL API and parsing algorithm that are being followed by this package are up to date with the URL specifications stated in the standard.
To use the whatwg-url package in your JavaScript project, first install the package from npm using the command npm install whatwg-url
. Once installed, you can import the package in your modules using the require
keyword like this:
const { URL, URLSearchParams } = require('whatwg-url');
You can now create and manipulate URL objects using the URL
and URLSearchParams
classes as per the WHATWG URL standard. For example:
const myURL = new URL('https://example.org/foo#bar');
console.log(myURL.hash); // Outputs: #bar
const params = new URLSearchParams('q=test&p=123');
console.log(params.get('q')); // Outputs: test
You can also use the low-level URL standard APIs provided by the package to manipulate URL records. Here is an example of how to parse a URL using parseURL
method:
const { parseURL } = require('whatwg-url');
const urlRecord = parseURL('https://example.org/foo#bar');
console.log(urlRecord.scheme); // Outputs: https
The comprehensive documentation for the whatwg-url package lies within the WHATWG URL Standard. Moreover, detail of the low-level APIs, such as specific methods and their parameters, is listed in the readme file on the package's GitHub repository. The URL record type API is also fully explained in the readme. Developers can also refer to the URL and the URLSearchParams in the URL standard for more information.