1.0.0 • Published 5 years ago

tsuid v1.0.0

Weekly downloads
5
License
Apache-2.0
Repository
github
Last release
5 years ago

tsuid

Time Series Unique ID

Generates 8-byte UUID that consists of:

  • 41 bits for time in milliseconds (we can use it until 2084/09/06 lunch time comes)
  • 13 bits for additional information - Can be used it to store the logical shard ID
  • 10 bits that represent an auto-incrementing sequence.

Installation

$ npm install --save tsuid

Examples

const tsuid = require('tsuid');

tsuid();            // Default: Base64 - "D6zWpFyMJGc"
tsuid("hex");       // Hex String      - "facd6acec2ff868"
tsuid("decimal");   // Decimal String  - "1129513692534654057"

Documentation

tsuid(options)

Generates and returns UUID.

  • options (object || string): Generating options. (or return type)
OptionDescriptionRangeDefault
typeReturn type of generated ID. See below for more details.-'base64'
additionalAdditional Unique Information (ex: Logical Shard ID)0 ~ 8191(Random)
counterAuto-incrementing sequence - to prevent conflicting0 ~ 1023(Random)
Return types
NameDescriptionType
base64Base64 Hash (Note that this is not pure Base64. We uses URL-Safe Base64URL)String
decimalDecimal StringString
number(Same as above)-
hexHex StringString
hash(Same as above)-
longLong objectLong

License: Apache-2.0

Author: shixiongfei