1.0.0 • Published 4 years ago
@mls44/uid v1.0.0
Simple usage
const uid = new UID().value
generates a 8 char uid from the charset 23456789abdegjkmnpqrvwxyz
Alpha only
import UID, { alpha } from './uid.js'
const uid = new UID({ charset: alpha, length: 6 }).value
generates a 6 char uid from the charset 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ'
Custom charset
const uid = new UID({ charset: '!@#$%^&*()_+', length: 4 }).value
Ensure unique
const uid = new UID().exclude([Array of uids to exclude]).value
Notes
- The included charsets
safe
andalpha
, exclude vowels to prevent expletives - No restrictions are placed on the length or charsets you provide. You could for example pass
{ charset: 'x', length:1 }
which will of course only ever generate a uid of 'x'. - If you provide an exclude array the code will keep looping until it finds a uid that is not in the array. If the array is too large and/or the charset and length provided are not sufficient it may take some time or enter an infinite loop.
1.0.0
4 years ago