Skip to content

decode

Module Export

text decode base64 |> [byte]
text decode base64Url |> [byte]
text decode hex |> [byte]
text decode utf8 |> [byte]
text decode text |> [byte]

Decodes text to binary data using keywords like base64, base64Url, hex, or utf8/text.

The encoding type is specified using a keyword after decode.

Decoding Types

KeywordInputOutputDescription
base64text[byte]Standard Base64 decoding
base64Urltext[byte]URL-safe Base64 decoding
hextext[byte]Hexadecimal decoding
utf8text[byte]Serialize text as UTF-8 bytes
texttext[byte]Alias for utf8

Examples

Decode Base64 to bytes

import { decode } from 'text'
from 'SGVsbG8=' decode base64
// Returns: [72, 101, 108, 108, 111]

Decode hex to bytes

import { decode } from 'text'
from '48656c6c6f' decode hex
// Returns: [72, 101, 108, 108, 111]

Decode text to UTF-8 bytes

import { decode } from 'text'
from 'Hello' decode utf8
// Returns: [72, 101, 108, 108, 111]

Decode text using the text alias

import { decode } from 'text'
from 'Hello' decode text
// Returns: [72, 101, 108, 108, 111]

See Also

  • encode for encoding bytes to text