URL
The URL interface is used to parse, construct, normalize, and encode URLs.
It works by providing properties which allow you to easily read and modify
the components of a URL.
You normally create a new URL object by specifying the URL as a string
when calling its constructor, or by providing a relative URL and a base
URL. You can then easily read the parsed components of the URL or make
changes to the URL.
Implements
Constructors
new URL()
new URL(url, base?): URL
Constructs a new URL object by parsing the specified URL.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | URL | The input URL to be parsed. |
base? | string | URL | The base URL to use in case the input URL is a relative URL. |
Returns
Properties
| Property | Modifier | Type |
|---|---|---|
hash | public | string |
host | public | string |
hostname | public | string |
href | public | string |
origin | readonly | string |
password | public | string |
pathname | public | string |
port | public | string |
protocol | public | string |
search | public | string |
username | public | string |
Accessors
searchParams
get searchParams(): URLSearchParams
Returns
Implementation of
globalThis.URL.searchParams
Methods
toJSON()
toJSON(): string
Returns a string containing the full URL. It is a synonym for the href property.
Returns
string
Implementation of
globalThis.URL.toJSON
toString()
toString(): string
Returns a string containing the full URL. It is a synonym for the href property, though it can't be used to modify the value.
Returns
string
Implementation of
globalThis.URL.toString
canParse()
static canParse(url, base?): void
Returns a boolean indicating whether or not an absolute URL, or a relative URL combined with a base URL, are parsable and valid.
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | URL | The input URL to be parsed. |
base? | string | URL | The base URL to use in case the input URL is a relative URL. |
Returns
void
See
https://developer.mozilla.org/docs/Web/API/URL/canParse_static
createObjectURL()
static createObjectURL(obj): string
Returns a string containing a URL which represents the provided Blob object.
Parameters
| Parameter | Type | Description |
|---|---|---|
obj | Blob | The object for which an object URL is to be created. |
Returns
string
revokeObjectURL()
static revokeObjectURL(url): void
Revokes an object URL previously created using URL.createObjectURL().
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | A string representing a URL that was created by calling URL.createObjectURL(). |
Returns
void