Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose all types #40

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1a6e1a4
Move basic types to `mw/utils`
Mar 12, 2024
0c232e3
Import `utils`
Mar 12, 2024
a97b35a
Expose `mw` types
Mar 12, 2024
d09b847
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Mar 12, 2024
933b8b8
Add missing deprecation annotations
Mar 12, 2024
bc0b9e1
Expose remaining types
Mar 13, 2024
a947599
Remove remaining imports
Mar 13, 2024
39a2cf6
Expose and rename API types
Mar 15, 2024
59235c5
Export `mw` from root
Mar 15, 2024
4fb95c1
Revert `api_params` semantic changes
Mar 18, 2024
d0af9fa
Synchronize type names with 1.42
May 5, 2024
11ff428
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Jun 4, 2024
c759e87
move JQuery.Tipsy.Direction sub-types
Oct 9, 2024
ed137c8
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Oct 9, 2024
cee15b8
fix mw.notification link
Oct 9, 2024
ec75f59
Cleanup mw namespace
Oct 9, 2024
c9be9d0
Revert `api_params` changes
Oct 14, 2024
e381261
Revert `api-types-generator.js` changes
Oct 14, 2024
f0e985e
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Oct 23, 2024
2956e76
Use `export default` instead of `export =`
Oct 30, 2024
35b1721
`mw.api`: Rename `Response` to `UnknownResponse`
Nov 2, 2024
a0cc94a
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Derugon Dec 15, 2024
a0c7362
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Derugon Dec 23, 2024
cc2b136
Merge branch 'main' of https://github.com/wikimedia-gadgets/types-med…
Derugon Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "./mw";
import "./jquery";
import "./vue";

export default mw;
371 changes: 193 additions & 178 deletions jquery/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,192 +5,207 @@ declare global {
*
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html
*/
client: Client;
client: JQuery.Client;
}
}

