Skip to content

Commit

Permalink
chore: use toUpperCase in detectOS (nodejs#7241)
Browse files Browse the repository at this point in the history
* Update detectOS.ts

Signed-off-by: CodingRule <[email protected]>

* Update detectOS.ts

Signed-off-by: CodingRule <[email protected]>

* Update detectOS.ts

Signed-off-by: CodingRule <[email protected]>

* Update apps/site/util/detectOS.ts

Co-authored-by: Aviv Keller <[email protected]>
Signed-off-by: CodingRule <[email protected]>

---------

Signed-off-by: CodingRule <[email protected]>
Co-authored-by: Aviv Keller <[email protected]>
  • Loading branch information
CodingRule and RedYetiDev authored Nov 19, 2024
1 parent c5345f5 commit 52e04b0
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions apps/site/util/detectOS.ts
Original file line number Diff line number Diff line change
@@ -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``
Expand Down

0 comments on commit 52e04b0

Please sign in to comment.