https://github.com/bendrucker/firebase-auto-ids
Generate random time-based IDs like Firebase
https://github.com/bendrucker/firebase-auto-ids
Last synced: over 1 year ago
JSON representation
Generate random time-based IDs like Firebase
- Host: GitHub
- URL: https://github.com/bendrucker/firebase-auto-ids
- Owner: bendrucker
- License: mit
- Created: 2015-02-23T23:17:10.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-08-04T12:55:57.000Z (almost 7 years ago)
- Last Synced: 2025-04-15T00:02:38.569Z (over 1 year ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# firebase-auto-ids [](https://travis-ci.org/bendrucker/firebase-auto-ids) [](https://greenkeeper.io/)
Generate random time-based, collision-proof IDs a la [`Firebase.push`](https://www.firebase.com/docs/web/api/firebase/push.html). Designed for testing and education (readability), not performance.
## Installing
```sh
$ npm install firebase-auto-ids
```
## API
##### `generate(now)` -> `String`
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` where `id1` was created at an earlier time (`now`) than `id2`
* `id1` < `id2` where `id1` and `id2` were created at the same `now` but `generateAutoId` was executed for `id1` before `id2`
* `id1` !== `id2` where `id1` and `id2` were created at the same `now` in different clients
##### `new generate.Generator()` -> `generator`
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.
##### `generator.generate(now)` -> `String`
Same as [`generate(now)`](#generatenow---string)