Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Encoding functions

$base64encode

$base64encode(str) encodes a string in base 64. Each character is taken as one byte, so the string must be in the Latin-1 range (\u0000 to ÿ). Encode other text with $encodeUrlComponent first, if needed.

$base64encode("myuser:mypass")
=> "bXl1c2VyOm15cGFzcw=="

$base64decode

$base64decode(str) decodes base 64 into a string, reading the bytes as UTF-8.

$base64decode("bXl1c2VyOm15cGFzcw==")
=> "myuser:mypass"

$encodeUrlComponent

$encodeUrlComponent(str) percent-encodes the UTF-8 bytes of every character that is not allowed in a URL component. It behaves like JavaScript’s encodeURIComponent.

$encodeUrlComponent("?x=test")
=> "%3Fx%3Dtest"

$encodeUrl

$encodeUrl(str) percent-encodes a whole URL, keeping the characters that have a meaning in URLs (:/?#[]@!$&'()*+,;=). It behaves like JavaScript’s encodeURI.

$encodeUrl("https://mozilla.org/?x=шеллы")
=> "https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B"

$decodeUrlComponent

$decodeUrlComponent(str) reverses $encodeUrlComponent. Malformed escapes fail with D3140.

$decodeUrlComponent("%3Fx%3Dtest")
=> "?x=test"

$decodeUrl

$decodeUrl(str) reverses $encodeUrl.

$decodeUrl("https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B")
=> "https://mozilla.org/?x=шеллы"

Adapted from the JSONata documentation (MIT license).