UNPKG

@mornya/platform-libs

Version:

Parses UA (user-agent) information of the current platform.

42 lines (41 loc) 1.39 kB
export type OSVendor = 'IOS' | 'AOS' | 'WOS' | 'WIN' | 'MAC' | 'LINUX'; export type BrowserType<T = any> = (T extends string ? T : never) | 'MOBILE' | 'DESKTOP'; export type BrowserVendor<T = any> = (T extends string ? T : never) | 'OPERA' | 'EDGE' | 'CHROME' | 'SAFARI' | 'FIREFOX' | 'IE'; export type Pattern<Key extends string> = { [K in Key]: RegExp[]; }; type Matched<Key extends string> = { name: Key | ''; matches: string[]; }; export type Browser = { type: string; vendor: string; version: string; }; export type Info<BT = any, BV = any> = { UA: { productName: string; productVersion: string; systemInfo: string; extras?: string; }; OS: { vendor: OSVendor | ''; version: string; }; Browser: { type: BrowserType<BT> | ''; vendor: BrowserVendor<BV> | ''; version: string; }; isDesktop: boolean; isMobile: boolean; isAOS: boolean; isIOS: boolean; }; export declare function resolveMatches<Key extends string>(pattern: Pattern<Key>, target: string | undefined): Matched<Key>; export declare function checkVersion(baseVersion: string, currVersion: string): -1 | 0 | 1; export declare function isTouchDevice(): boolean; export declare function getInfo<I extends Info, BV = I extends Info<unknown, infer U2> ? U2 : any>(userAgent: string): I; export {};