JSPM

  • Created
  • Published
  • Downloads 1367
  • Score
    100M100P100Q115282F
  • License Apache-2.0

Arbitrary base-n conversions w/ presets for base16/32/36/58/62/64/85, support for arrays & bigints

Package Exports

  • @thi.ng/base-n
  • @thi.ng/base-n/16
  • @thi.ng/base-n/32
  • @thi.ng/base-n/36
  • @thi.ng/base-n/58
  • @thi.ng/base-n/62
  • @thi.ng/base-n/64
  • @thi.ng/base-n/8
  • @thi.ng/base-n/85
  • @thi.ng/base-n/api
  • @thi.ng/base-n/base

Readme

base-n

npm version npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

Arbitrary base-n conversions w/ presets for base16/32/36/58/62/64/85, support for arrays & bigints.

Status

STABLE - used in production

Search or submit any issues for this package

Installation

yarn add @thi.ng/base-n

ES module import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/base-n"></script>

Skypack documentation

For Node.js REPL:

# with flag only for < v16
node --experimental-repl-await

> const baseN = await import("@thi.ng/base-n");

Package sizes (gzipped, pre-treeshake): ESM: 916 bytes

Dependencies

API

Generated API docs

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

Authors

Karsten Schmidt

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
}

License

© 2017 - 2022 Karsten Schmidt // Apache Software License 2.0