File size: 291 Bytes
a45ece3
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
const alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz-'

export function nanoid(size = 12): string {
  let id = ''
  const bytes = crypto.getRandomValues(new Uint8Array(size))
  for (let i = 0; i < size; i++) {
    id += alphabet[bytes[i] & 63]
  }
  return id
}