UNPKG

nanoid

Version:

A tiny (118 bytes), secure URL-friendly unique string ID generator

23 lines (19 loc) 456 B
import { urlAlphabet } from '../url-alphabet/index.js' export let customAlphabet = (alphabet, defaultSize = 21) => { return (size = defaultSize) => { let id = '' let i = size | 0 while (i-- > 0) { id += alphabet[(Math.random() * alphabet.length) | 0] } return id } } export let nanoid = (size = 21) => { let id = '' let i = size | 0 while (i-- > 0) { id += urlAlphabet[(Math.random() * 64) | 0] } return id }