r/webdev • u/TheWebDever • Oct 03 '26
Showoff Saturday jet-id: Unique ID generator with id lengths based on the entropy you ask for
jet-id is an open source universal unique-ID generator I built similar to nanoid or uuid. Unlike other unique-id generators, you can specify how many random bits (entropy) you want, and it creates the shortest id string that provides at least that much entropy using the Crockford alphabet, with dashes automatically inserted for readability. Dash inserting makes sure that no segment grows greater than 10 characters.
125 bits of entropy is the default and it works both CLI and programmatically:
npx jet-id -e 80
# V2BJABVRJ-S1TWXS-NTQA3 (20 random characters, 22 with the dashes)
npx jet-id
# 9GNK14S3A-728HK9-5NJQS-HWETM (25 random characters, 28 with the dashes)It also supports timestamped-IDs and monotonic-IDs (monotonic ids sort in creation order within a single millisecond).
import jetid from 'jet-id'
jetid.timed() // '1M41J22ER-RND9M6-3CZAQ-XT8GR'
jetid.mono(125?) // '1M41J2ZPK-8K0000-GE29AYBQ27-4496ZM40-29JSNX4'jet-id is really fast too. Check out these benchmarks
It's available right now on npm: https://www.npmjs.com/package/jet-id
Direct readme link: https://github.com/seanpmaxwell/jet-id#readme
Feedback, suggestions, and constructive criticism are very welcome (so are Github stars ⭐)
Feel free to reach out to me on GitHub or Reddit
2
u/untrochka Oct 03 '26
The entropy-first API is a useful idea. A small table in the README mapping requested bits to character count and approximate collision risk at, say, 1 million generated IDs would help people choose a value without guessing. I would also distinguish random IDs from the timestamped/monotonic modes in that guidance, since their ordering and predictability tradeoffs differ.
1
u/armastevs Oct 03 '26
Small question about the
-e 80example: Crockford base32 packs 5 bits per character, so 16 characters can hold 80 bits before adding dashes. The example shows 20 random characters. Is there a minimum length or rounding rule, or is that just an example typo? Worth clarifying since choosing the shortest length for a given entropy is the main feature.1
u/Any-Ask-4131 Oct 03 '26
For the monotonic mode, what happens if the clock moves backwards, or two processes generate IDs in the same millisecond? Worth spelling out whether the ordering guarantee is per process or across instances.
3
u/[deleted] Oct 03 '26
[removed] — view removed comment