@the-minimal/id
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

Id image

Highlights

  • Small (~ 700 bytes)
  • Low runtime overhead
  • Cryptographically correct random
  • Multiple entropy sources
    • Fingerprint
    • Counter
      • Random start value
      • Maximum of 4_294_967_295 values
    • Timestamp
      • 64 byte timestamp with millisecond precision
    • Salt
      • 52 bytes of random 8-bit values
    • External data
      • Data not provided
        • 32 bytes of random 8-bit values
      • Data is provided
        • Hashed using SHA-512
        • Random 32 byte slice
  • Variable length
    • Entropy sources are saved into 128 byte array
    • The byte array is hashed using SHA-512
    • The hash is converted into Base36 string
    • The Base36 string is randomly sliced into desired length
    • Default length is 24
  • Collision-resistant
    • 5.58e18 until 50% chance of collision
  • Uniform and URL-friendly output
    • ~0.005% character variance
  • Async / Non-blocking
  • 100% test coverage

API

init

Initializes a new instance of ID generator.

const createId8 = init({ length: 8 });

createId

Creates a random ID of length 24.

It accepts optional external data which is used as another source of entropy.

const userId = createId(userEmail);

Credits

This library is directly based on Cuid2.

Package Sidebar

Install

npm i @the-minimal/id

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

8.41 kB

Total Files

7

Last publish

Collaborators

  • yamiteru