module Base62

Overview

Converts between integers/bytes and an alphanumeric encoding.

Default base62 alphabet (Base62::CHARSET_DEFAULT) consists of the Arabic numerals, followed by the English capital letters and the English lowercase letters.

Extended Modules

Defined in:

base62.cr

Constant Summary

CHARSET_DEFAULT = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Default character set ([0-9A-Za-z]).

CHARSET_INVERTED = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Inverted character set ([0-9a-zA-Z]).

Instance Method Summary

Instance Method Detail

def compatible?(string : String, charset = CHARSET_DEFAULT) : Bool #

Checks whether a string is base62-compatible.

Base62.compatible?("15Ew2nYeRDscBipuJicYjl970D1") # => true

[View source]
def decode(string : String, charset = CHARSET_DEFAULT) : BigInt #

Returns the base62-decoded version of string as a BigInt.

Base62.decode("0000000000000000000001LY7VK") # => 1234567890

[View source]
def encode(number : Int, charset = CHARSET_DEFAULT) : String #

Returns the base62-encoded version of number as a String.

Base62.encode(1_234_567_890) # => "1LY7VK"

[View source]
def encode(value : String | Bytes, charset = CHARSET_DEFAULT) : String #

Returns the base62-encoded version of value as a String.

Base62.encode("\xFF" * 4)           # => "4gfFC3"
Base62.encode(Bytes.new(4, 255_u8)) # => "4gfFC3"

[View source]