# base62

> JavaScript Base62 encode/decoder

Latest version **2.0.2** (published 2024-04-02) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2024-04-02 |
| First published | 2012-02-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 25.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Andrew Nesbitt |
| Maintainers | andrewnez, fnd |
| Keywords | base-62, encoder, decoder |

## Links

- npm: https://www.npmjs.com/package/base62
- Repository: https://github.com/base62/base62.js
- Issues: https://github.com/base62/base62.js/issues
- Funding: https://github.com/sponsors/andrew
- npm.io page: https://npm.io/package/base62

## 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

- 2.0.2 (latest) — 2024-04-02
- 2.0.1 — 2019-03-06
- 2.0.0 — 2018-04-13
- 1.2.8 — 2018-03-30
- 1.2.7 — 2018-02-14
- 1.2.6 — 2018-02-14
- 1.2.5 — 2018-02-10
- 1.2.4 — 2018-02-10
- 1.2.1 — 2017-11-14
- 1.2.0 — 2017-05-15
- 1.1.2 — 2016-11-14
- 1.1.1 — 2016-04-14
- 1.1.0 — 2015-02-23
- 1.0.0 — 2014-10-11
- 0.1.2 — 2014-07-15
- … 2 more at https://npm.io/package/base62/versions

## README

# Base62.js
[![npm version](https://badge.fury.io/js/base62.svg)](http://badge.fury.io/js/base62)
[![CI](https://github.com/base62/base62.js/actions/workflows/ci.yml/badge.svg)](https://github.com/base62/base62.js/actions/workflows/ci.yml)
[![npm downloads](https://img.shields.io/npm/dm/base62.svg)](https://www.npmjs.com/package/base62)
[![license](https://img.shields.io/npm/l/base62.svg)](https://github.com/base62/base62.js/blob/master/LICENSE)

A JavaScript Base62 encode/decoder.

Base62 encoding converts numbers to ASCII strings (0-9, a-z and A-Z) and vice
versa, which typically results in comparatively short strings. Such identifiers
also tend to be more readily identifiable by humans.

* `999` -> `"g7"`
* `9999` -> `"2Bh"`
* `238327` -> `"ZZZ"`


## Installation

```shell
npm install base62
```


## Usage

```javascript
var base62 = require("base62");

base62.encode(999);  // "g7"
base62.decode("g7"); // 999
```

Both `encode` and `decode` support BigInt for values beyond `Number.MAX_SAFE_INTEGER`:

```javascript
base62.encode(9007199254740993n);                // "FfGNdXsE9"
base62.decode("FfGNdXsE9", { bigint: true });    // 9007199254740993n
```

You can also use a custom character set:

```javascript
var base62 = require("base62");

base62.setCharacterSet("~9876543210ABCDEFGHIJKLMNOPQRSTU$#@%!abcdefghijklmnopqrstuvw-=");

base62.encode(999);  // "F3"
base62.decode("F3"); // 999
```

`setCharacterSet` expects a string containing exactly 62 unique characters.


## Development

Source code is hosted on [GitHub](http://github.com/base62/base62.js).
Please report issues or feature requests in
[GitHub Issues](https://github.com/base62/base62.js/issues).

 * Fork the project.
 * Make your feature addition or bug fix.
 * Add tests for it.
 * Send a pull request.


## License

MIT. Copyright (c) 2026 Andrew Nesbitt. See [LICENSE](https://github.com/base62/base62.js/blob/master/LICENSE) for details.

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