npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unique-identity

v2.3.5

Published

Amazingly unique ids which are short and Perfect for Url Shorteners, Product SKUs, Socket Ids, Data Base Ids, SQL, MongoDB, PostGres, MySQL, MSSQL, Redis ids, and any other id users might see...

Downloads

20

Readme

unique-identity

Amazingly unique ids which are short and Perfect for Url Shorteners, Product SKUs, Socket Ids, Data Base Ids, SQL, MongoDB, PostGres, MySQL, MSSQL, Redis ids, Front-End Temp 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.
  • Set Pre-Fix in unique IDs.
  • Set Post-Fix in unique IDs.
  • Now With Typescript Support 🥳

  • Now any typescript based Environment can easily use unique-identity 🤩

Usage

//JavaScript
const id = require('unique-identity');
//Or
const { characters, get, setPostfix, setPrefix } = require('unique-identity');


console.log(id.get());
// De3MOQxCZAdHpvx3pG
// Bukc9IfvI8mh10PD5G
// D1kxsCOHcwrrfEDGpG
// VzS-0jSpkgQr7AD9G
//TypeScript
import { characters, get, setPostfix, setPrefix } from 'unique-identity';
//Or
import * as id from 'unique-identity';
//Or
import id from 'unique-identity';

console.log(id.get());
// De3MOQxCZAdHpvx3pG
// Bukc9IfvI8mh10PD5G
// D1kxsCOHcwrrfEDGpG
// VzS-0jSpkgQr7AD9G

Mongoose Unique Id

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

API

//JavaScript
const id = require('unique-identity');
//Or
const { characters, get, setPostfix, setPrefix } = require('unique-identity');

//TypeScript
import { characters, get, setPostfix, setPrefix } from 'unique-identity';
//Or
import * as id from 'unique-identity';
//Or
import id from '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


//JavaScript
const id = require('unique-identity');
//Or
const { characters, get, setPostfix, setPrefix } = require('unique-identity');

//TypeScript
import { characters, get, setPostfix, setPrefix } from 'unique-identity';
//Or
import * as id from 'unique-identity';
//Or
import id from '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 }

You can also set the Pre-Fix and Post-Fix characters too and the unique id will be generated accordingly.

Example

//JavaScript
const id = require('unique-identity');
//Or
const { characters, get, setPostfix, setPrefix } = require('unique-identity');

//TypeScript
import { characters, get, setPostfix, setPrefix } from 'unique-identity';
//Or
import * as id from 'unique-identity';
//Or
import id from 'unique-identity';

// To Set Pre-Fix

id.setPrefix(inputString);

console.log(id.setPrefix(inputString));
// { status : true }

console.log(id.setPrefix(/*invalid type input*/));
// { message: 'Invalid input type, Required string.', status: false }

console.log(id.setPrefix(/*input string length more than 50 chars*/));
// { message: 'Max chars limit is 50.', status: false }


// To Set Post-Fix

id.setPostfix(inputString);

console.log(id.setPostfix(inputString));
// { status : true }

console.log(id.setPostfix(/*invalid type input*/));
// { message: 'Invalid input type, Required string.', status: false }

console.log(id.setPostfix(/*input string length more than 50 chars*/));
// { message: 'Max chars limit is 50.', status: false }

Pre-Fix & Post-Fix Examples


//Pre-Fix

id.setPrefix('SKU_');
console.log(id.get());
// SKU_De3MOQxCZAdHpvx3pG
// SKU_Bukc9IfvI8mh10PD5G
// SKU_D1kxsCOHcwrrfEDGpG


//Post-Fix

id.setPostfix('_postFix');
console.log(id.get());
// De3MOQxCZAdHpvx3pG_postFix
// Bukc9IfvI8mh10PD5G_postFix
// D1kxsCOHcwrrfEDGpG_postFix


//For Both
id.setPrefix('SKU_');
id.setPostfix('_postFix');

console.log(id.get());
// SKU_De3MOQxCZAdHpvx3pG_postFix
// SKU_Bukc9IfvI8mh10PD5G_postFix
// SKU_D1kxsCOHcwrrfEDGpG_postFix

//To Unset the Pre-Fix or Post-Fix

id.setPrefix('');// it will unset prefix
id.setPostfix('');// it will unset postfix