UNPKG

my-ua-parser

Version:

Detect Browser, Engine, OS, CPU, and Device type/model from User-Agent data. Supports browser & node.js environment

227 lines (193 loc) 6.73 kB
/* MIT License Copyright (c) Matteo Collina <hello@matteocollina.com>. Copyright (c) Microsoft Corporation. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE */ declare namespace UAParser { // tslint:disable:interface-name backward compatible exclusion interface IBrowser { /** * Possible values : * Amaya, Android Browser, Arora, Avant, Baidu, Blazer, Bolt, Camino, Chimera, Chrome, * Chromium, Comodo Dragon, Conkeror, Dillo, Dolphin, Doris, Edge, Epiphany, Fennec, * Firebird, Firefox, Flock, GoBrowser, iCab, ICE Browser, IceApe, IceCat, IceDragon, * Iceweasel, IE [Mobile], Iron, Jasmine, K-Meleon, Konqueror, Kindle, Links, * Lunascape, Lynx, Maemo, Maxthon, Midori, Minimo, MIUI Browser, [Mobile] Safari, * Mosaic, Mozilla, Netfront, Netscape, NetSurf, Nokia, OmniWeb, Opera [Mini/Mobi/Tablet], * Phoenix, Polaris, QQBrowser, RockMelt, Silk, Skyfire, SeaMonkey, SlimBrowser, Swiftfox, * Tizen, UCBrowser, Vivaldi, w3m, Yandex */ name: string | undefined; /** * Determined dynamically */ version: string | undefined; /** * Determined dynamically * @deprecated */ major: string | undefined; } interface IDevice { /** * Determined dynamically */ model: string | undefined; /** * Possible type: * console, mobile, tablet, smarttv, wearable, embedded */ type: string | undefined; /** * Possible vendor: * Acer, Alcatel, Amazon, Apple, Archos, Asus, BenQ, BlackBerry, Dell, GeeksPhone, * Google, HP, HTC, Huawei, Jolla, Lenovo, LG, Meizu, Microsoft, Motorola, Nexian, * Nintendo, Nokia, Nvidia, Ouya, Palm, Panasonic, Polytron, RIM, Samsung, Sharp, * Siemens, Sony-Ericsson, Sprint, Xbox, ZTE */ vendor: string | undefined; } interface IEngine { /** * Possible name: * Amaya, EdgeHTML, Gecko, iCab, KHTML, Links, Lynx, NetFront, NetSurf, Presto, * Tasman, Trident, w3m, WebKit */ name: string | undefined; /** * Determined dynamically */ version: string | undefined; } interface IOS { /** * Possible 'os.name' * AIX, Amiga OS, Android, Arch, Bada, BeOS, BlackBerry, CentOS, Chromium OS, Contiki, * Fedora, Firefox OS, FreeBSD, Debian, DragonFly, Gentoo, GNU, Haiku, Hurd, iOS, * Joli, Linpus, Linux, Mac OS, Mageia, Mandriva, MeeGo, Minix, Mint, Morph OS, NetBSD, * Nintendo, OpenBSD, OpenVMS, OS/2, Palm, PCLinuxOS, Plan9, Playstation, QNX, RedHat, * RIM Tablet OS, RISC OS, Sailfish, Series40, Slackware, Solaris, SUSE, Symbian, Tizen, * Ubuntu, UNIX, VectorLinux, WebOS, Windows [Phone/Mobile], Zenwalk */ name: string | undefined; /** * Determined dynamically */ version: string | undefined; } interface ICPU { /** * Possible architecture: * 68k, amd64, arm, arm64, avr, ia32, ia64, irix, irix64, mips, mips64, pa-risc, * ppc, sparc, sparc64 */ architecture: string | undefined; } interface IResult { ua: string; browser: IBrowser; device: IDevice; engine: IEngine; os: IOS; cpu: ICPU; } interface BROWSER { NAME: "name"; /** * @deprecated */ MAJOR: "major"; VERSION: "version"; } interface CPU { ARCHITECTURE: "architecture"; } interface DEVICE { MODEL: "model"; VENDOR: "vendor"; TYPE: "type"; CONSOLE: "console"; MOBILE: "mobile"; SMARTTV: "smarttv"; TABLET: "tablet"; WEARABLE: "wearable"; EMBEDDED: "embedded"; } interface ENGINE { NAME: "name"; VERSION: "version"; } interface OS { NAME: "name"; VERSION: "version"; } interface UAParserInstance { /** * Returns browser information */ getBrowser(): IBrowser; /** * Returns OS information */ getOS(): IOS; /** * Returns browsers engine information */ getEngine(): IEngine; /** * Returns device information */ getDevice(): IDevice; /** * Returns parsed CPU information */ getCPU(): ICPU; /** * Returns UA string of current instance */ getUA(): string; /** * Set & parse UA string */ setUA(uastring: string): UAParserInstance; /** * Returns parse result */ getResult(): IResult; } } type UAParser = UAParser.UAParserInstance; declare const UAParser: { VERSION: string; BROWSER: UAParser.BROWSER; CPU: UAParser.CPU; DEVICE: UAParser.DEVICE; ENGINE: UAParser.ENGINE; OS: UAParser.OS; /** * Create a new parser with UA prepopulated and extensions extended */ new(uastring?: string, extensions?: Record<string, unknown>): UAParser.UAParserInstance; new(extensions?: Record<string, unknown>): UAParser.UAParserInstance; (uastring?: string, extensions?: Record<string, unknown>): UAParser.IResult; (extensions?: Record<string, unknown>): UAParser.IResult; // alias for older syntax UAParser: typeof UAParser; }; export as namespace UAParser; export = UAParser;