2017-12-14 15:52:20 +03:00
|
|
|
let _private = {};
|
|
|
|
|
|
|
|
_private.getRandomInt = function (min, max) {
|
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a unique identifier with the given `len`.
|
|
|
|
*
|
2022-05-06 17:04:23 +03:00
|
|
|
* @deprecated use secret.create() instead
|
2017-12-14 15:52:20 +03:00
|
|
|
* @param {Number} maxLength
|
|
|
|
* @return {String}
|
|
|
|
*/
|
|
|
|
module.exports.uid = function uid(maxLength) {
|
2020-04-29 18:44:27 +03:00
|
|
|
const buf = [];
|
|
|
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
|
|
const charLength = chars.length;
|
|
|
|
let i;
|
2017-12-14 15:52:20 +03:00
|
|
|
|
|
|
|
for (i = 0; i < maxLength; i = i + 1) {
|
|
|
|
buf.push(chars[_private.getRandomInt(0, charLength - 1)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.join('');
|
|
|
|
};
|