///
import { Controller } from "stimulus";
function generatePassword() {
const chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*";
let password = "";
for (let i = 0; i < 8; i++) {
password += chars.charAt(Math.floor(Math.random() * chars.length));
}
return password;
}
export default class extends Controller {
getInput(): HTMLInputElement {
return this.element.parentElement!.querySelector(
"input"
) as HTMLInputElement;
}
generate() {
this.getInput().value = generatePassword();
this.getInput().setAttribute("type", "text");
}
}