forked from jitsi/jitsi-meet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cc2b38
commit 4584d89
Showing
5 changed files
with
271 additions
and
220 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,82 @@ | ||
/** | ||
* Alphanumeric characters. | ||
* @const | ||
*/ | ||
var ALPHANUM = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
const ALPHANUM | ||
= '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; | ||
|
||
/** | ||
* Hexadecimal digits. | ||
* Hexadecimal digit characters. | ||
* @const | ||
*/ | ||
var HEX_DIGITS = '0123456789abcdef'; | ||
const HEX_DIGITS = '0123456789abcdef'; | ||
|
||
/** | ||
* Generates random int within the range [min, max] | ||
* @param min the minimum value for the generated number | ||
* @param max the maximum value for the generated number | ||
* @returns random int number | ||
* Generate a string with random alphanumeric characters with a specific length. | ||
* | ||
* @param {number} length - The length of the string to return. | ||
* @returns {string} A string of random alphanumeric characters with the | ||
* specified length. | ||
*/ | ||
function randomInt(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
export function randomAlphanumString(length) { | ||
return _randomString(length, ALPHANUM); | ||
} | ||
|
||
/** | ||
* Get random element from array or string. | ||
* @param {Array|string} arr source | ||
* @returns array element or string character | ||
* Get random element of array or string. | ||
* | ||
* @param {Array|string} arr - Source. | ||
* @returns {Array|string} Array element or string character. | ||
*/ | ||
function randomElement(arr) { | ||
return arr[randomInt(0, arr.length -1)]; | ||
export function randomElement(arr) { | ||
return arr[randomInt(0, arr.length - 1)]; | ||
} | ||
|
||
/** | ||
* Generate random alphanumeric string. | ||
* @param {number} length expected string length | ||
* @returns {string} random string of specified length | ||
* Returns a random hex digit. | ||
* | ||
* @returns {Array|string} | ||
*/ | ||
function randomAlphanumStr(length) { | ||
var result = ''; | ||
export function randomHexDigit() { | ||
return randomElement(HEX_DIGITS); | ||
} | ||
|
||
for (var i = 0; i < length; i += 1) { | ||
result += randomElement(ALPHANUM); | ||
} | ||
/** | ||
* Generates a string of random hexadecimal digits with a specific length. | ||
* | ||
* @param {number} length - The length of the string to return. | ||
* @returns {string} A string of random hexadecimal digits with the specified | ||
* length. | ||
*/ | ||
export function randomHexString(length) { | ||
return _randomString(length, HEX_DIGITS); | ||
} | ||
|
||
return result; | ||
/** | ||
* Generates random int within the range [min, max]. | ||
* | ||
* @param {number} min - The minimum value for the generated number. | ||
* @param {number} max - The maximum value for the generated number. | ||
* @returns {number} Random int number. | ||
*/ | ||
export function randomInt(min, max) { | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
|
||
/** | ||
* Exported interface. | ||
* Generates a string of random characters with a specific length. | ||
* | ||
* @param {number} length - The length of the string to return. | ||
* @param {string} characters - The characters from which the returned string is | ||
* to be constructed. | ||
* @returns {string} A string of random characters with the specified length. | ||
*/ | ||
var RandomUtil = { | ||
/** | ||
* Returns a random hex digit. | ||
* @returns {*} | ||
*/ | ||
randomHexDigit: function() { | ||
return randomElement(HEX_DIGITS); | ||
}, | ||
/** | ||
* Returns a random string of hex digits with length 'len'. | ||
* @param len the length. | ||
*/ | ||
randomHexString: function (len) { | ||
var ret = ''; | ||
while (len--) { | ||
ret += this.randomHexDigit(); | ||
} | ||
return ret; | ||
}, | ||
randomElement: randomElement, | ||
randomAlphanumStr: randomAlphanumStr, | ||
randomInt: randomInt | ||
}; | ||
function _randomString(length, characters) { | ||
let result = ''; | ||
|
||
module.exports = RandomUtil; | ||
for (let i = 0; i < length; ++i) { | ||
result += randomElement(characters); | ||
} | ||
|
||
return result; | ||
} |
Oops, something went wrong.