Commit | Line | Data |
---|---|---|
badeb466 | 1 | function randString() |
0bd5933d | 2 | { |
dac39588 | 3 | return Math.random().toString(36).substr(2); // remove `0.` |
badeb466 | 4 | } |
0bd5933d | 5 | |
866842c3 | 6 | module.exports = function(tokenLength) |
badeb466 | 7 | { |
dac39588 | 8 | let res = ""; |
866842c3 BA |
9 | // 10 = min length of a rand() string |
10 | let nbRands = Math.ceil(tokenLength/10); | |
dac39588 BA |
11 | for (let i = 0; i < nbRands; i++) |
12 | res += randString(); | |
866842c3 | 13 | return res.substr(0, tokenLength); |
0bd5933d | 14 | } |