1.0.0 • Published 9 years ago

simple-gen v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

Simple-gen

This module creates really simple high performance unique keys

npm install simple-gen

Usage:

var gen = new Generator('PREFIX')

gen.next()
// => 0xPREFIXx1421287155611x0
gen.next()
// => 0xPREFIXx1421287155611x1
gen.next()
// => 0xPREFIXx1421287155612x0

It creates the key based on a timestamp, and ensures a new one is unique by incrementing the last index if that timestamp has already been used.

If you want unique key based on the environment, you can use an environment specific ID as the prefix e.g.

var gen = new Generator('PREFIXx' + process.env.SYSTEM_NAME)

gen.next()
// => 0xPREFIXxMy-System-Namex1421287155611x0