Here's a simple implementation of a password generator function in TypeScript that takes in a desired length and generates a random password with uppercase letters:
index.ts485 chars14 lines
This function first declares two strings: uppercaseChars
which contains only uppercase letters, and allChars
which contains uppercase letters, lowercase letters, and digits. It then initializes an empty string for the password.
The function then iterates length
number of times and adds a random character from the uppercaseChars
string for the first character, and from the allChars
string for the rest of the characters. Finally, the function returns the generated password.
You can call this function with a desired length to generate a random password:
index.ts169 chars3 lines
gistlibby LogSnag