diff --git a/index.js b/index.js new file mode 100644 index 0000000..f3c5eca --- /dev/null +++ b/index.js @@ -0,0 +1,21 @@ + +/** + * + * @param {number} len length of the id which shall be generated + * @returns + */ + +const generateId = (len) => { + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + let result = ''; + for (let i = 0; i < len; i++) { + const randomIndex = Math.floor(Math.random() * characters.length); + result += characters[randomIndex]; + } + + return result; +} + +module.exports = { + generateId +} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..6e1b0de --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "id-generator", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +}