This project is part of the @thi.ng/umbrella monorepo.
Arbitrary base-n conversions w/ presets for base8/16/32/36/58/62/64/85, support for bigints and encoding/decoding of byte arrays.
In addition to the actual converters/encoders, the package also provides the plain character strings for each base and variations.
STABLE - used in production
Search or submit any issues for this package
yarn add @thi.ng/base-n
ES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/base-n"></script>
For Node.js REPL:
const baseN = await import("@thi.ng/base-n");
Package sizes (brotli'd, pre-treeshake): ESM: 931 bytes
import { BASE85, defBase } from "@thi.ng/base-n";
BASE85.encodeBigInt(2n ** 128n - 1);
// '=r54lj&NUUO~Hi%c2ym0'
BASE85.decodeBigInt("=r54lj&NUUO~Hi%c2ym0").toString(16);
// 'ffffffffffffffffffffffffffffffff'
// define a custom base impl
const ternary = defBase("012");
ternary.encode(12345678)
// '212020020002100'
ternary.decode("212020020002100");
// 12345678
If this project contributes to an academic publication, please cite it as:
@misc{thing-base-n,
title = "@thi.ng/base-n",
author = "Karsten Schmidt",
note = "https://thi.ng/base-n",
year = 2017
}
© 2017 - 2023 Karsten Schmidt // Apache License 2.0