From 39bbcac6fa2425ec565103d75f40379b8741af78 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Fri, 2 Apr 2021 02:36:32 +0530 Subject: [PATCH] add types for $.client --- jquery/client.d.ts | 140 +++++++++++++++++++++++++++++++++++++++++++++ jquery/index.d.ts | 1 + package-lock.json | 4 +- package.json | 2 +- 4 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 jquery/client.d.ts diff --git a/jquery/client.d.ts b/jquery/client.d.ts new file mode 100644 index 0000000..0b82e40 --- /dev/null +++ b/jquery/client.d.ts @@ -0,0 +1,140 @@ +declare global { + interface JQueryStatic { + client: Client; + } +} + +interface Client { + /** + * Get an object containing information about the client. + * + * The resulting client object will be in the following format: + * + * { + * 'name': 'firefox', + * 'layout': 'gecko', + * 'layoutVersion': 20101026, + * 'platform': 'linux' + * 'version': '3.5.1', + * 'versionBase': '3', + * 'versionNumber': 3.5, + * } + * + * Example: + * + * if ( $.client.profile().layout == 'gecko' ) { + * // This will only run in Gecko browsers, such as Mozilla Firefox. + * } + * + * var profile = $.client.profile(); + * if ( profile.layout == 'gecko' && profile.platform == 'linux' ) { + * // This will only run in Gecko browsers on Linux. + * } + * + * Recognised browser names: + * + * - `android` (legacy Android browser, prior to Chrome Mobile) + * - `chrome` (includes Chrome Mobile, Microsoft Edge, Opera, and others) + * - `crios` (Chrome on iOS, which uses Mobile Safari) + * - `edge` (legacy Microsoft Edge, which uses EdgeHTML) + * - `firefox` (includes Firefox Mobile, Iceweasel, and others) + * - `fxios` (Firefox on iOS, which uses Mobile Safari) + * - `konqueror` + * - `msie` + * - `opera` (legacy Opera, which uses Presto) + * - `rekonq` + * - `safari` (including Mobile Safari) + * - `silk` + * + * Recognised layout engines: + * + * - `edge` (EdgeHTML 12-18, as used by legacy Microsoft Edge) + * - `gecko` + * - `khtml` + * - `presto` + * - `trident` + * - `webkit` + * + * Note that Chrome and Chromium-based browsers like Opera have their layout + * engine identified as `webkit`. + * + * Recognised platforms: + * + * - `ipad` + * - `iphone` + * - `linux` + * - `mac` + * - `solaris` (untested) + * - `win` + * + * @param {Object} [nav] An object with a 'userAgent' and 'platform' property. + * Defaults to the global `navigator` object. + * @return {Object} The client object + */ + profile(nav?: { userAgent: string; platform: string }): ClientProfile; + + /** + * Checks the current browser against a support map object. + * + * Version numbers passed as numeric values will be compared like numbers (1.2 > 1.11). + * Version numbers passed as string values will be compared using a simple component-wise + * algorithm, similar to PHP's version_compare ('1.2' < '1.11'). + * + * A browser map is in the following format: + * + * { + * // Multiple rules with configurable operators + * 'msie': [['>=', 7], ['!=', 9]], + * // Match no versions + * 'iphone': false, + * // Match any version + * 'android': null + * } + * + * It can optionally be split into ltr/rtl sections: + * + * { + * 'ltr': { + * 'android': null, + * 'iphone': false + * }, + * 'rtl': { + * 'android': false, + * // rules are not inherited from ltr + * 'iphone': false + * } + * } + * + * @param {Object} map Browser support map + * @param {Object} [profile] A client-profile object + * @param {boolean} [exactMatchOnly=false] Only return true if the browser is matched, + * otherwise returns true if the browser is not found. + * + * @return {boolean} The current browser is in the support map + */ + test(map: any, profile?: ClientProfile, exactMatchOnly?: boolean): boolean; +} + +interface ClientProfile { + name: + | "android" + | "chrome" + | "crios" + | "edge" + | "firefox" + | "fxios" + | "konqueror" + | "msie" + | "opera" + | "rekong" + | "safari" + | "silk"; + layout: "edge" | "gecko" | "khtml" | "presto" | "trident" | "webkit"; + layoutVersion: number; + platform: "ipad" | "iphone" | "linux" | "mac" | "solaris" | "win"; + version: string; + versionBase: string; + versionNumber: number; +} + +export {}; diff --git a/jquery/index.d.ts b/jquery/index.d.ts index a51dd5f..ce7413a 100644 --- a/jquery/index.d.ts +++ b/jquery/index.d.ts @@ -2,3 +2,4 @@ import "jquery"; import "./textSelection"; import "./collapsibleTabs"; +import "./client"; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8de599a..55ba5a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "types-mediawiki", - "version": "0.8.0", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.8.0", + "version": "1.1.0", "license": "GPL-3.0-or-later", "dependencies": { "@types/jquery": "^3.5.5" diff --git a/package.json b/package.json index 99d28ee..3b7af10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "types-mediawiki", - "version": "1.0.0", + "version": "1.1.0", "description": "TypeScript definitions for MediaWiki JS interface", "types": "index.d.ts", "scripts": {