interface Client {
/**
* Get an object containing information about the client.
*
* The resulting client object will be in the following format:
*
* ```js
* {
* 'name': 'firefox',
* 'layout': 'gecko',
* 'layoutVersion': 20101026,
* 'platform': 'linux'
* 'version': '3.5.1',
* 'versionBase': '3',
* 'versionNumber': 3.5,
* }
* ```
*
* @example
* ```js
* 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.
* }
* ```
* @param {ClientNavigator} [nav] An object with a 'userAgent' and 'platform' property.
* Defaults to the global `navigator` object.
* @returns {ClientProfile} The client object
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.profile
*/
profile(nav?: ClientNavigator): ClientProfile;
namespace JQuery {
interface Client {
/**
* Get an object containing information about the client.
*
* The resulting client object will be in the following format:
*
* ```js
* {
* 'name': 'firefox',
* 'layout': 'gecko',
* 'layoutVersion': 20101026,
* 'platform': 'linux'
* 'version': '3.5.1',
* 'versionBase': '3',
* 'versionNumber': 3.5,
* }
* ```
*
* @example
* ```js
* 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.
* }
* ```
* @param {Client.Navigator} [nav] An object with a 'userAgent' and 'platform' property.
* Defaults to the global `navigator` object.
* @returns {Client.Profile} The client object
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.profile
*/
profile(nav?: Client.Navigator): Client.Profile;

/**
* 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:
*
* ```js
* {
* // 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:
*
* ```js
* {
* 'ltr': {
* 'android': null,
* 'iphone': false
* },
* 'rtl': {
* 'android': false,
* // rules are not inherited from ltr
* 'iphone': false
* }
* }
* ```
*
* @param {ClientSupportMap} map Browser support map
* @param {ClientProfile} [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.
* @returns {boolean} The current browser is in the support map
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.test
*/
test(map: ClientSupportMap, profile?: ClientProfile, exactMatchOnly?: boolean): boolean;
}
/**
* 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:
*
* ```js
* {
* // 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:
*
* ```js
* {
* 'ltr': {
* 'android': null,
* 'iphone': false
* },
* 'rtl': {
* 'android': false,
* // rules are not inherited from ltr
* 'iphone': false
* }
* }
* ```
*
* @param {Client.SupportMap} map Browser support map
* @param {Client.Profile} [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.
* @returns {boolean} The current browser is in the support map
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.test
*/
test(
map: Client.SupportMap,
profile?: Client.Profile,
exactMatchOnly?: boolean
): boolean;
}

export interface ClientNavigator {
platform: string;
userAgent: string;
}
namespace Client {
interface Navigator {
platform: string;
userAgent: string;
}

type ComparisonOperator = "==" | "===" | "!=" | "!==" | "<" | "<=" | ">" | ">=";

type SupportMap = SupportMap.Undirected | Record<"ltr" | "rtl", SupportMap.Undirected>;

type ClientProfileLayout = "edge" | "gecko" | "khtml" | "presto" | "trident" | "webkit";
type ClientProfileName =
| "android"
| "chrome"
| "crios"
| "edge"
| "firefox"
| "fxios"
| "konqueror"
| "msie"
| "opera"
| "rekong"
| "safari"
| "silk";
type ClientProfilePlatform = "ipad" | "iphone" | "linux" | "mac" | "solaris" | "win";
namespace SupportMap {
type Condition = [ComparisonOperator, string | number];

type ComparisonOperator = "==" | "===" | "!=" | "!==" | "<" | "<=" | ">" | ">=";
type ClientSupportCondition = [ComparisonOperator, string | number];
type Undirected = Partial<Record<Profile.Name, false | null | Condition[]>>;
}

type UndirectedClientSupportMap = Partial<
Record<ClientProfileName, false | null | ClientSupportCondition[]>
>;
type ClientSupportMap =
| UndirectedClientSupportMap
| Record<"ltr" | "rtl", UndirectedClientSupportMap>;
/**
* An object containing information about the client.
*
* @example
* ```js
* {
* 'name': 'firefox',
* 'layout': 'gecko',
* 'layoutVersion': 20101026,
* 'platform': 'linux'
* 'version': '3.5.1',
* 'versionBase': '3',
* 'versionNumber': 3.5,
* }
* ```
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.Profile
*/
interface Profile {
/**
* Name of the layout engine. 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`.
*/
layout: Profile.Layout | "unknown";
/**
* Version of the layout engine,
* e.g. `6` or `20101026`.
*/
layoutVersion: number | "unknown";
/**
* Name of the browser. Recognized 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`
*/
name: Profile.Name | "unknown";
/**
* Operating system the browser is running on.
* Recognised platforms:
*
* - `ipad`
* - `iphone`
* - `linux`
* - `mac`
* - `solaris` (untested)
* - `win`
*/
platform: Profile.Platform | "unknown";
version: string;
versionBase: string;
versionNumber: number;
}

/**
* An object containing information about the client.
*
* @example
* ```js
* {
* 'name': 'firefox',
* 'layout': 'gecko',
* 'layoutVersion': 20101026,
* 'platform': 'linux'
* 'version': '3.5.1',
* 'versionBase': '3',
* 'versionNumber': 3.5,
* }
* ```
* @see https://doc.wikimedia.org/jquery-client/master/jQuery.client.html#.Profile
*/
interface ClientProfile {
/**
* Name of the layout engine. 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`.
*/
layout: ClientProfileLayout | "unknown";
/**
* Version of the layout engine,
* e.g. `6` or `20101026`.
*/
layoutVersion: number | "unknown";
/**
* Name of the browser. Recognized 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`
*/
name: ClientProfileName | "unknown";
/**
* Operating system the browser is running on.
* Recognised platforms:
*
* - `ipad`
* - `iphone`
* - `linux`
* - `mac`
* - `solaris` (untested)
* - `win`
*/
platform: ClientProfilePlatform | "unknown";
version: string;
versionBase: string;
versionNumber: number;
namespace Profile {
type Layout = "edge" | "gecko" | "khtml" | "presto" | "trident" | "webkit";

type Name =
| "android"
| "chrome"
| "crios"
| "edge"
| "firefox"
| "fxios"
| "konqueror"
| "msie"
| "opera"
| "rekong"
| "safari"
| "silk";

type Platform = "ipad" | "iphone" | "linux" | "mac" | "solaris" | "win";
}
}
}
}

/** @deprecated Use {@link JQuery.Client.Navigator} instead */
export type ClientNavigator = JQuery.Client.Navigator;

export {};
Loading
Loading