# baseint

> Encode and decode in any base, supports BigInt

Latest version **0.1.0** (published 2024-03-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install baseint
pnpm add baseint
yarn add baseint
bun add baseint
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2024-03-11 |
| First published | 2024-03-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Eugene Song |
| Maintainers | tilleps |
| Keywords | base62, base58, base36, base32, encoding, decoding, shortner |

## Links

- npm: https://www.npmjs.com/package/baseint
- Repository: https://github.com/tilleps/base-int
- Homepage: https://github.com/tilleps/base-int#readme
- Issues: https://github.com/tilleps/base-int/issues
- npm.io page: https://npm.io/package/baseint

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2024-03-11

## README

# BaseInt

Encode and decode strings to a custom base

Inspired by / derivative of [base62.js](https://github.com/base62/base62.js) and [Base-x](https://github.com/cryptocoinjs/base-x)

**WARNING:** This module is **NOT [RFC4648](https://datatracker.ietf.org/doc/html/rfc4648#page-10)
compliant** (formerly [RFC3548](https://datatracker.ietf.org/doc/html/rfc3548)).  Meaning base64 
and base64url will not encode/decode the same as `btoa()` and `atob()` or any of the native encodings 
(base16, base32)

## Installation

```sh
npm install baseint
```


## Usage

```js
import BaseInt, {
  BASE64URL,
  BASE64,
  BASE62,
  BASE32,
  BASE32HEX,
  BASE16
} from "baseint";

// Supply which base you want to use (BASE62 is default)
const baseInt = new BaseInt(BASE62);

// Or supply your own base
const charset = "abcd1234";
const baseInt = new BaseInt(charset);

const encoded = baseInt.encode(numstr);
const decoded = baseInt.decode(encoded);
```


### UUID Example

```js
const baseInt = new BaseInt();

const uuid = "b9b03417-a52a-47cf-8638-3c26b2628c98";

//  Convert uuid to bigint/number/numeric string
const bn = BigInt("0x" + uuid.replace(/-/g, ""));

const encoded = baseInt.encode(bn);
// FoYGiVxbLcGdqtB3H0Qzbi

//  Or encode directly
const encoded = baseInt.encodeUUID(uuid);
// FoYGiVxbLcGdqtB3H0Qzbi

const decoded = baseInt.decodeToUUID(encoded);
// b9b03417-a52a-47cf-8638-3c26b2628c98
```


## Predefined Bases / Character Sets

| Base        | Characters                                                           |
| ----------- | -------------------------------------------------------------------- |
| BASE64URL   | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`   |
| BASE64      | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`   |
| BASE62      | `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`     |
| BASE36      | `0123456789abcdefghijklmnopqrstuvwxyz`                               |
| BASE32Z     | `ybndrfg8ejkmcpqxot1uwisza345h769`                                   |
| BASE32HEX   | `0123456789ABCDEFGHIJKLMNOPQRSTUV`                                   |
| BASE32      | `ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`                                   |
| BASE16      | `0123456789ABCDEF`                                                   |
| BASE8       | `01234567`                                                           |
| BASE2       | `01`                                                                 |



## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/baseint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
