Last active
May 24, 2024 17:03
-
-
Save alekstar79/2f34431f79871da5d59ef17363f80e61 to your computer and use it in GitHub Desktop.
Random string generator
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
| const caps = Array.from('ABCDEFGHIJKLMNOPQRSTUVWXYZ'), | |
| lower = Array.from('abcdefghijklmnopqrstuvwxyz'), | |
| numbers = Array.from('0123456789') | |
| export function symbols(set = 'all') | |
| { | |
| return set === 'all' ? Array.from([...caps,...lower,...numbers]) : Array.from({ caps, lower, numbers }[set]) | |
| } | |
| export function rndstring(length = 7, signs = 'all') | |
| { | |
| const base = symbols(signs) | |
| return Array.from({ length }, () => base[Math.random() * base.length | 0]).join('') | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment