quickid
Version:
Quick ID is a lightweight and efficient npm package designed to generate unique and random IDs effortlessly. With simplicity in mind, Quick ID provides a single function, quickId(), which returns a randomly generated alphanumeric string of a specified len
17 lines (13 loc) • 419 B
JavaScript
const getRandomIndex = (max) => Math.floor(Math.random() * max);
const generate = (length = 8) => {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
const randomIndex = getRandomIndex(characters.length);
result += characters.charAt(randomIndex);
}
return result;
};
module.exports = {
generate,
};