diff --git a/types/ismobilejs/index.d.ts b/types/ismobilejs/index.d.ts index c0f7c4ec8b..18eee7ea1a 100644 --- a/types/ismobilejs/index.d.ts +++ b/types/ismobilejs/index.d.ts @@ -3,41 +3,55 @@ // Definitions by: Maksim Karelov // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -export const any: boolean; -export const phone: boolean; -export const tablet: boolean; -export const seven_inch: boolean; +interface Apple { + phone: boolean; + ipod: boolean; + tablet: boolean; + device: boolean; +} -export const apple: { - phone: boolean; - ipod: boolean; - tablet: boolean; - device: boolean; -}; +interface Android { + phone: boolean; + tablet: boolean; + device: boolean; +} -export const android: { - phone: boolean; - tablet: boolean; - device: boolean; -}; +interface Amazon { + phone: boolean; + tablet: boolean; + device: boolean; +} -export const amazon: { - phone: boolean; - tablet: boolean; - device: boolean; -}; +interface Windows { + phone: boolean; + tablet: boolean; + device: boolean; +} -export const windows: { - phone: boolean; - tablet: boolean; - device: boolean; -}; +interface Other { + blackberry_10: boolean; + blackberry: boolean; + opera: boolean; + firefox: boolean; + chrome: boolean; + device: boolean; +} -export const other: { - blackberry_10: boolean; - blackberry: boolean; - opera: boolean; - firefox: boolean; - chrome: boolean; - device: boolean; -}; +interface IsMobile { + any: boolean; + phone: boolean; + tablet: boolean; + seven_inch: boolean; + + apple: Apple; + android: Android; + amazon: Amazon; + windows: Windows; + other: Other; + + (userAgent?: string): IsMobile; +} + +declare const isMobile: IsMobile; + +export = isMobile; diff --git a/types/ismobilejs/ismobilejs-tests.ts b/types/ismobilejs/ismobilejs-tests.ts index e69de29bb2..d53c674da9 100644 --- a/types/ismobilejs/ismobilejs-tests.ts +++ b/types/ismobilejs/ismobilejs-tests.ts @@ -0,0 +1,19 @@ +import * as isMobile from 'ismobilejs'; + +const MOZILLA_ANDROID_UA = 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'; +const MOZILLA_IPHONE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4'; + +const CHROME_ANDROID_UA = 'Mozilla/5.0 (Linux; Android 8.0.0; Pixel Build/OPP3.170518.006) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.66 Mobile Safari/537.36'; +const CHROME_IPHONE_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1'; + +// $ExpectType boolean +isMobile(MOZILLA_ANDROID_UA).android.phone; +// $ExpectType boolean +isMobile(MOZILLA_IPHONE_UA).apple.phone; + +// $ExpectType boolean +isMobile(CHROME_ANDROID_UA).android.phone; +// $ExpectType boolean +isMobile(CHROME_IPHONE_UA).apple.phone; + +console.log(isMobile.apple); diff --git a/types/ismobilejs/tsconfig.json b/types/ismobilejs/tsconfig.json index 3e3a1071d3..ae9975d94e 100644 --- a/types/ismobilejs/tsconfig.json +++ b/types/ismobilejs/tsconfig.json @@ -2,11 +2,13 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../"