From e800147eaa0a95cfe8a82723c9d8295633d43f51 Mon Sep 17 00:00:00 2001 From: Franco Speziali Date: Thu, 25 May 2023 15:48:53 +0200 Subject: [PATCH] Default to day grouping if invalid parameter --- src/Calendar/index.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Calendar/index.ts b/src/Calendar/index.ts index df69afa..6d0a2dc 100644 --- a/src/Calendar/index.ts +++ b/src/Calendar/index.ts @@ -14,12 +14,24 @@ export default class Calendar { constructor(json: object) { this.jsonContent = json; - this.groupType = json["group"] - ? json["group"].charAt(0).toUpperCase() - : GroupTypes.Day; + this.groupType = this.getGroupType(json); this.events = new Events(json["events"]); } + private getGroupType(json: object): GroupTypes { + if (!json["group"]) { + return GroupTypes.Day; + } + + const groupType = json["group"].charAt(0).toUpperCase(); + + if (!Object.values(GroupTypes).includes(groupType)) { + return GroupTypes.Day; + } + + return groupType; + } + render(): HTMLDivElement { switch (this.groupType) { case GroupTypes.Day: