Skip to main content

SipaUrl

SipaUrl

SipaUrl

Tool class to access and manipulate the current or given URLs

SipaUrl.getUrl() string

Get the current address of the website

Example

SipaUrl.getUrl();
// => https://my-website.com/web/?page=abc&param=ok

SipaUrl.getProtocol() 'http' | 'https'

Get the protocol of the current url (without colon)

Example

SipaUrl.getProtocol();
// => 'https'

SipaUrl.getHostName() string

Get the host name of the current url

Example

localhost
127.0.0.1
localhost:7000
my-domain.com

SipaUrl.getParams() Object.<string, string>

Get all params of the current URL

Example

// URL: https://my-business.com/?one=1&stat=true
SipaUrl.getParams();
// => { "one": "1", "stat": "true" }

SipaUrl.setParams(params)

Set or overwrite given parameters of the current url

ParamTypeDescription
paramsObject.<string, string>in format { param1: value1, param2: value2, ... }

Example

// URL: https://my-business.com/?one=1&stat=true&that=cool
SipaUrl.setParams({ "more": "better", "stat": "false"});
// URL: https://my-business.com/?one=1&stat=false&that=cool&more=better

SipaUrl.setParam(param_key, value)

Set or overwrite one specific parameter of the current url

ParamType
param_keystring
valuestring

Example

// URL: https://my-business.com/?super=banana&coca=cola
SipaUrl.setParam("pepsi","coke");
// URL: https://my-business.com/?super=banana&coca=cola&pepsi=coke

SipaUrl.removeParams(param_keys)

Remove given params of the current url

ParamType
param_keysArray.<String>

Example

// URL: https://my-business.com/?some=stuff&foo=bar&more=power
SipaUrl.removeParams(["some","more"]);
// URL: https://my-business.com/?foo=bar

SipaUrl.removeParam(param_key)

Remove given param of the current url

ParamType
param_keystring

Example

// URL: https://my-business.com/?some=stuff&foo=bar
SipaUrl.removeParam("foo");
// URL: https://my-business.com/?some=stuff

SipaUrl.setAnchor(anchor, jump)

Set or overwrite given anchor of the current url

ParamTypeDefaultDescription
anchorstringwithout leading # character
jumpbooleanfalsejump to anchor

SipaUrl.removeAnchor()

Remove the anchor of the current URL

Example

// URL: https://my-business.com/?some=stuff&foo=bar#my-anchor
SipaUrl.removeAnchor();
// URL: https://my-business.com/?some=stuff&foo=bar

SipaUrl.getAnchor() string

Get the anchor of the current URL without leading #

SipaUrl.createUrlParams(params, options) string

Creates an url query string based on the given key<->value object

ParamTypeDescription
paramsObject.<string, string>in format { param1: value1, param2: value2, ... }
optionsObject
options.url_encodebooleanurl encode parameter keys and values, default: true
options.multi_param_attributesbooleanif attribute is of array, make it 'id=1&id=2&id=3' on true, or 'id=1,2,3' on false

Example

{ a: 1, b: [1,2,3], c: "test space" }
=>
'a=1&b=1&b=2&b=3&c=test%20space'

SipaUrl.getParamsOfUrl(url, options) Object.<string, string>

Create a JSON, containing the parameters of the given url

Returns: Object.<string, string> - return a JSON with { param1: value1, param2: value2, ... }

ParamTypeDescription
urlstringthe url to extract parameters from
optionsObject
options.decode_uribooleandecode uri parameter values

Example

SipaUrl.getParamsOfUrl("https://my-business.com/?some=stuff&foo=bar");
// => { "some": "stuff", "foo": "bar" }

SipaUrl.removeParamsOfUrl(url, param_keys) string

Remove the given parameters from the given url

ParamTypeDescription
urlstringto remove the params from
param_keysArray.<String>array of keys to remove from the given url, e.g. ['key1','key2'}

SipaUrl.removeParamOfUrl(url, param_key)

Remove the given one parameter from the given url

ParamTypeDescription
urlstring
param_keystringname of the param

SipaUrl.setParamsOfUrl(url, params) string

Set/overwrite the parameters of the given url

Returns: string - with given parameters

ParamTypeDescription
urlstring
paramsObject.<string, string>in format { param1: value1, param2: value2, ... }

SipaUrl.setAnchorOfUrl(url, anchor) string

Set/overwrite the anchor of the given url

Returns: string - with given anchor

ParamTypeDescription
urlstring
anchorstringas string, without leading #

SipaUrl.getAnchorOfUrl(url, options) string

Get the anchor of the given url

Returns: string - the anchor of the given url

ParamTypeDescription
urlstring
optionsobject
options.return_prefixed_hashbooleanreturn the prefixed hash

SipaUrl.removeAnchorOfUrl(url) string

Remove the anchor of the given url

Returns: string - without anchor

ParamType
urlstring