Created
January 25, 2021 21:10
-
-
Save justin-schroeder/78581bc2e892801c954aa3ccb4cf8eb9 to your computer and use it in GitHub Desktop.
Random id, token, uuid generator (or whatever you want to call it)
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
/** | |
* Prouces a random token like token(5) = 1a4c9 | |
* @param n {number} The length of the token | |
* @returns {string} | |
*/ | |
const token = (n: number) => | |
String.fromCharCode( | |
...new Array(n) | |
.fill(0) | |
.map( | |
(_n, i) => [48, 97][i % 2] + Math.floor(Math.random() * [10, 25][i % 2]) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment