Encoding (@std/encoding)
@std/encoding converts between u8[] bytes and hex / base64 strings.
import { hexEncode, base64Encode, base64Decode } from "@std/encoding";
console.log(hexEncode("abc")); // 616263 (a string coerces to u8[])console.log(base64Encode("hello")); // aGVsbG8=
let bytes: u8[] = base64Decode("YWJj");let s: string = bytes; // "abc"console.log(s);Reference
hexEncode(bytes: u8[]): string // lowercase hexhexDecode(s: string): u8[] // throws on odd length / non-hexbase64Encode(bytes: u8[]): string // standard, paddedbase64Decode(s: string): u8[] // throws on malformed inputA string coerces to u8[] (its UTF-8 bytes), so hexEncode("abc") works directly. Decoders return
a u8[], which coerces back to a string when you need text.