1.0.0 • Published 1 year ago

id-zero v1.0.0

Weekly downloads
-
License
Unlicense
Repository
github
Last release
1 year ago

id-zero

npm version License Build status

Basically the simplest, tiniest ID generator imaginable. It produces pseudorandom lowercase alphanumeric strings of any length in just ~75 bytes of code (minified and Brotli compressed).

export default (length) => {
  let id = ''

  while (id.length < length) {
    id += Math.random().toString(36).slice(2)
  }

  return id.slice(0, length)
}

If you need IDs that are guaranteeably unique or secure, this obviously isn't what you need. I recommend nanoid.

Example usage

import idZero from 'id-zero'

idZero(6) // 'x37m3q'
idZero(12) // '0hw4tpx7i2qj'
idZero(24) // 'j1x927x4b5792h5paov6otfi'