Last active
November 15, 2018 20:59
-
-
Save sdesalas/10a316504cdd62399c353b391ff57757 to your computer and use it in GitHub Desktop.
Base56 random character generation.
This file contains hidden or 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
| // Thanks to https://github.com/evanx/secret-base56 | |
| const letters24 = 'ABCDEFGHJKLMNPQRSTUVWXYZ'; // exclude I and O since too similar to 0 and 1 | |
| const digits8 = '23456789'; // omit 0 and 1 to avoid potential confusion with O and I (and perhaps 'l') | |
| const charset = [digits8, letters24, letters24.toLowerCase()].join(''); | |
| module.exports = length => Array(length) | |
| .fill() | |
| .map(() => charset[Math.floor(Math.random() * 56)]) | |
| .join(''); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: