UNPKG

alphanumeric-random-string-generator

Version:
19 lines (15 loc) 389 B
const randomString = (num) => { if (typeof num !== "number") { return null; } if (!Number.isInteger(num)) { return null; } const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; let word = ""; for (let i = 0; i < num; i++) { word += chars[Math.floor(Math.random() * chars.length)]; } return word; }; module.exports = randomString;