create a password with uppercase letters in typescript

Here's an example function in TypeScript that generates a random password with uppercase letters:

index.ts
function generatePassword(length: number): string {
  const uppercaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  let password = '';

  for (let i = 0; i < length; i++) {
    const randomIndex = Math.floor(Math.random() * uppercaseLetters.length);
    const randomChar = uppercaseLetters[randomIndex];
    password += randomChar;
  }

  return password;
}
353 chars
13 lines

This function takes a length parameter, which specifies the length of the password to generate. It then creates a string of uppercase letters, and loops length times, each time generating a random uppercase letter and adding it to the password string. Finally, it returns the password string.

You can call this function like this:

index.ts
const password = generatePassword(10);
console.log(password);
62 chars
3 lines

This would generate a random password of length 10 with only uppercase letters. You can modify the uppercaseLetters string to include additional characters if you want.

gistlibby LogSnag