Skip to content

Commit

Permalink
fix(DiscordHeader): ensure that the level property is a number
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Feb 17, 2024
1 parent 45ef043 commit a97a969
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/components/discord-header/DiscordHeader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ export class DiscordHeader extends LitElement {
@property({ type: Number, reflect: true })
public accessor level: 1 | 2 | 3 = 1;

public ensureLevelIsNumber(): void {
if (this.level && !isNaN(this.level)) {
this.level = Number(this.level) as typeof this.level;
}
}

public checkLevel() {
if (this.level < 1 || this.level > 3) {
throw new RangeError('The level property must be a number between 1 and 3 (inclusive)');
}
}

protected override render() {
this.ensureLevelIsNumber();
this.checkLevel();

switch (this.level) {
Expand Down

0 comments on commit a97a969

Please sign in to comment.