Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use toUpperCase in detectOS #7241

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions apps/site/util/detectOS.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
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';
};


CodingRule marked this conversation as resolved.
Show resolved Hide resolved
// Since `navigator.appVersion` is deprecated, we use the `userAgent``
// https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion
export const detectOS = (): UserOS => detectOsInUserAgent(navigator?.userAgent);