JSPM

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

Arbitrary base-n conversions w/ presets for base8/16/32/36/58/62/64/83/85, support for bigints and encoding/decoding of byte arrays

Package Exports

  • @thi.ng/base-n
  • @thi.ng/base-n/10
  • @thi.ng/base-n/16
  • @thi.ng/base-n/26
  • @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/83
  • @thi.ng/base-n/85
  • @thi.ng/base-n/api
  • @thi.ng/base-n/base
  • @thi.ng/base-n/chars/10
  • @thi.ng/base-n/chars/16
  • @thi.ng/base-n/chars/26
  • @thi.ng/base-n/chars/32
  • @thi.ng/base-n/chars/36
  • @thi.ng/base-n/chars/58
  • @thi.ng/base-n/chars/62
  • @thi.ng/base-n/chars/64
  • @thi.ng/base-n/chars/83
  • @thi.ng/base-n/chars/85
  • @thi.ng/base-n/decode
  • @thi.ng/base-n/encode

Readme

[!IMPORTANT] ‼️ Announcing the thi.ng user survey 2024 📋

Please participate in the survey here!
(open until end of February)

To achieve a better sample size, I'd highly appreciate if you could circulate the link to this survey in your own networks.

Discussion

@thi.ng/base-n

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 190 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Arbitrary base-n conversions w/ presets for base8/16/32/36/58/62/64/83/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.

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:

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

Package sizes (brotli'd, pre-treeshake): ESM: 1.24 KB

Dependencies

None

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

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 - 2024 Karsten Schmidt // Apache License 2.0