yabase/intid

Integer helpers for short URL-safe identifiers.

The byte-oriented codecs in yabase/facade are the right tool when the input is opaque bytes (hashes, public keys, raw payloads). For the very common short-ID case — DB autoincrement ids, sequence numbers, hash truncations — callers want Int -> compact string directly. Without these helpers every project re-implements the same Int -> big-endian bytes -> trim-leading-zero shim.

encode_int_* emits canonical form: no leading zero characters beyond what the value itself requires (encode_int_base58(0) == "1", the alphabet’s zero character; encode_int_base58(58) == "21", no leading "1").

decode_int_* is tolerant of leading zero characters (decode_int_base58("0042") and decode_int_base58("42") both return the same Int), so input from external sources that zero-pads is accepted without ceremony.

Negative inputs are normalized to int.absolute_value before encoding — the magnitude is what gets stored. The decode side always returns a non-negative Int.

Values

pub fn decode_int_base32_crockford(
  input: String,
) -> Result(Int, encoding.CodecError)

Decode a Crockford Base32 string back to an Int.

pub fn decode_int_base32_rfc4648(
  input: String,
) -> Result(Int, encoding.CodecError)

Decode a Base32 (RFC 4648) string back to an Int.

pub fn decode_int_base36(
  input: String,
) -> Result(Int, encoding.CodecError)

Decode a Base36 string back to an Int.

pub fn decode_int_base58(
  input: String,
) -> Result(Int, encoding.CodecError)

Decode a Base58 (Bitcoin alphabet) string back to an Int.

pub fn decode_int_base58_flickr(
  input: String,
) -> Result(Int, encoding.CodecError)

Decode a Base58 (Flickr alphabet) string back to an Int.

pub fn decode_int_base62(
  input: String,
) -> Result(Int, encoding.CodecError)

Decode a Base62 string back to an Int.

pub fn encode_int_base32_crockford(value: Int) -> String

Encode a non-negative Int as a Crockford Base32 string.

pub fn encode_int_base32_rfc4648(value: Int) -> String

Encode a non-negative Int as a Base32 (RFC 4648) string.

pub fn encode_int_base36(value: Int) -> String

Encode a non-negative Int as a Base36 string.

pub fn encode_int_base58(value: Int) -> String

Encode a non-negative Int as a Base58 (Bitcoin alphabet) string.

pub fn encode_int_base58_flickr(value: Int) -> String

Encode a non-negative Int as a Base58 (Flickr alphabet) string.

pub fn encode_int_base62(value: Int) -> String

Encode a non-negative Int as a Base62 string.

Search Document