+16
| function getRandomIndex(max: number): number { | ||
| return Math.floor(Math.random() * max); | ||
| } | ||
| export function generate(length: number = 8): string { | ||
| const characters: string = 'abcdefghijklmnopqrstuvwxyz0123456789'; | ||
| let result: string = ''; | ||
| for (let i: number = 0; i < length; i++) { | ||
| const randomIndex: number = getRandomIndex(characters.length); | ||
| result += characters.charAt(randomIndex); | ||
| } | ||
| return result; | ||
| } |
| { | ||
| "compilerOptions": { | ||
| "target": "es6", | ||
| "module": "commonjs", | ||
| "strict": true | ||
| }, | ||
| "include": ["src/**/*.ts"], | ||
| "exclude": ["node_modules"] | ||
| } | ||
+5
-2
| { | ||
| "name": "quickid", | ||
| "version": "1.0.2", | ||
| "version": "1.0.3", | ||
| "description": "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 length.", | ||
@@ -18,3 +18,6 @@ "main": "index.js", | ||
| "author": "MD. HASAN MIA", | ||
| "license": "ISC" | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "typescript": "^5.3.3" | ||
| } | ||
| } |
-17
| 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, | ||
| }; |
2591
12.07%4
33.33%21
61.54%1
Infinity%+ Added
+ Added