Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

unique-identity

2.0.0 • Public • Published

unique-identity

Amazingly unique ids which are short and Perfect for url shorteners, MongoDB and Redis ids, and any other id users might see..

Features

  • Generates unique id's on multiple processes and machines even if called at the same time.
  • With the Process ID, MAC Address and the combinations of current Time the ID's are unique even if called at the same time from multiple machines and processes.

Usage

const id = require('unique-identity');
 
console.log(id.get());
// De3MOQxCZAdHpvx3pG
// Bukc9IfvI8mh10PD5G
// D1kxsCOHcwrrfEDGpG
// VzS-0jSpkgQr7AD9G

Mongoose Unique Id

_id: {
  'type': String,
  'default': id.get()
},

API

const id = require('unique-identity');

Example

users.insert({
  _id: id.get(),
  name: '...',
  email: '...'
});

You can also set your custom 64 unique characters then unique id will be generated accordingly.

Example

const id = require('unique-identity');
 
let characters='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
id.characters(characters);
 
console.log(id.characters(characters));
// { status : true }
 
console.log(id.characters('duplicate characters of string'));
// { message: 'duplicate characters found!', status: false }
 
console.log(id.characters('wrong length of string'));
// { message: 'need 64 unique characters!', status: false }

Install

npm i unique-identity

DownloadsWeekly Downloads

10

Version

2.0.0

License

ISC

Unpacked Size

5.29 kB

Total Files

6

Last publish

Collaborators

  • avatar