Export Parser types

- Move the Parser namespace into the Bowser namespace
- Make the Parser class an interface so consumers can't construct a Parser class (this is not exported by bowser)
pull/289/head
Jace 5 years ago
parent 13e178ccce
commit 96510405be
No known key found for this signature in database
GPG Key ID: 270028FF4C46FF51

403
index.d.ts vendored

@ -6,219 +6,218 @@ export = Bowser;
export as namespace Bowser; export as namespace Bowser;
declare namespace Bowser { declare namespace Bowser {
/**
* Creates a Parser instance
* @param {string} UA - User agent string
* @param {boolean} skipParsing
*/
/** function getParser(UA: string, skipParsing?: boolean): Parser.Parser;
* Creates a Parser instance
* @param {string} UA - User agent string
* @param {boolean} skipParsing
*/
function getParser(UA: string, skipParsing?: boolean): Parser.Parser; /**
* Creates a Parser instance and runs Parser.getResult immediately
* @param UA - User agent string
* @returns {Parser.ParsedResult}
*/
/** function parse(UA: string): Parser.ParsedResult;
* Creates a Parser instance and runs Parser.getResult immediately
* @param UA - User agent string
* @returns {Parser.ParsedResult}
*/
function parse(UA: string): Parser.ParsedResult; namespace Parser {
} interface Parser {
constructor(UA: string, skipParsing?: boolean): Parser.Parser;
declare namespace Parser {
class Parser {
constructor(UA: string, skipParsing?: boolean);
/**
* Get parsed browser object
* @return {BrowserDetails} Browser's details
*/
getBrowser(): BrowserDetails;
/**
* Get browser's name
* @return {String} Browser's name or an empty string
*/
getBrowserName(): string;
/**
* Get browser's version
* @return {String} version of browser
*/
getBrowserVersion(): string; /**
* Get parsed browser object
* @return {BrowserDetails} Browser's details
*/
/** getBrowser(): BrowserDetails;
* Get OS
* @return {OSDetails} - OS Details
*
* @example
* this.getOS(); // {
* // name: 'macOS',
* // version: '10.11.12',
* // }
*/
getOS(): OSDetails; /**
* Get browser's name
* @return {String} Browser's name or an empty string
*/
/** getBrowserName(): string;
* Get OS name
* @param {Boolean} [toLowerCase] return lower-cased value
* @return {String} name of the OS macOS, Windows, Linux, etc.
*/
getOSName(toLowerCase?: boolean): string; /**
* Get browser's version
* @return {String} version of browser
*/
/** getBrowserVersion(): string;
* Get OS version
* @return {String} full version with dots ('10.11.12', '5.6', etc)
*/
getOSVersion(): string;
/** /**
* Get parsed platform * Get OS
* @returns {PlatformDetails} * @return {OSDetails} - OS Details
*/ *
* @example
* this.getOS(); // {
* // name: 'macOS',
* // version: '10.11.12',
* // }
*/
getPlatform(): PlatformDetails; getOS(): OSDetails;
/** /**
* Get platform name * Get OS name
* @param {boolean} toLowerCase * @param {Boolean} [toLowerCase] return lower-cased value
*/ * @return {String} name of the OS macOS, Windows, Linux, etc.
*/
getPlatformType(toLowerCase?: boolean): string;
getOSName(toLowerCase?: boolean): string;
/**
* Get parsed engine /**
* @returns {EngineDetails} * Get OS version
*/ * @return {String} full version with dots ('10.11.12', '5.6', etc)
*/
getEngine(): EngineDetails;
getOSVersion(): string;
/**
* Get parsed result /**
* @return {ParsedResult} * Get parsed platform
*/ * @returns {PlatformDetails}
*/
getResult(): ParsedResult;
getPlatform(): PlatformDetails;
/**
* Get UserAgent string of current Parser instance /**
* @return {String} User-Agent String of the current <Parser> object * Get platform name
*/ * @param {boolean} toLowerCase
*/
getUA(): string;
getPlatformType(toLowerCase?: boolean): string;
/**
* Is anything? Check if the browser is called "anything", /**
* the OS called "anything" or the platform called "anything" * Get parsed engine
* @param {String} anything * @returns {EngineDetails}
* @returns {Boolean} */
*/
getEngine(): EngineDetails;
is(anything: any): boolean;
/**
/** * Get parsed result
* Parse full information about the browser * @return {ParsedResult}
*/ */
parse(): void; getResult(): ParsedResult;
/** /**
* Get parsed browser object * Get UserAgent string of current Parser instance
* @returns {BrowserDetails} * @return {String} User-Agent String of the current <Parser> object
*/ */
parseBrowser(): BrowserDetails; getUA(): string;
/** /**
* Get parsed engine * Is anything? Check if the browser is called "anything",
* @returns {EngineDetails} * the OS called "anything" or the platform called "anything"
*/ * @param {String} anything
* @returns {Boolean}
parseEngine(): EngineDetails; */
/** is(anything: any): boolean;
* Parse OS and save it to this.parsedResult.os
* @returns {OSDetails} /**
*/ * Parse full information about the browser
*/
parseOS(): OSDetails;
parse(): void;
/**
* Get parsed platform /**
* @returns {PlatformDetails} * Get parsed browser object
*/ * @returns {BrowserDetails}
*/
parsePlatform(): PlatformDetails;
parseBrowser(): BrowserDetails;
/**
* Check if parsed browser matches certain conditions /**
* * Get parsed engine
* @param {checkTree} checkTree It's one or two layered object, * @returns {EngineDetails}
* which can include a platform or an OS on the first layer */
* and should have browsers specs on the bottom-laying layer
* parseEngine(): EngineDetails;
* @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
* Returns `undefined` when the browser is no described in the checkTree object. /**
* * Parse OS and save it to this.parsedResult.os
* @example * @returns {OSDetails}
* const browser = new Bowser(UA); */
* if (browser.check({chrome: '>118.01.1322' }))
* // or with os parseOS(): OSDetails;
* if (browser.check({windows: { chrome: '>118.01.1322' } }))
* // or with platforms /**
* if (browser.check({desktop: { chrome: '>118.01.1322' } })) * Get parsed platform
*/ * @returns {PlatformDetails}
*/
satisfies(checkTree: checkTree): boolean | undefined;
parsePlatform(): PlatformDetails;
/**
* Check if any of the given values satifies `.is(anything)` /**
* @param {string[]} anythings * Check if parsed browser matches certain conditions
* @returns {boolean} true if at least one condition is satisfied, false otherwise. *
*/ * @param {checkTree} checkTree It's one or two layered object,
* which can include a platform or an OS on the first layer
some(anythings: string[]): boolean | undefined; * and should have browsers specs on the bottom-laying layer
*
/** * @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
* Test a UA string for a regexp * Returns `undefined` when the browser is no described in the checkTree object.
* @param regex *
* @returns {boolean} true if the regex matches the UA, false otherwise. * @example
*/ * const browser = new Bowser(UA);
* if (browser.check({chrome: '>118.01.1322' }))
test(regex: RegExp): boolean; * // or with os
} * if (browser.check({windows: { chrome: '>118.01.1322' } }))
* // or with platforms
interface ParsedResult { * if (browser.check({desktop: { chrome: '>118.01.1322' } }))
browser: BrowserDetails; */
os: OSDetails;
platform: PlatformDetails; satisfies(checkTree: checkTree): boolean | undefined;
engine: EngineDetails;
} /**
* Check if any of the given values satifies `.is(anything)`
interface Details { * @param {string[]} anythings
name?: string; * @returns {boolean} true if at least one condition is satisfied, false otherwise.
version?: string; */
}
some(anythings: string[]): boolean | undefined;
interface OSDetails extends Details {
versionName?: string; /**
} * Test a UA string for a regexp
* @param regex
interface PlatformDetails { * @returns {boolean} true if the regex matches the UA, false otherwise.
type?: string; */
vendor?: string;
model?: string; test(regex: RegExp): boolean;
} }
type BrowserDetails = Details; interface ParsedResult {
type EngineDetails = Details; browser: BrowserDetails;
os: OSDetails;
interface checkTree { platform: PlatformDetails;
[key: string]: any; engine: EngineDetails;
} }
interface Details {
name?: string;
version?: string;
}
interface OSDetails extends Details {
versionName?: string;
}
interface PlatformDetails {
type?: string;
vendor?: string;
model?: string;
}
type BrowserDetails = Details;
type EngineDetails = Details;
interface checkTree {
[key: string]: any;
}
}
} }

Loading…
Cancel
Save