Documentation
¶
Overview ¶
Package base62 is a standard-library-only Go implementation of Base62 encoding, the alphanumeric (0-9, A-Z, a-z) binary-to-text scheme used by URL shorteners and short-id generators across the npm ecosystem (base62, base-x). Because the alphabet contains only characters that are safe in URLs and identifiers, Base62 is a common choice for compact, human-friendly tokens.
Encode and Decode convert between arbitrary byte slices and Base62 strings, preserving leading zero bytes as leading '0' characters. EncodeInt and DecodeInt convert unsigned 64-bit integers, the form most short-id schemes use. Decode and DecodeInt return ErrInvalidCharacter for input outside the alphabet. The implementation uses math/big for the base conversion, is deterministic, and depends only on the standard library.
Index ¶
Constants ¶
const Alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Alphabet is the standard Base62 alphabet: digits, then uppercase, then lowercase letters.
Variables ¶
var ErrInvalidCharacter = errors.New("base62: invalid character")
ErrInvalidCharacter is returned when decoding input containing a character outside the Base62 alphabet.
Functions ¶
func Decode ¶
Decode returns the bytes represented by the Base62-encoded string s. Leading '0' characters decode to leading zero bytes. It returns ErrInvalidCharacter for any character outside the alphabet.
func DecodeInt ¶
DecodeInt returns the unsigned integer represented by the Base62 string s. It returns ErrInvalidCharacter for input outside the alphabet.
Types ¶
This section is empty.