URL
Browser-compatible URL class, implemented by following the WHATWG URL Standard. Examples of parsed URLs may be found in the Standard itself.
Instance Members
hash: StringGets and sets the fragment portion of the URL.
host: StringGets and sets the host portion of the URL.
hostname: StringGets and sets the hostname portion of the URL
The key difference between url.host and url.hostname is that url.hostname does not include the port.
href: StringGets and sets the serialized URL.
origin: StringGets the read-only serialization of the URL's origin.
password: StringGets and sets the password portion of the URL.
pathname: StringGets and sets the path portion of the URL.
port: StringGets and sets the port portion of the URL.
The port value may be a number or a string containing a number in the range 0 to 65535 (inclusive).
Setting the value to the default port of the URL objects given protocol will result in the port value becoming the empty string ('').
protocol: StringGets and sets the protocol portion of the URL.
search: StringGets and sets the serialized query portion of the URL.
searchParams: URLSearchParamsGets the URLSearchParams object representing the query parameters of the URL.
This property is read-only; to replace the entirety of query parameters of the URL, use the url.search setter.
See URLSearchParams documentation for details.
username: StringGets and sets the username portion of the URL.
toString(): StringThe toString() method on the URL object returns the serialized URL.
The value returned is equivalent to that of url.href and url.toJSON().
Because of the need for standard compliance, this method does not allow users to customize the serialization process of the URL.
For more flexibility, require('url').format() method might be of interest.
| Returns |
|---|
| String |
toJSON(): StringThe toJSON() method on the URL object returns the serialized URL.
The value returned is equivalent to that of url.href and url.toString().
This method is automatically called when an URL object is serialized with JSON.stringify().
| Returns |
|---|
| String |
Creates a new URL object by parsing the input relative to the base.
If base is passed as a string, it will be parsed equivalent to new URL(base).
| Name | Type | Default |
|---|---|---|
input |
String | |
base |
String | (optional) |
Metadata
| Name | Parameters |
|---|---|
:jsRequire |
"url", "URL" |