1 | ;
|
2 |
|
3 | var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_';
|
4 |
|
5 | function generateId(length) {
|
6 | if (!length) {
|
7 | length = 8;
|
8 | }
|
9 | var res = '';
|
10 | for (var i = 0; i < length; ++i) {
|
11 | res += alphabet[Math.floor(Math.random() * alphabet.length)];
|
12 | }
|
13 | return res;
|
14 | }
|
15 |
|
16 | module.exports = generateId;
|