Skip to content
/ jsid Public

You can create a TSID-like key using JavaScript. This key is generated to fit JavaScript's integer range.

License

Notifications You must be signed in to change notification settings

Barnie/jsid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSID

You can create a TSID-like key using JavaScript. This key is generated to fit JavaScript's integer range.

JSID Structure

  • Time component (42 bits) : ~ 2109-05-14
  • Node ID (5 bits) : 0 ~ 31
  • Counter (5 bits) : 0 ~ 31
|------------------------------------------|-----|-----|
       time (msecs until 2109-05-14)        node  counter
                42 bits                    5 bits  5 bits

Example

const Jsid = require('@barnie/jsid');
const jsid = new Jsid(5);        // node: 5

jsid.getInt();
// result: 1761692919744673

jsid.getBin();
// result: '0110010000100100000000011100101101011011010010100010'

About

You can create a TSID-like key using JavaScript. This key is generated to fit JavaScript's integer range.

Resources

License

Stars

Watchers

Forks

Packages

No packages published