forked from nodejs/nodejs.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetectOS.ts
More file actions
36 lines (35 loc) · 861 Bytes
/
Copy pathdetectOS.ts
File metadata and controls
36 lines (35 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// eslint-disable-next-line no-shadow
export enum UserOS {
MAC = 'MAC',
WIN = 'WIN',
UNIX = 'UNIX',
LINUX = 'LINUX',
MOBILE = 'MOBILE',
UNKNOWN = 'UNKNOWN',
}
export function detectOS(): UserOS {
let OS = UserOS.UNKNOWN;
if (typeof window !== 'undefined') {
switch (typeof navigator !== 'undefined') {
case navigator.appVersion.includes('Win'):
OS = UserOS.WIN;
break;
case navigator.appVersion.includes('Mac'):
OS = UserOS.MAC;
break;
case navigator.appVersion.includes('X11'):
OS = UserOS.UNIX;
break;
case navigator.appVersion.includes('Linux'):
OS = UserOS.LINUX;
break;
case navigator.appVersion.includes('Mobi'):
OS = UserOS.MOBILE;
break;
default:
OS = UserOS.UNKNOWN;
break;
}
}
return OS;
}