Utilities
Utility functions available in Shelly Scripts for data encoding and conversion.
btoh()
Converts a string to hexadecimal representation.
btoh(data) -> string
| Property | Type | Description |
|---|---|---|
| string | The string to convert |
Returns: A string representing every byte of data as 2 hexadecimal digits.
let hex = btoh("Hello");
console.log(hex); // "48656c6c6f"
btoa()
Encodes a string to Base64.
btoa(data) -> string
| Property | Type | Description |
|---|---|---|
| string | The string to encode |
Returns: Base64-encoded string.
let encoded = btoa("Hello World");
console.log(encoded); // "SGVsbG8gV29ybGQ="
atob()
Decodes a Base64 string.
atob(data) -> string
| Property | Type | Description |
|---|---|---|
| string | The Base64-encoded string to decode |
Returns: Decoded string.
let decoded = atob("SGVsbG8gV29ybGQ=");
console.log(decoded); // "Hello World"
tip
Use atob() and btoa() to transfer binary data with JSON, encoding binary blobs to Base64 and back.