UNPKG

express-useragent

Version:

JS Library & ExpressJS user-agent middleware exposing

106 lines (102 loc) 3.14 kB
import { Request, Response, NextFunction } from 'express'; import { IncomingHttpHeaders } from 'http'; interface AgentDetails extends Record<string, unknown> { isYaBrowser: boolean; isAuthoritative: boolean; isMobile: boolean; isMobileNative: boolean; isTablet: boolean; isiPad: boolean; isiPod: boolean; isiPhone: boolean; isiPhoneNative: boolean; isAndroid: boolean; isAndroidNative: boolean; isBlackberry: boolean; isOpera: boolean; isIE: boolean; isEdge: boolean; isIECompatibilityMode: boolean; isSafari: boolean; isFirefox: boolean; isWebkit: boolean; isChrome: boolean; isKonqueror: boolean; isOmniWeb: boolean; isSeaMonkey: boolean; isFlock: boolean; isAmaya: boolean; isPhantomJS: boolean; isEpiphany: boolean; isDesktop: boolean; isWindows: boolean; isLinux: boolean; isLinux64: boolean; isMac: boolean; isChromeOS: boolean; isBada: boolean; isSamsung: boolean; isRaspberry: boolean; isBot: boolean | string; isCurl: boolean; isAndroidTablet: boolean; isWinJs: boolean; isKindleFire: boolean; isSilk: boolean; isCaptive: boolean; isSmartTV: boolean; isUC: boolean; isFacebook: boolean; isAlamoFire: boolean; isElectron: boolean; silkAccelerated: boolean; browser: string; version: string | number; os: string; platform: string; geoIp: Record<string, string | string[]>; source: string; isWechat: boolean; isWindowsPhone: boolean; electronVersion: string; SilkAccelerated?: boolean; } type HeadersLike = Partial<Record<string, string | string[] | undefined>>; declare class UserAgent { private readonly versions; private readonly browsers; private readonly os; private readonly platform; Agent: AgentDetails; constructor(); reset(): this; testNginxGeoIP(headers: HeadersLike | IncomingHttpHeaders): this; testBot(): void; testSmartTV(): void; testMobile(): void; testAndroidTablet(): void; testTablet(): void; testCompatibilityMode(): void; testSilk(): string | false; testKindleFire(): string | false; testCaptiveNetwork(): string | false; testWebkit(): void; testWechat(): void; parse(source: string): AgentDetails; hydrate(source: string): this; private getBrowser; private getBrowserVersion; private getWechatVersion; private getElectronVersion; private getOS; private getPlatform; } interface UserAgentAugmentedRequest extends Request { useragent?: ReturnType<UserAgent['parse']>; headers: IncomingHttpHeaders & Record<string, string | string[] | undefined>; } declare const useragent: UserAgent; type UserAgentMiddleware = (req: Request, res: Response, next: NextFunction) => void; declare const express: () => UserAgentMiddleware; declare const useragentMiddleware: () => UserAgentMiddleware; export { type AgentDetails, type HeadersLike, UserAgent, type UserAgentAugmentedRequest, type UserAgentMiddleware, useragent as default, express, useragent, useragentMiddleware };