mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
[CL-682] Convert color password enum to const (#15908)
This commit is contained in:
@@ -2,14 +2,8 @@ import { Component, computed, HostBinding, input } from "@angular/core";
|
|||||||
|
|
||||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||||
|
|
||||||
// FIXME: update to use a const object instead of a typescript enum
|
type CharacterType = "letter" | "emoji" | "special" | "number";
|
||||||
// eslint-disable-next-line @bitwarden/platform/no-enums
|
|
||||||
enum CharacterType {
|
|
||||||
Letter,
|
|
||||||
Emoji,
|
|
||||||
Special,
|
|
||||||
Number,
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* The color password is used primarily in the Generator pages and in the Login type form. It includes
|
* 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
|
* 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[]> = {
|
characterStyles: Record<CharacterType, string[]> = {
|
||||||
[CharacterType.Emoji]: [],
|
emoji: [],
|
||||||
[CharacterType.Letter]: ["tw-text-main"],
|
letter: ["tw-text-main"],
|
||||||
[CharacterType.Special]: ["tw-text-danger"],
|
special: ["tw-text-danger"],
|
||||||
[CharacterType.Number]: ["tw-text-primary-600"],
|
number: ["tw-text-primary-600"],
|
||||||
};
|
};
|
||||||
|
|
||||||
@HostBinding("class")
|
@HostBinding("class")
|
||||||
@@ -68,18 +62,18 @@ export class ColorPasswordComponent {
|
|||||||
|
|
||||||
private getCharacterType(character: string): CharacterType {
|
private getCharacterType(character: string): CharacterType {
|
||||||
if (character.match(Utils.regexpEmojiPresentation)) {
|
if (character.match(Utils.regexpEmojiPresentation)) {
|
||||||
return CharacterType.Emoji;
|
return "emoji";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (character.match(/\d/)) {
|
if (character.match(/\d/)) {
|
||||||
return CharacterType.Number;
|
return "number";
|
||||||
}
|
}
|
||||||
|
|
||||||
const specials = ["&", "<", ">", " "];
|
const specials = ["&", "<", ">", " "];
|
||||||
if (specials.includes(character) || character.match(/[^\w ]/)) {
|
if (specials.includes(character) || character.match(/[^\w ]/)) {
|
||||||
return CharacterType.Special;
|
return "special";
|
||||||
}
|
}
|
||||||
|
|
||||||
return CharacterType.Letter;
|
return "letter";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user