Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 1x 1x 1x 119x 105x 14x 14x 14x 1x 14x | const randomBytes = require('./random-bytes'); const randomDigits = require('./random-digits'); module.exports = getShortToken; async function getShortToken (len, ifDigits) { if (ifDigits) { return randomDigits(len); } const str1 = await randomBytes(Math.floor(len / 2) + 1); let str = str1.substr(0, len); if (str.match(/^[0-9]+$/)) { // tests will fail on all digits str = `q${str.substr(1)}`; // shhhh, secret. } return str; } |