# hashids-bn

> **Hashids-bn** is small JavaScript library to generate YouTube-like ids from numbers. This fork uses BigNumber so that number isn't limited. [http://hashids.org/javascript](http://hashids.org/javascript)

Latest version **1.0.2** (published 2019-08-26) · ISC license · 0 weekly downloads

## Install

```sh
npm install hashids-bn
pnpm add hashids-bn
yarn add hashids-bn
bun add hashids-bn
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-08-26 |
| First published | 2019-08-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 34.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | nonamesheep |
| Keywords | hashids, hashid, hash, encode, decode, BigInt, big-number |

## Links

- npm: https://www.npmjs.com/package/hashids-bn
- Repository: https://github.com/AminoApps/hashids-bn
- Homepage: https://github.com/AminoApps/hashids-bn#readme
- Issues: https://github.com/AminoApps/hashids-bn/issues
- npm.io page: https://npm.io/package/hashids-bn

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

- 1.0.2 (latest) — 2019-08-26
- 1.0.1 — 2019-08-26
- 1.0.0 — 2019-08-26

## README

**hashids-bn** is small JavaScript library to generate YouTube-like ids from numbers. This fork uses BigNumber so that number isn't limited.
[http://hashids.org/javascript](http://hashids.org/javascript)

Getting started
-------

Install Hashids via:

- [node.js](https://nodejs.org): `npm install --save hashids-bn`


This fork is only intended to use in nodejs server (> 10), but modern browser should also work.

Use in Node.js:

```javascript
var Hashids = require('hashids-bn');
var hashids = new Hashids();

console.log(hashids.encode(1));
```

Quick example
-------

```javascript
var hashids = new Hashids();

var id = hashids.encode(1, 2, 3); // o2fXhV
var numbers = hashids.decode(id); // [1, 2, 3]
```

More options
-------

**A few more ways to pass to `encode()`:**

```javascript
var hashids = new Hashids();

console.log(hashids.encode(1, 2, 3)); // o2fXhV
```

**Make your ids unique:**

Pass a project name to make your ids unique:

```javascript
var hashids = new Hashids('My Project');
console.log(hashids.encode(1, 2, 3)); // Z4UrtW

var hashids = new Hashids('My Other Project');
console.log(hashids.encode(1, 2, 3)); // gPUasb
```

**Use padding to make your ids longer:**

Note that ids are only padded to fit **at least** a certain length. It doesn't mean that your ids will be *exactly* that length.

```javascript
var hashids = new Hashids(); // no padding
console.log(hashids.encode(1)); // jR

var hashids = new Hashids('', 10); // pad to length 10
console.log(hashids.encode(1)); // VolejRejNm
```

**Pass a custom alphabet:**

```javascript
var hashids = new Hashids('', 0, 'abcdefghijklmnopqrstuvwxyz'); // all lowercase
console.log(hashids.encode(1, 2, 3)); // mdfphx
```

Default alphabet is `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`.


Pitfalls
-------

1. When decoding, output is always an array of numbers (even if you encode only one number):

	```javascript
	var hashids = new Hashids();

	var id = hashids.encode(1);
	console.log(hashids.decode(id)); // [1]
	```

2. Encoding negative numbers is not supported.
3. If you pass bogus input to `encode()`, a TypeError is raised:

	```javascript
	var hashids = new Hashids();

	var id = hashids.encode('123a'); // TypeError
	```

4. Do not use this library as a security tool and do not encode sensitive data. This is **not** an encryption library.

Randomness
-------

The primary purpose of Hashids is to obfuscate ids. It's not meant or tested to be used as a security or compression tool. Having said that, this algorithm does try to make these ids random and unpredictable:

No repeating patterns showing there are 3 identical numbers in the id:

```javascript
var hashids = new Hashids();
console.log(hashids.encode(5, 5, 5)); // A6t1tQ
```

Same with incremented numbers:

```javascript
var hashids = new Hashids();

console.log(hashids.encode(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); // wpfLh9iwsqt0uyCEFjHM

console.log(hashids.encode(1)); // jR
console.log(hashids.encode(2)); // k5
console.log(hashids.encode(3)); // l5
console.log(hashids.encode(4)); // mO
console.log(hashids.encode(5)); // nR
```

Curses! #$%@
-------

This code was written with the intent of placing created ids in visible places, like the URL. Therefore, the algorithm tries to avoid generating most common English curse words by generating ids that never have the following letters next to each other:

	c, f, h, i, s, t, u

License
-------

MIT

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