Press "Enter" to skip to content

JavaScript Library to Generate YouTube-Like ids From Numbers | Hashids

Hashids is a small JavaScript library for creating YouTube-like IDs from numbers. Use it when you don’t want to view your database IDs to the user.

How to make use of it:

Install the Hashids package.

# NPM
$ npm install hashids --save

Import the Hashids module.

import Hashids from './lib/hashids.js'

Initialize the Hashids.

var myHashId = new Hashids();

Encode a number or hex.

// Mj3
hashids.encode(123);

// LPj9LA
hashids.encodeHex('fafafa');

Decode the generated IDs.

hashids.decode(id);
hashids.decodeHex(id);

Config the library bypassing the next parameters:

// Hashids(salt, minLength, alphabet)
var myHashId = new Hashids(0, 5, 'abc');

Check if is legitimate.

hashids.isValidId(id);

Generate Unique IDs Like Youtube, Hashids Plugin/Github


See Demo And Download

Official Website(niieani): Click Here

This superior jQuery/javascript plugin is developed by niieani. For extra Advanced Usages, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published.