mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 19:09:18 +08:00
[ismobilejs] Fix isMobile typings and tests (#22824)
* Fix isMobile typings and tests * Fix isMobile export
This commit is contained in:
80
types/ismobilejs/index.d.ts
vendored
80
types/ismobilejs/index.d.ts
vendored
@@ -3,41 +3,55 @@
|
||||
// Definitions by: Maksim Karelov <https://github.com/Ty3uK>
|
||||
// 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
|
||||
Reference in New Issue
Block a user