Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
**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)
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
Install Hashids via:
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:
var Hashids = require('hashids-bn');
var hashids = new Hashids();
console.log(hashids.encode(1));
var hashids = new Hashids();
var id = hashids.encode(1, 2, 3); // o2fXhV
var numbers = hashids.decode(id); // [1, 2, 3]
A few more ways to pass to encode()
:
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:
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.
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:
var hashids = new Hashids('', 0, 'abcdefghijklmnopqrstuvwxyz'); // all lowercase
console.log(hashids.encode(1, 2, 3)); // mdfphx
Default alphabet is abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
.
When decoding, output is always an array of numbers (even if you encode only one number):
var hashids = new Hashids();
var id = hashids.encode(1);
console.log(hashids.decode(id)); // [1]
Encoding negative numbers is not supported.
If you pass bogus input to encode()
, a TypeError is raised:
var hashids = new Hashids();
var id = hashids.encode('123a'); // TypeError
Do not use this library as a security tool and do not encode sensitive data. This is not an encryption library.
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:
var hashids = new Hashids();
console.log(hashids.encode(5, 5, 5)); // A6t1tQ
Same with incremented numbers:
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
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
MIT
FAQs
**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)
The npm package hashids-bn receives a total of 10 weekly downloads. As such, hashids-bn popularity was classified as not popular.
We found that hashids-bn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.