Skip to content

Commit

Permalink
Rename to password-strenght.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Skrypt committed Jan 11, 2025
1 parent bdb9cfa commit 9f5d234
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @param {string} options.target - CSS selector for the element where the strength progress bar is displayed.
* @param {string} options.style - CSS style string for the progress bar.
*/
export default function strength(element: HTMLInputElement, options: any) {
export default (element: HTMLInputElement, options: any) => {

const settings = Object.assign({
requiredLength: 8,
Expand All @@ -38,12 +38,9 @@ export default function strength(element: HTMLInputElement, options: any) {

let valid = false;

function getPercentage(a: number, b: number) {
return (b / a) * 100;
}

function getLevel(value: number) {
const getPercentage = (a: number, b: number) => (b / a) * 100;

const getLevel = (value: number) => {
if (value >= 100) {
return "bg-success";
}
Expand All @@ -57,9 +54,9 @@ export default function strength(element: HTMLInputElement, options: any) {
}

return "bg-danger";
}
};

function checkStrength(value: string) {
const checkStrength = (value: string) => {

const minLength = value.length >= settings.requiredLength ? 1 : 0;
capitalletters = !settings.requireUppercase || value.match(upperCase) ? 1 : 0;
Expand All @@ -73,9 +70,9 @@ export default function strength(element: HTMLInputElement, options: any) {
valid = percentage >= 100;

createProgressBar(percentage, getLevel(percentage));
}
};

function createProgressBar(percentage: string | number, level: string) {
const createProgressBar = (percentage: string | number, level: string) => {
const el = document.createElement("div");
el.className = "progress";
el.setAttribute("value", percentage.toString());
Expand All @@ -89,7 +86,7 @@ export default function strength(element: HTMLInputElement, options: any) {
const target = document.querySelector(settings.target);
target.innerHTML = "";
target.appendChild(el);
}
};

element.addEventListener("keyup", () => checkStrength(element.value));
element.addEventListener("keydown", () => checkStrength(element.value));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import strenght from "@orchardcore/frontend/components/strength";
import strenght from "@orchardcore/frontend/components/password-strength";

// Show or hide the connection string or table prefix section when the database provider is selected
const toggleConnectionStringAndPrefix = () => {
Expand Down

0 comments on commit 9f5d234

Please sign in to comment.