The library constrains URLs by types of the function parameters:
- A
URL
parameter only accepts an absolute URL. - A
string
parameter accepts either an absolute URL or a relative URL.
npm install --save url-operator
# or
yarn add url-operator
function setProtocol(url: URL, protocol: string): URL
function setUsername(url: URL, username: string): URL
function setPassword(url: URL, password: string): URL
function setHost(url: URL, host: string): URL
function setPort(url: URL, port: number): URL
function setPathname(url: URL, pathname: string): URL
function appendPathname(url: URL, pathname: string): URL
function setSearch(url: URL, search: string): URL
function setSearchParam(url: URL, name: string, value: string | number): URL
function setSearchParams(url: URL, searchParams: Record<string, string | number>): URL
function appendSearchParam(url: URL, name: string, value: string | number): URL
function setHash(url: URL, hash: string): URL
function encode(url: string): string
function decode(url: string): string