From 52e04b06a93c961084e97d5f33b8f02888c87be4 Mon Sep 17 00:00:00 2001 From: CodingRule Date: Tue, 19 Nov 2024 06:20:02 -0800 Subject: [PATCH] chore: use `toUpperCase` in `detectOS` (#7241) * Update detectOS.ts Signed-off-by: CodingRule * Update detectOS.ts Signed-off-by: CodingRule * Update detectOS.ts Signed-off-by: CodingRule * Update apps/site/util/detectOS.ts Co-authored-by: Aviv Keller Signed-off-by: CodingRule --------- Signed-off-by: CodingRule Co-authored-by: Aviv Keller --- apps/site/util/detectOS.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/apps/site/util/detectOS.ts b/apps/site/util/detectOS.ts index 92b8f2277e39e..351eb1a9fe444 100644 --- a/apps/site/util/detectOS.ts +++ b/apps/site/util/detectOS.ts @@ -1,19 +1,9 @@ import type { UserOS } from '@/types/userOS'; export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => { - const osMatch = userAgent?.match(/(Win|Mac|Linux)/); - switch (osMatch && osMatch[1]) { - case 'Win': - return 'WIN'; - case 'Mac': - return 'MAC'; - case 'Linux': - return 'LINUX'; - case 'AIX': - return 'AIX'; - default: - return 'OTHER'; - } + // Match OS names and convert to uppercase directly if there's a match + const osMatch = userAgent?.match(/(Win|Mac|Linux|AIX)/); + return osMatch ? (osMatch[1].toUpperCase() as UserOS) : 'OTHER'; }; // Since `navigator.appVersion` is deprecated, we use the `userAgent``