base32
Base32 encoding/decoding library.
Classes & types
Functions
base32.alphabet | Creates a base32 alphabet with encoding and decoding maps. |
base32.decode | Decodes the specified base32 encoded string. |
base32.encode | Encodes the specified string to base32. |
base32.validate | Checks if the specified base32 encoded string is valid. |
#base32.alphabet
function base32.alphabet(alphabet_str: string): base32.Alphabet
Creates a base32 alphabet with encoding and decoding maps.
Parameters
| Name | Type | Description |
|---|---|---|
alphabet_str | string | The alphabet string, 32 unique characters without =. |
Returns
| Type | Name | Description |
|---|---|---|
base32.Alphabet | alphabet | The alphabet. |
#base32.decode
function base32.decode(base32_str: string, ignore_padding?: boolean, alphabet?: ( "standard" | "extended" | base32.Alphabet )?): string
Decodes the specified base32 encoded string.
Throws an error if the string has invalid length, padding or characters.
Parameters
| Name | Type | Description |
|---|---|---|
base32_str | string | The base32 encoded string to decode. |
ignore_paddingoptional | boolean | Whether padding is optional. |
alphabetoptional | ( "standard" | "extended" | base32.Alphabet )? | The alphabet to use. |
Returns
| Type | Name | Description |
|---|---|---|
string | raw_str | The decoded string. |
#base32.encode
function base32.encode(raw_str: string, ignore_padding?: boolean, alphabet?: ( "standard" | "extended" | base32.Alphabet )?): string
Encodes the specified string to base32.
Parameters
| Name | Type | Description |
|---|---|---|
raw_str | string | The string to encode. |
ignore_paddingoptional | boolean | Whether to ignore padding. |
alphabetoptional | ( "standard" | "extended" | base32.Alphabet )? | The alphabet to use. |
Returns
| Type | Name | Description |
|---|---|---|
string | base32_str | The encoded string. |
#base32.validate
function base32.validate(base32_str: string, ignore_padding?: boolean, alphabet?: ( "standard" | "extended" | base32.Alphabet )?): boolean, nil | string
Checks if the specified base32 encoded string is valid.
Parameters
| Name | Type | Description |
|---|---|---|
base32_str | string | The base32 encoded string to check. |
ignore_paddingoptional | boolean | Whether padding is optional. |
alphabetoptional | ( "standard" | "extended" | base32.Alphabet )? | The alphabet to use. |
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_valid | true if the base32 string is valid, false otherwise |
nil | string | err_msg | The error message. |