base62

Arbitrary base encoding-decoding functions, defaulting to Base-62.

Abandoned Pure Nim score 15/100 · tests present · no docs generated

Summary

Latest Version Unknown
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install base62
choosenim install base62
git clone https://github.com/singularperturbation/base62-encode

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
base62 - - - - - - -

README

Base 62 encoder-decoder

Summary

This is an encoder/decoder that accepts an arbitrary "alphabet" as a string to use for encoding integers and for decoding them. It defaults to an alphabet of 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ (and a base62 encoding).

The decoder does a simple check for validity (characters not in the set of characters in the input alphabet), and returns -1 for an invalid string.

The primary use-case (my own itch that is being scratched) is shortening integers to URL-friendly strings.

Using

If you don't specify an input alphabet, we will use the default to make a base62 encoder/decoder funciton tuple - if an alphabet is supplied, then the encoder and decoder uses that.

Example:

from base62 import nil
# Suppose you want a really bad binary encoder - with GenerateFunctionPair we
# have an encoder and decoder using the input alphabet.
let
  (encode,decode) = base62.GenerateFunctionPair("01")

echo encode(32)
echo decode("100000")

Testing

Compile as own module - has a built in unit test for base62 that should run and assert expected results are equal to runtime results.