This block provides an object with a set of methods for decoding a URI-encoded string.
Name | Return type | Description |
---|---|---|
decodeURI(str {String} ) |
String |
Decodes a URI. |
decodeURIComponent(str {String} ) |
String |
Decodes a URI component. |
Element | Usage | Description |
---|---|---|
querystring | JS |
This element provides an object with a set of methods for working with a URI query string. It decodes the string from URI format. |
Element | Name | Returned value | Description |
---|---|---|---|
querystring | parse(str {String} ) |
Object |
Creates an object using the query parameters from the address bar. |
stringify(obj {Object} ) |
String |
Creates a query string based on the object properties. |
The block is implemented in:
vanilla.js
Both of these methods function as wrappers for the standard JavaScript methods decodeURI
and decodeURIComponent
.
As they execute, the methods check whether the passed string is in UTF-8 format. If not, they generate an error.
decodeURI
methodDecodes a URI. This method is identical to the standard JavaScript method decodeURI, but it supports Cyrillic encoding CP-1251
.
Accepted arguments:
str {String}
– A string with escape sequences. Required argument.Return value: String
. If escape sequences are not found in the string, the method returns the string without any changes.
Example:
modules.require('uri', function(uri){
uri.decodeURI("https://developer.mozilla.org/ru/docs/JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "https://developer.mozilla.org/ru/docs/JavaScript_Shells"
})
decodeURIComponent
methodDecodes a URI component. This method is identical to the standard JavaScript method decodeURIComponent, but it supports Cyrillic encoding CP-1251
.
Accepted arguments:
str {String}
– A string with escape sequences. Required argument.Return value: String
. If escape sequences are not found in the string, the method returns the string without any changes.
Example:
modules.require('uri', function(uri){
uri.decodeURIComponent("JavaScript_%D1%88%D0%B5%D0%BB%D0%BB%D1%8B");
// "JavaScript_Shells"
})
querystring
elementThis element provides an object with a set of methods for working with a URI query string.
parse
methodCreates an object using the parameters from a URI query string.
Accepted arguments:
str {String}
– A string with parameters as key-value pairs. The =
symbol separates a key from its value. Pairs are separated by the &
symbol. During parsing, keys and values are decoded from URI format. Required argument.Return value: Object
. The object created from the parameters in the address bar.
stringify
methodCreates a URI query string from an object.
Accepted arguments:
obj {Object}
– The object to create the string from. Required argument.Return value: String
. Property names are separated from values by the =
symbol, and the &
symbol separates pairs in the string.