UNPKG

324 BJavaScriptView Raw
1'use strict';
2
3var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_';
4
5function 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
16module.exports = generateId;