1
- export type DetectedInfoType = 'browser' | 'node' | 'bot-device' | 'bot' | 'react-native' ;
1
+ export type DetectedInfoType =
2
+ | 'browser'
3
+ | 'node'
4
+ | 'bot-device'
5
+ | 'bot'
6
+ | 'react-native' ;
2
7
3
8
interface DetectedInfo <
4
9
T extends DetectedInfoType ,
5
10
N extends string ,
6
11
O ,
7
12
V = null
8
- > {
13
+ > {
9
14
readonly type : T ;
10
15
readonly name : N ;
11
16
readonly version : V ;
@@ -19,7 +24,7 @@ export class BrowserInfo
19
24
public readonly name : Browser ,
20
25
public readonly version : string ,
21
26
public readonly os : OperatingSystem | null ,
22
- ) { }
27
+ ) { }
23
28
}
24
29
25
30
export class NodeInfo
@@ -28,19 +33,19 @@ export class NodeInfo
28
33
public readonly name : 'node' = 'node' ;
29
34
public readonly os : NodeJS . Platform = process . platform ;
30
35
31
- constructor ( public readonly version : string ) { }
36
+ constructor ( public readonly version : string ) { }
32
37
}
33
38
34
39
export class SearchBotDeviceInfo
35
40
implements
36
- DetectedInfo < 'bot-device' , Browser , OperatingSystem | null , string > {
41
+ DetectedInfo < 'bot-device' , Browser , OperatingSystem | null , string > {
37
42
public readonly type = 'bot-device' ;
38
43
constructor (
39
44
public readonly name : Browser ,
40
45
public readonly version : string ,
41
46
public readonly os : OperatingSystem | null ,
42
47
public readonly bot : string ,
43
- ) { }
48
+ ) { }
44
49
}
45
50
46
51
export class BotInfo implements DetectedInfo < 'bot' , 'bot' , null , null > {
@@ -57,7 +62,7 @@ export class ReactNativeInfo
57
62
public readonly name : 'react-native' = 'react-native' ;
58
63
public readonly version : null = null ;
59
64
public readonly os : null = null ;
60
- } ;
65
+ }
61
66
62
67
export type Browser =
63
68
| 'aol'
@@ -188,7 +193,13 @@ const operatingSystemRules: OperatingSystemRule[] = [
188
193
189
194
export function detect (
190
195
userAgent ?: string ,
191
- ) : BrowserInfo | SearchBotDeviceInfo | BotInfo | NodeInfo | ReactNativeInfo | null {
196
+ ) :
197
+ | BrowserInfo
198
+ | SearchBotDeviceInfo
199
+ | BotInfo
200
+ | NodeInfo
201
+ | ReactNativeInfo
202
+ | null {
192
203
if ( ! ! userAgent ) {
193
204
return parseUserAgent ( userAgent ) ;
194
205
}
0 commit comments