1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

[CL-682] Convert color password enum to const (#15908)

This commit is contained in:
Vicki League
2025-08-06 14:35:37 -04:00
committed by GitHub
parent 423b1cf1df
commit 6ec0a61b7e

View File

@@ -2,14 +2,8 @@ import { Component, computed, HostBinding, input } from "@angular/core";
import { Utils } from "@bitwarden/common/platform/misc/utils";
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
enum CharacterType {
Letter,
Emoji,
Special,
Number,
}
type CharacterType = "letter" | "emoji" | "special" | "number";
/**
* The color password is used primarily in the Generator pages and in the Login type form. It includes
* the logic for displaying letters as `text-main`, numbers as `primary`, and special symbols as
@@ -36,10 +30,10 @@ export class ColorPasswordComponent {
});
characterStyles: Record<CharacterType, string[]> = {
[CharacterType.Emoji]: [],
[CharacterType.Letter]: ["tw-text-main"],
[CharacterType.Special]: ["tw-text-danger"],
[CharacterType.Number]: ["tw-text-primary-600"],
emoji: [],
letter: ["tw-text-main"],
special: ["tw-text-danger"],
number: ["tw-text-primary-600"],
};
@HostBinding("class")
@@ -68,18 +62,18 @@ export class ColorPasswordComponent {
private getCharacterType(character: string): CharacterType {
if (character.match(Utils.regexpEmojiPresentation)) {
return CharacterType.Emoji;
return "emoji";
}
if (character.match(/\d/)) {
return CharacterType.Number;
return "number";
}
const specials = ["&", "<", ">", " "];
if (specials.includes(character) || character.match(/[^\w ]/)) {
return CharacterType.Special;
return "special";
}
return CharacterType.Letter;
return "letter";
}
}