index.d.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /// <reference types="node" />
  2. export declare type DetectedInfoType = 'browser' | 'node' | 'bot-device' | 'bot' | 'react-native';
  3. interface DetectedInfo<T extends DetectedInfoType, N extends string, O, V = null> {
  4. readonly type: T;
  5. readonly name: N;
  6. readonly version: V;
  7. readonly os: O;
  8. }
  9. export declare class BrowserInfo implements DetectedInfo<'browser', Browser, OperatingSystem | null, string> {
  10. readonly name: Browser;
  11. readonly version: string;
  12. readonly os: OperatingSystem | null;
  13. readonly type = "browser";
  14. constructor(name: Browser, version: string, os: OperatingSystem | null);
  15. }
  16. export declare class NodeInfo implements DetectedInfo<'node', 'node', NodeJS.Platform, string> {
  17. readonly version: string;
  18. readonly type = "node";
  19. readonly name: 'node';
  20. readonly os: NodeJS.Platform;
  21. constructor(version: string);
  22. }
  23. export declare class SearchBotDeviceInfo implements DetectedInfo<'bot-device', Browser, OperatingSystem | null, string> {
  24. readonly name: Browser;
  25. readonly version: string;
  26. readonly os: OperatingSystem | null;
  27. readonly bot: string;
  28. readonly type = "bot-device";
  29. constructor(name: Browser, version: string, os: OperatingSystem | null, bot: string);
  30. }
  31. export declare class BotInfo implements DetectedInfo<'bot', 'bot', null, null> {
  32. readonly type = "bot";
  33. readonly bot: true;
  34. readonly name: 'bot';
  35. readonly version: null;
  36. readonly os: null;
  37. }
  38. export declare class ReactNativeInfo implements DetectedInfo<'react-native', 'react-native', null, null> {
  39. readonly type = "react-native";
  40. readonly name: 'react-native';
  41. readonly version: null;
  42. readonly os: null;
  43. }
  44. export declare type Browser = 'aol' | 'edge' | 'edge-ios' | 'yandexbrowser' | 'kakaotalk' | 'samsung' | 'silk' | 'miui' | 'beaker' | 'edge-chromium' | 'chrome' | 'chromium-webview' | 'phantomjs' | 'crios' | 'firefox' | 'fxios' | 'opera-mini' | 'opera' | 'pie' | 'netfront' | 'ie' | 'bb10' | 'android' | 'ios' | 'safari' | 'facebook' | 'instagram' | 'ios-webview' | 'curl' | 'searchbot';
  45. export declare type OperatingSystem = 'iOS' | 'Android OS' | 'BlackBerry OS' | 'Windows Mobile' | 'Amazon OS' | 'Windows 3.11' | 'Windows 95' | 'Windows 98' | 'Windows 2000' | 'Windows XP' | 'Windows Server 2003' | 'Windows Vista' | 'Windows 7' | 'Windows 8' | 'Windows 8.1' | 'Windows 10' | 'Windows ME' | 'Windows CE' | 'Open BSD' | 'Sun OS' | 'Linux' | 'Mac OS' | 'QNX' | 'BeOS' | 'OS/2' | 'Chrome OS';
  46. export declare function detect(userAgent?: string): BrowserInfo | SearchBotDeviceInfo | BotInfo | NodeInfo | ReactNativeInfo | null;
  47. export declare function browserName(ua: string): Browser | null;
  48. export declare function parseUserAgent(ua: string): BrowserInfo | SearchBotDeviceInfo | BotInfo | null;
  49. export declare function detectOS(ua: string): OperatingSystem | null;
  50. export declare function getNodeVersion(): NodeInfo | null;
  51. export {};