URL6
A more practical URL parser for Node.js that combines new and legacy APIs.
Install
npm install url6 --save
Example
const { URL } = require("url6");
var url = new URL("https://root:123456@example.com:443/dir/filename.html?lang=en-US#id");
console.log(url);
url.protocol = "http:"; // change protocol
url.hostname = "github.com"; // change hostname
url.port = 80; // change port
url.query.author = "Ayon Lee"; // modify query object.
console.log(url);
API
class URL
new URL(input?: string)
url.href: string
-
url.protocol: string
with trailing:
. -
url.slashes: boolean
whether//
appears after theprotocol
. url.auth: string
url.username: string
url.password: string
url.host: string
-
url.hostname: string
without trailingport
number. url.port: number
-
url.origin: string
readonly. url.path: string
-
url.pathname: string
without trailingsearch
string. url.search: string
-
url.query: { [key: string]: string }
parsed by qs module. url.hash: string
-
url.toString()
same asurl.href
. -
url.toJSON()
same asurl.toString()
.
This module is meant to bring some features from Node.js 8.0+ to Node.js 6.X
or even lower versions, it cannot be run in browser, use native URL
instead.