Tea — a strongly typed scripting language
Tea
DocsPlaygroundExamplesReferenceCommunity
GitHub

Tea Language

A strongly typed scripting language for native tools.

© 2026 Tea Language.

Agent documentationContributingCommunityRepository

Language Runtime

Built-ins

Standard Library

std.argsstd.assertstd.audiostd.encodingstd.envstd.fsstd.hashstd.httpstd.netstd.jsonstd.mathstd.parsestd.pathstd.processstd.randomstd.raylibstd.regexstd.stringstd.timestd.url

Read as Markdown

Standard Library

std.encoding

Binary-to-text encodings: base64, URL-safe base64, and hex.

Exported functions

pub def base64_encode(data: List[Int]) -> String

Encode bytes as standard base64 text.

Examples

use encoding from "std.encoding"

@println(encoding.base64_encode([102, 111, 111])) # Zm9v
pub def base64_encode_text(text: String) -> String

Encode UTF-8 text as standard base64 text.

Examples

use encoding from "std.encoding"

@println(encoding.base64_encode_text("hello")) # aGVsbG8=
pub def try_base64_decode(text: String) -> List[Int] ! EncodingError

Decode standard base64 text into bytes, throwing on invalid input.

Examples

use encoding from "std.encoding"

def demonstrate() -> Void
  try encoding.try_base64_decode("!!!") catch err
    case is encoding.EncodingError.InvalidBase64
      @println(`Invalid input: ${err.input}`)
      return
    case _
      @panic("unexpected encoding error")
  end
  return
end

demonstrate()
pub def base64_decode(text: String) -> List[Int]

Decode standard base64 text into bytes, panicking on invalid input.

Examples

use encoding from "std.encoding"

const encoded = encoding.base64_encode_text("foo")
@println(encoding.base64_decode(encoded)) # [102, 111, 111]
pub def base64url_encode(data: List[Int]) -> String

Encode bytes as URL-safe base64 text without padding.

Examples

use encoding from "std.encoding"

@println(encoding.base64url_encode([251, 255])) # -_8
pub def base64url_encode_text(text: String) -> String

Encode UTF-8 text as URL-safe base64 text without padding.

Examples

use encoding from "std.encoding"

@println(encoding.base64url_encode_text("hello")) # aGVsbG8
pub def try_base64url_decode(text: String) -> List[Int] ! EncodingError

Decode URL-safe base64 text into bytes, throwing on invalid input.

Examples

use encoding from "std.encoding"

def demonstrate() -> Void
  try encoding.try_base64url_decode("!!!") catch err
    case is encoding.EncodingError.InvalidBase64
      @println(`Invalid input: ${err.input}`)
      return
    case _
      @panic("unexpected encoding error")
  end
  return
end

demonstrate()
pub def base64url_decode(text: String) -> List[Int]

Decode URL-safe base64 text into bytes, panicking on invalid input.

Examples

use encoding from "std.encoding"

@println(encoding.base64url_decode("-_8")) # [251, 255]
pub def hex_encode(data: List[Int]) -> String

Encode bytes as lowercase hexadecimal text.

Examples

use encoding from "std.encoding"

@println(encoding.hex_encode([0, 255, 16])) # 00ff10
pub def hex_encode_text(text: String) -> String

Encode UTF-8 text as lowercase hexadecimal text.

Examples

use encoding from "std.encoding"

@println(encoding.hex_encode_text("foo")) # 666f6f
pub def try_hex_decode(text: String) -> List[Int] ! EncodingError

Decode hexadecimal text into bytes, throwing on invalid input.

Examples

use encoding from "std.encoding"

def demonstrate() -> Void
  try encoding.try_hex_decode("zz") catch err
    case is encoding.EncodingError.InvalidHex
      @println(`Invalid input: ${err.input}`)
      return
    case _
      @panic("unexpected encoding error")
  end
  return
end

demonstrate()
pub def hex_decode(text: String) -> List[Int]

Decode hexadecimal text into bytes, panicking on invalid input.

Examples

use encoding from "std.encoding"

@println(encoding.hex_decode("00FF10")) # [0, 255, 16]