base16/base32/base36/base58/base62/base64 for MoonBit — RFC 4648 hex/base32/base64 plus a big-integer base-N core behind base36/base58/base62.
Moved on mooncakes from Lfan-ke/moonbase to moonbitstack/moonbase.
| Package | What it is | Kind |
|---|---|---|
| @base16 | RFC 4648 hexadecimal | byte-oriented (2 chars/byte) |
| @base32 | RFC 4648 A-Z2-7 + base32hex 0-9A-V | byte-oriented (5 bytes → 8 chars) |
| @base36 | dense case-insensitive 0-9a-z, plus an integer mode | big-integer base-N |
| @base58 | the Bitcoin / IPFS alphabet (0OIl dropped) | big-integer base-N |
| @base62 | URL-safe 0-9A-Za-z, plus an integer mode | big-integer base-N |
| @base64 | RFC 4648 standard +/ and URL-safe -_ | byte-oriented (3 bytes → 4 chars) |
flowchart LR
B([bytes]) --> BY["byte-oriented<br/>bit packing · RFC 4648"]
B --> IN["big-integer<br/>base-N conversion"]
BY --> b16["@base16"]
BY --> b32["@base32<br/><small>+ base32hex</small>"]
BY --> b64["@base64<br/><small>std + url-safe</small>"]
IN --> core(["@moonbase core<br/><small>any custom alphabet</small>"])
core --> b36["@base36"]
core --> b58["@base58"]
core --> b62["@base62"]moon add moonbitstack/moonbase@base16.encode(b"\x00\x0f\xff") // -> "000fff" (leading zero survives)
@base16.encode_upper(b"foobar") // -> "666F6F626172" (RFC 4648 canonical)
@base16.decode("DeAdBeEf") // -> Some(b"\xde\xad\xbe\xef")
@base16.decode("abc") // -> None (odd length)@base32.encode(b"foobar") // -> "MZXW6YTBOI======"
@base32.decode("MZXW6YTBOI") // -> Some(b"foobar") (padding optional)
@base32.encode_hex(b"foobar") // -> "CPNMUOJ1E8======"
@base32.decode_hex("CPNMUOJ1E8======") // -> Some(b"foobar")@base36.encode(b"\xde\xad\xbe\xef") // bytes -> a base36 string
@base36.decode("...") // string -> Some(bytes) / None
@base36.encode_uint(123456789) // -> "21i3v9" (== (123456789).toString(36))
@base36.decode_uint("21i3v9") // -> Some(123456789)let encoded = @base58.encode(b"Hello, MoonBit!")
let decoded = @base58.decode(encoded) // -> Some(b"Hello, MoonBit!")
@base58.decode("0OIl") // -> None (none of these are base58 characters)@base62.encode(b"\xde\xad\xbe\xef") // bytes -> a base62 string
@base62.decode("...") // string -> Some(bytes) / None
@base62.encode_uint(123456789) // -> "8M0kX"
@base62.decode_uint("8M0kX") // -> Some(123456789)@base64.encode(b"foobar") // -> "Zm9vYmFy"
@base64.encode(b"f") // -> "Zg=="
@base64.decode("Zm9vYg") // -> Some(b"foob") (padding optional)
@base64.encode_url(b"\xfb\xff\xbf") // -> "-_-_" (never + / or =)
@base64.decode_url("-_-_") // -> Some(b"\xfb\xff\xbf")let base36 = @moonbase.Alphabet::new("0123456789abcdefghijklmnopqrstuvwxyz")
@moonbase.encode(b"\xde\xad\xbe\xef", base36) // -> a base36 string
@moonbase.decode("...", base36) // -> Some(bytes) / Nonemoon testInstall
Download zipbase16/base32/base36/base58/base62/base64 for MoonBit — RFC 4648 hex/base32/base64 plus a big-integer base-N core behind base36/base58/base62.