kuid
TypeScript icon, indicating that this package has built-in type declarations

2.1.4 • Public • Published

kuid

Travis-CI

Collision-resistant ids optimized for horizontal scaling and binary search lookup performance.

Currently available for Node, browsers, Ruby, .Net, Go, PHP and Elixir (see ports below -- more ports are welcome).

kuid() returns a short random string with some collision-busting measures. Safe to use as HTML element ID's, and unique server-side record lookups.

Example

ESM:

import kuid from 'kuid';
 
kuid.initPrefix('yo')
console.log( kuid() );
 
// yojld2cjxh0000qzrmn831i7rn

Node style:

var kuid = require('kuid');
console.log( kuid() );
 
// kjld2cyuq0000t3rmniod1foy

Installing

$ npm install --save kuid

Broken down

** c - h72gsb32 - 0000 - udoc - l363eofy **

The groups, in order, are:

  • 'prefix' - identifies this as a kuid, and allows you to use it in html entity ids.
  • Timestamp
  • Counter - a single process might generate the same random string. The weaker the pseudo-random source, the higher the probability. That problem gets worse as processors get faster. The counter will roll over if the value gets too big.
  • Client fingerprint
  • Random (using cryptographically secure libraries where available).

Package Sidebar

Install

npm i kuid

Weekly Downloads

173

Version

2.1.4

License

MIT

Unpacked Size

17.5 kB

Total Files

19

Last publish

Collaborators

  • dakshmiglani