mirror of
https://github.com/lasthead0/yandex2mqtt.git
synced 2025-08-08 09:01:00 +03:00
Release
This commit is contained in:
32
utils/index.js
Normal file
32
utils/index.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Return a unique identifier with the given `len`.
|
||||
*
|
||||
* @param {Number} length
|
||||
* @return {String}
|
||||
* @api private
|
||||
*/
|
||||
module.exports.getUid = function(length) {
|
||||
let uid = '';
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
const charsLength = chars.length;
|
||||
|
||||
for (let i = 0; i < length; ++i) {
|
||||
uid += chars[getRandomInt(0, charsLength - 1)];
|
||||
}
|
||||
|
||||
return uid;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a random int, used by `utils.getUid()`.
|
||||
*
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @return {Number}
|
||||
* @api private
|
||||
*/
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
Reference in New Issue
Block a user