Hashids – Generate short unique IDs in JavaScript and other languages

A libraries, that helps to generate short unique IDs in JavaScript (as well node.js and CoffeeScript), and many other programming languages.

Generate short unique IDs in JavaScript and not only

Hashids is a small JavaScript library to generate hash ids from one or many numbers. Hashed are similar to YouTube or bit.ly. For JS, there are a client-side and node.js versions.

Generate short unique ids from integers easily – short, unique and non-sequential.

Generate short unique IDs in JavaScript and more languages
Generate short unique IDs in JavaScript and more languages

Key features

– Create short unique ids from numbers (positive numbers and zero)

– Tiny code – fast and does not depend on external libraries

– Incremental input is mangled to stay unguessable

– Allow custom alphabet as well as salt (ids are unique only to us)

Usage

bower install hashids

Or simply:

<script type="text/javascript" src="lib/hashids.min.js"></script>

Sample code – encoding:

var Hashids = require("hashids"),
  hashids = new Hashids("this is the salt");

var id = hashids.encode(12345);
// => NkK9

Sample code – decoding:

var Hashids = require("hashids"),
  hashids = new Hashids("this is the salt");

var numbers = hashids.decode("NkK9");
// => 12345

License: MIT

Demo:

codepen.io

Project homepage:

http://hashids.org/javascript

Get the library to generate short unique IDs from GitHub:

https://github.com/ivanakimov/hashids.js

See also:

Create GUID / UUID in JavaScript? (Stackoverflow topic)

JavaScript Barcode Generator (JsBarcode)

jQuery password generator with strength meter – the pwdMeter

JavaScript physics animations library – dynamics.js

Enjoy!

Share:Share on Facebook1Share on Google+0Tweet about this on TwitterShare on LinkedIn1Pin on Pinterest1