-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathRandom.js
More file actions
22 lines (21 loc) · 612 Bytes
/
Random.js
File metadata and controls
22 lines (21 loc) · 612 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const UNMISTAKABLE_CHARS =
'23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz';
export default {
/**
* Generates a random id-string of given length.
* The string will consist of characters from the following list:
* `23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijkmnopqrstuvwxyz`
* @param count {number} length of the id
* @returns {string} the generated id string
*/
id(count = 17) {
let res = '';
for (let i = 0; i < count; i++) {
res +=
UNMISTAKABLE_CHARS[
Math.floor(Math.random() * UNMISTAKABLE_CHARS.length)
];
}
return res;
},
};