infinity.url¶
Provides URL-encoding and decoding functionality. The infinity.url namespace is provided by the infinity.encoding module.
Module: infinity.encoding
Example:
infinity.loadModule('infinity.encoding');
let encodedData = infinity.url.encode('AUO_ÄÜÖ ß-"+&,?.<=>', infinity.encoding.utf8);
console.debug(encodedData);
//AUO_%C3%84%C3%9C%C3%96%20%C3%9F-"%2B%26%2C%3F.<%3D>
let decodedData = infinity.url.decode(encodedData, infinity.encoding.utf8);
console.debug(decodedData);
//AUO_ÄÜÖ ß-"+&,?.<=>
decode()¶
Decodes the given URL-encoded string and returns the result. Percent-encoded bytes (%XX) and %uXXXX sequences are decoded and + is converted to a space.
Signature:
decode( value: string, encoding?: infinity.encoding ): string
Parameters:
-
value:
stringThe string to decode.
-
encoding:
infinity.encoding, optionalThe character encoding of the decoded bytes. If omitted, the bytes are decoded as UTF-8 (Windows-1252 if they are not valid UTF-8);
%uXXXXsequences are then added as UTF-8 (before 3.11 they caused an access violation withoutencoding).
Return type: string
Example:
infinity.loadModule('infinity.encoding');
let decodedData = infinity.url.decode(encodedData, infinity.encoding.utf8);
encode()¶
Encodes the given string to URL-encoding and returns the result. Control characters, spaces, non-ASCII characters and the characters ! # $ % & ' ( ) * + / \ : ; = ? @ [ ] { } , are percent-encoded; all other characters are kept.
Signature:
encode( value: string, encoding?: infinity.encoding ): string
Parameters:
-
value:
stringThe string to encode.
-
encoding:
infinity.encoding, optionalThe character encoding used to convert the characters to bytes before percent-encoding. Default: UTF-8.
Return type: string
Example:
infinity.loadModule('infinity.encoding');
let encodedData = infinity.url.encode(dataToEncode, infinity.encoding.utf8);