url-operator
v0.3.1
Published
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.
Downloads
1,503
Readme
url-operator
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.
Install
npm install --save url-operator
# or
yarn add url-operator
API
setProtocol
function setProtocol(url: URL, protocol: string): URL
setUsername
function setUsername(url: URL, username: string): URL
setPassword
function setPassword(url: URL, password: string): URL
setHost
function setHost(url: URL, host: string): URL
setPort
function setPort(url: URL, port: number): URL
setPathname
function setPathname(url: URL, pathname: string): URL
appendPathname
function appendPathname(url: URL, pathname: string): URL
setSearch
function setSearch(url: URL, search: string): URL
setSearchParam
function setSearchParam(url: URL, name: string, value: string | number): URL
setSearchParams
function setSearchParams(url: URL, searchParams: Record<string, string | number>): URL
appendSearchParam
function appendSearchParam(url: URL, name: string, value: string | number): URL
setHash
function setHash(url: URL, hash: string): URL
encode
function encode(url: string): string
decode
function decode(url: string): string