3.0.0 • Published 6 years ago

iguid v3.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

IGUID

Incremental Global Unique Identifier

Installation

$ npm i iguid

Usage

const uid = require('iguid');

uid(); // 1530430595960
uid(); // 1530430595961
uid(); // 1530430595962


console.log(
  [...new Array(100)].map(() => ({ id: uid()}))
)

// [
//   { id: '1530430595963' },
//   { id: '1530430595964' },
//   .....
// ]

Customized Instance

By default iguid uses the the timestamp when the process was started as prefix. This is used to achieve some level of uniqueness when called from multiple node instances.

However you can spin-off a new instance of the generator passing a custom prefix.

const uid = require('iguid').newUp('c')

console.log(uid()) // c0
console.log(uid()) // c1
console.log(uid()) // c2
console.log(uid()) // c3

Pass a falsey value to remove prefix altogether

const uid = require('iguid').newUp(null)

console.log(uid()) // 0
console.log(uid()) // 1

NOTE:

Nothing really!

That's all folks :)

Credits

3.0.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago