1 | const {
|
2 | shuffle,
|
3 | toUpper,
|
4 | floor,
|
5 | } = require('lodash');
|
6 |
|
7 | const underscore = '_';
|
8 | const numbers = '0123456789';
|
9 | const letters = 'abcdefghijklmnopqrstuvwxyz';
|
10 | const upperLetters = toUpper(letters);
|
11 | const stringSet = `${underscore}${numbers}${letters}${upperLetters}`;
|
12 | const stringSetLength = stringSet.length;
|
13 |
|
14 | module.exports = (len = 7) => {
|
15 | if (len < 1) {
|
16 | return '';
|
17 | }
|
18 | let delta = floor(len / stringSetLength);
|
19 | let str = stringSet;
|
20 | while (delta--) {
|
21 | str += str;
|
22 | }
|
23 | return shuffle(str.split('')).slice(0, len).join('');
|
24 | };
|