The ‘url’ module provides utilities for URL resolution and parsing. The getters and setters implement the properties of URL objects on the class prototype, and the URL class is available on the global object.
Example:
Javascript
const searchpar = new URLSearchParams( "keya=vala&keyb=valb" );
for (let pair of searchpar.entries()) {
console.log(pair[0] + ', ' + pair[1]);
}
|
Output:
keya, vala
keyb, valb
The Complete list of URL is listed below:
Methods
|
Description
|
URL() |
It provides utilities for URL resolution and parsing |
url.toString() |
It is an inbuilt application programming interface(API) of the URL module |
URL.toJSON() |
Return the serialized URL of the URL object. |
url.domainToUnicode() |
Get the domain for the particular ASCII value. |
API
|
Description
|
hash |
Get and set the fragment portion of the URL. |
host API |
Get and set the host portion of the URL. |
origin API |
This url.origin is an inbuilt application programming interface(API) of the URL class |
username API |
Get and set the username of URL. |
search API |
Get and set the query part of URL. |
port API |
Get and set the port portion of the URL.the port value may be a number |
pathname API |
Get and set the pathname portion of the URL. |
password API |
Get and set the password portion of the URL. |
href API |
It is an Inbuilt application programming interface of class URL within the url module |
hostname API |
Get and set the hostname portion of the URL. |
pathToFileURL API |
Converts the path to a file and ensures that the URL control characters (/, \, : ) |
fileURLToPath API |
Decodes the file URL to a path string and ensures that the URL control characters (/, %) |
parse(urlString, parseQueryString, slashesDenoteHost) |
It takes a URL string, parses it, and it will return a URL object with each part of the address as properties. |
Special Schemes of protocol API |
Get and set the protocol scheme of the URL. |
protocol |
Get and set the protocol portion of the URL. |
domainToASCII |
It is an inbuilt application programming interface of class URL within url module. |
domainToUnicode |
It is an inbuilt application programming interface of class URL within url module. |
resolve(from,to) |
It is an inbuilt method of class URL that resolves a target URL relative to a base URL. |
format(urlObject) |
It is an inbuilt API provided by URL class, which takes an object or string |
format |
With the help of url.format()method, we are able to format the hostname according to our needs. |
Class: URLSearchParams
Class: URLSearchParams
|
Description
|
append() |
This method adds a key/value pair specified by the user. |
delete() |
This method deletes the parameter specified by the user and all its associated values. |
entries() |
Returns an iterator that allows iterating through all the key/value pairs present in the object. |
forEach() |
Returns an iterator that allows iterating through all values contained in this object with the help of a callback function. |
get() |
Returns the first value of the input search parameter. |
get() |
Get the value for a particular name entry present in the URL search params object. |
getAll() |
Returns all the values of the input search parameter in the form of an array. |
sort() |
This method uses a stable sorting algorithm. |
toString() |
Get the object of uri search params to the object as a string. |
keys() |
Get the iterator object containing all the name entries only of the URL search params object. |
values() |
In the URLSearchParams interface, the values() method returns an iterator |
set() |
Sets the value given as an input parameter. |
toString() |
Returns a query string that is suitable for use in a URL. |
keys() |
In the URLSearchParams interface, the keys() method returns an Iterator |
has() |
In the URLSearchParams interface, the has() method returns a Boolean |
Legacy urlObject:
auth |
Return the string of parameters. |
hash |
It is used for identifying the “fragment” portion of a URL. |
host |
Return the hostname in the URL as a string. |
search |
Get the search query within the hostname which is followed by the ‘?’ character. |
protocol |
It is used by the given hostname. |
href |
Return the complete URL string along with the protocols(HTTP) and pathname or other search terms. |
query |
Check whether the query is a string or an object. |
slashes |
It is used when one wants to check whether there is a need for ASCII valued forward-slash character (/) after the colon (:) |
port |
Get the numeric port portion of the host component within the hostname. |
pathname |
It is used by the given hostname. |
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!