Generate random time-based, collision-proof IDs a la Firebase.push
. Designed for testing and education (readability), not performance.
$ npm install firebase-auto-ids
firebase-auto-ids exports a function. Pass in now
, the current timestamp (e.g. Date.now()
). generate
returns an ID string. Like Firebase.push
, IDs hold the following properties:
id1
<id2
whereid1
was created at an earlier time (now
) thanid2
id1
<id2
whereid1
andid2
were created at the samenow
butgenerateAutoId
was executed forid1
beforeid2
id1
!==id2
whereid1
andid2
were created at the samenow
in different clients
Creates a new generator
instance. Individual instances do not share state. This means that IDs created at the same time in a given runtime will no longer be determined by call order.
Same as generate(now)