Skip to content

Commit a8ae7d8

Browse files
CodingRuleavivkeller
authored andcommitted
chore: use toUpperCase in detectOS (#7241)
* Update detectOS.ts Signed-off-by: CodingRule <ioumih32@gmail.com> * Update detectOS.ts Signed-off-by: CodingRule <ioumih32@gmail.com> * Update detectOS.ts Signed-off-by: CodingRule <ioumih32@gmail.com> * Update apps/site/util/detectOS.ts Co-authored-by: Aviv Keller <redyetidev@gmail.com> Signed-off-by: CodingRule <ioumih32@gmail.com> --------- Signed-off-by: CodingRule <ioumih32@gmail.com> Co-authored-by: Aviv Keller <redyetidev@gmail.com>
1 parent a03d578 commit a8ae7d8

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

apps/site/util/detectOS.ts

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
import type { UserOS } from '@/types/userOS';
22

33
export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => {
4-
const osMatch = userAgent?.match(/(Win|Mac|Linux)/);
5-
switch (osMatch && osMatch[1]) {
6-
case 'Win':
7-
return 'WIN';
8-
case 'Mac':
9-
return 'MAC';
10-
case 'Linux':
11-
return 'LINUX';
12-
case 'AIX':
13-
return 'AIX';
14-
default:
15-
return 'OTHER';
16-
}
4+
// Match OS names and convert to uppercase directly if there's a match
5+
const osMatch = userAgent?.match(/(Win|Mac|Linux|AIX)/);
6+
return osMatch ? (osMatch[1].toUpperCase() as UserOS) : 'OTHER';
177
};
188

199
// Since `navigator.appVersion` is deprecated, we use the `userAgent``

0 commit comments

Comments
 (0)