UNPKG

549 BJavaScriptView Raw
1const {
2 shuffle,
3 toUpper,
4 floor,
5} = require('lodash');
6
7const underscore = '_';
8const numbers = '0123456789';
9const letters = 'abcdefghijklmnopqrstuvwxyz';
10const upperLetters = toUpper(letters);
11const stringSet = `${underscore}${numbers}${letters}${upperLetters}`;
12const stringSetLength = stringSet.length;
13
14module.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};