RGJS6 URI module.
Members
-
<static, constant> clean
-
Clean up path. Removes double (//) and trailing slashes.
Note: ignores[protocol]://double slash!
Moved to rgjs.path.clean()- Deprecated:
-
- Yes
Example
// Returns 'https://www.example.com/path/to/index.html' rgjs.uri.concat('https://', 'www.example.com', 'path', 'to', 'index.html');
Methods
-
<static> buildParams(obj)
-
Build URI params from key-value object.
Note: '?' is NOT prepended. Values are encoded if needed.Parameters:
Name Type Description objobject An object containing key-value pairs.
Returns:
Query string, ex: 'key1=val1&key2=val2'.
- Type
- string
Example
const params_obj = { query: 'some_value', filters: [ 'value_1', 'value_2', ], }; rgjs.uri.buildParams(params_obj) // query=some_value&filters[]=value_1&filters[]=value_2 -
<static> concat(path [, args])
-
Concat a (URI) path.
You should use rgjs.path.concat()Parameters:
Name Type Argument Description pathstring A path.
args* <optional>
<repeatable>
More paths.
- Deprecated:
-
- Yes
Returns:
The concatonated filepath
- Type
- string
Example
// Returns 'https://www.example.com/path/to/index.html' rgjs.uri.concat('https://', 'www.example.com', 'path', 'to', 'index.html'); -
<static> decodeURIComp(urlcomp [, force])
-
decodeURIComponent that checks if decoding is required.
Parameters:
Name Type Argument Description urlcompstring Url or other type of string that (may) need decoding.
forceboolean <optional>
Force decoding, even if the 'urlcomp' already seems to be decoded.
Returns:
- Type
- string
Examples
rgjs.uri.decodeURIComp('https%3A%2F%2Fwww.example.com'); // https://www.example.com// No change (because already encoded) rgjs.uri.decodeURIComp('https://www.example.com'); // https://www.example.com -
<static> decodeUriComp()
-
decodeURIComponent that checks if decoding is required.
Alias of [rgjs.uri.decodeURIComp()]{@ module:rgjs/uri~decodeURIComp}. -
<static> encodeURIComp(urlcomp [, force] [, times])
-
encodeURIComponent that checks if encoding is required.
Parameters:
Name Type Argument Default Description urlcompstring Url or other type of string that (may) need encoding.
forceboolean <optional>
Optional Force encoding, even if the 'urlcomp' already seems to be encoded.
timesnumber <optional>
1 Optional. Number of times to encode. Defaults to 1.
Returns:
- Type
- string
Examples
rgjs.uri.encodeURIComp('https://www.example.com'); // https%3A%2F%2Fwww.example.com// No change (because already encoded) rgjs.uri.encodeURIComp('https%3A%2F%2Fwww.example.com'); // https%3A%2F%2Fwww.example.com// Encode twice rgjs.uri.encodeURIComp('https://www.example.com', true, 2); // https%253A%252F%252Fwww.example.com -
<static> encodeUriComp()
-
encodeURIComponent that checks if encoding is required.
Alias of [rgjs.uri.encodeURIComp()]{@ module:rgjs/uri~encodeURIComp}. -
<static> getAllParams( [url])
-
Get all URI params.
Parameters:
Name Type Argument Description urlstring <optional>
Optional. Defaults to window.location.href.
Returns:
All href params as an object ({key: value, etc}).
- Type
- object
Example
// Example url: www.example.com/?query=some_value rgjs.uri.getAllParams(); // {query: 'some_value'}; -
<static> getParam(key [, fallback] [, url])
-
Get URI param by key.
Parameters:
Name Type Argument Description keystring The parameter key.
fallback* <optional>
Optional. A fallback value when key is not set. Defaults to NULL.
urlstring <optional>
Optional. Defaults to window.location.href.
Returns:
The result or defaultValue on failure.
- Type
- string
Example
// Example url: www.example.com/?query=some_value rgjs.uri.getParam('query'); // 'some_value' -
<static> isURICompEncoded(str)
-
Checks a sequence of % (percent), one digit and another digit or letter from A to F, i.e. %20, %2F, %2E, etc.s
Parameters:
Name Type Description strstring The string that may be uri encoded.
Returns:
True or false.
- Type
- boolean
Example
rgjs.uri.decodeURIComp('https%3A%2F%2Fwww.example.com'); // true rgjs.uri.decodeURIComp('https://www.example.com'); // false -
<static> isUriCompEncoded()
-
Checks a sequence of % (percent), one digit and another digit or letter from A to F, i.e. %20, %2F, %2E, etc.
Alias of isUriCompEncoded(). -
<static> urlify(str [, maxLen] [, maxWords])
-
Url-ify a string. Strips all characters except alphanumeric, replace spaces with dashes, lowercases.
Parameters:
Name Type Argument Default Description strstring The string.
maxLennumber <optional>
-1 Optional. Maximum number of characters. Defaults to unlimited (-1)
maxWordsnumber <optional>
-1 Optional. Maximum number of words. Defaults to unlimited (-1)
Returns:
The urlified string.
- Type
- string
Example
rgjs.uri.urlify('https://www.example.com'); // 'https-www-example-com'