Skip to content

Std\Encoding

Encoding – string encoding and decoding utilities.

Provides Base64, hex, URL percent-encoding, and HTML entity escaping.

Encode a string to Base64.

import base64Encode from Std\Encoding in
base64Encode "hello" # => "aGVsbG8="

Decode a Base64-encoded string back to its original form.

import base64Decode from Std\Encoding in
base64Decode "aGVsbG8=" # => "hello"

Encode each byte of a string as two hex characters.

import hexEncode from Std\Encoding in
hexEncode "AB" # => "4142"

Decode a hex-encoded string back to bytes.

import hexDecode from Std\Encoding in
hexDecode "4142" # => "AB"

Percent-encode a string for use in URLs.

import urlEncode from Std\Encoding in
urlEncode "hello world" # => "hello%20world"

Decode a percent-encoded URL string.

import urlDecode from Std\Encoding in
urlDecode "hello%20world" # => "hello world"

Escape HTML special characters (<, >, &, ", ') to their entity equivalents.

import htmlEscape from Std\Encoding in
htmlEscape "<b>hi</b>" # => "&lt;b&gt;hi&lt;/b&gt;"