encode
Module Export
[byte] encode base64 |> text[byte] encode base64Url |> text[byte] encode hex |> text[byte] encode utf8 |> text[byte] encode text |> textEncodes binary data to a text format using keywords like base64, base64Url, hex, or utf8/text.
The encoding type is specified using a keyword after encode.
Encoding Types
| Keyword | Input | Output | Description |
|---|---|---|---|
base64 | [byte] | text | Standard Base64 encoding |
base64Url | [byte] | text | URL-safe Base64 (no padding) |
hex | [byte] | text | Lowercase hexadecimal |
utf8 | [byte] | text | Interpret bytes as UTF-8 text |
text | [byte] | text | Alias for utf8 |
Examples
Encode bytes to Base64
import { encode } from 'text'
from [72, 101, 108, 108, 111] encode base64
// Returns: 'SGVsbG8='Encode bytes to hex
import { encode } from 'text'
from [72, 101, 108, 108, 111] encode hex
// Returns: '48656c6c6f'Encode bytes as UTF-8 text
import { encode } from 'text'
from [72, 101, 108, 108, 111] encode utf8
// Returns: 'Hello'Encode bytes using the text alias
import { encode } from 'text'
from [72, 101, 108, 108, 111] encode text
// Returns: 'Hello'See Also
- decode for decoding text to bytes