UNPKG

@eszmateusz/node-unique-id-generator

Version:

It is simple node package with the module that generates a unique multi-character string number as a random id. It is provided set of letters and numbers. Set idLength parameter determines the number of characters in the multi-character string. The res

14 lines (10 loc) 347 B
const randomID = (idLength) => { let id = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charsAmount = characters.length; for (let i = 0; i < idLength; i++) { id += characters.charAt(Math.floor(Math.random() * charsAmount)); } return id; } module.exports = randomID;