UNPKG

6.04 kBTypeScriptView Raw
1// Type definitions for ua-parser-js 0.7
2// Project: https://github.com/faisalman/ua-parser-js
3// Definitions by: Viktor Miroshnikov <https://github.com/superduper>
4// Lucas Woo <https://github.com/legendecas>
5// Pablo Rodríguez <https://github.com/MeLlamoPablo>
6// Piotr Błażejewicz <https://github.com/peterblazejewicz>
7// BendingBender <https://github.com/BendingBender>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9
10declare namespace UAParser {
11 // tslint:disable:interface-name backward compatible exclusion
12
13 interface IBrowser {
14 /**
15 * Possible values :
16 * Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Camino, Chimera, Chrome,
17 * Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge, Epiphany, Fennec,
18 * Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, IceDragon,
19 * Iceweasel, IE [Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle, Links,
20 * Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari,
21 * Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet],
22 * Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, SlimBrowser, Swiftfox,
23 * Tizen, UCBrowser, Vivaldi, w3m, Yandex
24 *
25 */
26 name: string | undefined;
27
28 /**
29 * Determined dynamically
30 */
31 version: string | undefined;
32
33 /**
34 * Determined dynamically
35 * @deprecated
36 */
37 major: string | undefined;
38 }
39
40 interface IDevice {
41 /**
42 * Determined dynamically
43 */
44 model: string | undefined;
45
46 /**
47 * Possible type:
48 * console, mobile, tablet, smarttv, wearable, embedded
49 */
50 type: string | undefined;
51
52 /**
53 * Possible vendor:
54 * Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone,
55 * Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian,
56 * Nintendo, Nokia, Nvidia, Ouya, Palm, Panasonic, Polytron, RIM, Samsung, Sharp,
57 * Siemens, Sony-Ericsson, Sprint, Xbox, ZTE
58 */
59 vendor: string | undefined;
60 }
61
62 interface IEngine {
63 /**
64 * Possible name:
65 * Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto,
66 * Tasman, Trident, w3m, WebKit
67 */
68 name: string | undefined;
69 /**
70 * Determined dynamically
71 */
72 version: string | undefined;
73 }
74
75 interface IOS {
76 /**
77 * Possible 'os.name'
78 * AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki,
79 * Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS,
80 * Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD,
81 * Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PCLinuxOS, Plan9, Playstation, QNX, RedHat,
82 * RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen,
83 * Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk
84 */
85 name: string | undefined;
86 /**
87 * Determined dynamically
88 */
89 version: string | undefined;
90 }
91
92 interface ICPU {
93 /**
94 * Possible architecture:
95 * 68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc,
96 * ppc, sparc, sparc64
97 */
98 architecture: string | undefined;
99 }
100
101 interface IResult {
102 ua: string;
103 browser: IBrowser;
104 device: IDevice;
105 engine: IEngine;
106 os: IOS;
107 cpu: ICPU;
108 }
109
110 interface BROWSER {
111 NAME: "name";
112 /**
113 * @deprecated
114 */
115 MAJOR: "major";
116 VERSION: "version";
117 }
118
119 interface CPU {
120 ARCHITECTURE: "architecture";
121 }
122
123 interface DEVICE {
124 MODEL: "model";
125 VENDOR: "vendor";
126 TYPE: "type";
127 CONSOLE: "console";
128 MOBILE: "mobile";
129 SMARTTV: "smarttv";
130 TABLET: "tablet";
131 WEARABLE: "wearable";
132 EMBEDDED: "embedded";
133 }
134
135 interface ENGINE {
136 NAME: "name";
137 VERSION: "version";
138 }
139
140 interface OS {
141 NAME: "name";
142 VERSION: "version";
143 }
144
145 interface UAParserInstance {
146 /**
147 * Returns browser information
148 */
149 getBrowser(): IBrowser;
150
151 /**
152 * Returns OS information
153 */
154 getOS(): IOS;
155
156 /**
157 * Returns browsers engine information
158 */
159 getEngine(): IEngine;
160
161 /**
162 * Returns device information
163 */
164 getDevice(): IDevice;
165
166 /**
167 * Returns parsed CPU information
168 */
169 getCPU(): ICPU;
170
171 /**
172 * Returns UA string of current instance
173 */
174 getUA(): string;
175
176 /**
177 * Set & parse UA string
178 */
179 setUA(uastring: string): UAParserInstance;
180
181 /**
182 * Returns parse result
183 */
184 getResult(): IResult;
185 }
186}
187
188type UAParser = UAParser.UAParserInstance;
189
190declare const UAParser: {
191 VERSION: string;
192 BROWSER: UAParser.BROWSER;
193 CPU: UAParser.CPU;
194 DEVICE: UAParser.DEVICE;
195 ENGINE: UAParser.ENGINE;
196 OS: UAParser.OS;
197
198 /**
199 * Create a new parser with UA prepopulated and extensions extended
200 */
201 new (uastring?: string, extensions?: Record<string, unknown>): UAParser.UAParserInstance;
202 new (extensions?: Record<string, unknown>): UAParser.UAParserInstance;
203 (uastring?: string, extensions?: Record<string, unknown>): UAParser.IResult;
204 (extensions?: Record<string, unknown>): UAParser.IResult;
205
206 // alias for older syntax
207 UAParser: typeof UAParser;
208};
209
210export as namespace UAParser;
211export = UAParser;