3 ms·
Another option is to generate a ULID and just take the timestamp part (6 bytes, I forget how many characters). Uses Crockford Base32 already so no need for the
by kortex 4y ago
Another option is to generate a ULID and just take the timestamp part (6 bytes, I forget how many characters). Uses Crockford Base32 already so no need for the custom alphabet.
- dahfizz 4y agoThat is definitely taking the long way around.... Why not just grab a timestamp and base32 it yourself? ULIDs also use millisecond timestamps, and use implementation magic to sort IDs within a millisecond. If you are just using the timestamp portion, you should use micro or nanoseconds.
- kortex 4y agoWell yeah that's kind of what I mean. On some libraries you can generate and encode just the timestamp part.
- dahfizz 4y agoIts literally one line of code, let slug = base32Encode( window.performance.now() ) Maybe 15 LoC if you don't want to import a b32 encoder. Hardly seems worth a dependency.