1
0
mirror of https://github.com/lancedikson/bowser synced 2025-12-05 06:02:14 +00:00

Fix TypeScript definitions to resolve TS2309 and TS2451 errors

Co-authored-by: naorpeled <6171622+naorpeled@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-28 23:52:57 +00:00
parent 8d01b928c5
commit 759ec75e33

569
index.d.ts vendored
View File

@ -2,321 +2,294 @@
// Project: https://github.com/lancedikson/bowser // Project: https://github.com/lancedikson/bowser
// Definitions by: Alexander P. Cerutti <https://github.com/alexandercerutti>, // Definitions by: Alexander P. Cerutti <https://github.com/alexandercerutti>,
export = Bowser;
export as namespace Bowser; export as namespace Bowser;
export function getParser(UA: string, skipParsing?: boolean): Bowser.Parser.Parser; export function getParser(UA: string, skipParsing?: boolean): Parser.Parser;
export function parse(UA: string): Bowser.Parser.ParsedResult; export function parse(UA: string): Parser.ParsedResult;
export const BROWSER_MAP: Record<string, string>; export const BROWSER_MAP: Record<string, string>;
export const ENGINE_MAP: Record<string, string>; export const ENGINE_MAP: Record<string, string>;
export const OS_MAP: Record<string, string>; export const OS_MAP: Record<string, string>;
export const PLATFORMS_MAP: Record<string, string>; export const PLATFORMS_MAP: Record<string, string>;
declare namespace Bowser { export namespace Parser {
/** interface Parser {
* Creates a Parser instance constructor(UA: string, skipParsing?: boolean): Parser.Parser;
* @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; /**
* Check if the version is equals the browser version
/** * @param version The string to compare with the browser version
* Constants exposed via bowser getters * @returns {boolean}
*/ */
const BROWSER_MAP: Record<string, string>;
const ENGINE_MAP: Record<string, string>;
const OS_MAP: Record<string, string>;
const PLATFORMS_MAP: Record<string, string>;
namespace Parser {
interface Parser {
constructor(UA: string, skipParsing?: boolean): Parser.Parser;
/** compareVersion(version: string): boolean;
* Check if the version is equals the browser version
* @param version The string to compare with the browser version
* @returns {boolean}
*/
compareVersion(version: string): boolean;
/**
* Get parsed browser object
* @return {BrowserDetails} Browser's details
*/
getBrowser(): BrowserDetails;
/**
* Get browser's name
* @param {Boolean} [toLowerCase] return lower-cased value
* @return {String} Browser's name or an empty string
*/
getBrowserName(toLowerCase?: boolean): string;
/**
* Get browser's version
* @return {String} version of browser
*/
getBrowserVersion(): string | undefined;
/**
* Get OS
* @return {OSDetails} - OS Details
*
* @example
* this.getOS(); // {
* // name: 'macOS',
* // version: '10.11.12',
* // }
*/
getOS(): OSDetails;
/**
* 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 OS version
* @return {String} full version with dots ('10.11.12', '5.6', etc)
*/
getOSVersion(): string;
/** /**
* Get parsed platform * Get parsed browser object
* @returns {PlatformDetails} * @return {BrowserDetails} Browser's details
*/ */
getPlatform(): PlatformDetails;
/** getBrowser(): BrowserDetails;
* Get platform name
* @param {boolean} toLowerCase
*/
getPlatformType(toLowerCase?: boolean): string; /**
* Get browser's name
* @param {Boolean} [toLowerCase] return lower-cased value
* @return {String} Browser's name or an empty string
*/
/** getBrowserName(toLowerCase?: boolean): string;
* Get parsed engine
* @returns {EngineDetails}
*/
getEngine(): EngineDetails; /**
* Get browser's version
* @return {String} version of browser
*/
/** getBrowserVersion(): string | undefined;
* Get parsed engine's name
* @returns {String} Engine's name or an empty string
*/
getEngineName(): string; /**
* Get OS
* @return {OSDetails} - OS Details
*
* @example
* this.getOS(); // {
* // name: 'macOS',
* // version: '10.11.12',
* // }
*/
/** getOS(): OSDetails;
* Get parsed result
* @return {ParsedResult}
*/
getResult(): ParsedResult;
/**
* Get UserAgent string of current Parser instance
* @return {String} User-Agent String of the current <Parser> object
*/
getUA(): string;
/**
* Is anything? Check if the browser is called "anything",
* the OS called "anything" or the platform called "anything"
* @param {String} anything
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {Boolean}
*/
is(anything: any, includingAlias?: boolean): boolean;
/**
* Check if the browser name equals the passed string
* @param browserName The string to compare with the browser name
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {boolean}
*/
isBrowser(browserName: string, includingAlias?: boolean): boolean;
/**
* Check if the engine name equals the passed string
* @param engineName The string to compare with the engine name
* @returns {boolean}
*/
isEngine(engineName: string): boolean;
/**
* Check if the OS name equals the passed string
* @param OSName The string to compare with the OS name
* @returns {boolean}
*/
isOS(OSName: string): boolean;
/**
* Check if the platform name equals the passed string
* @param platformName The string to compare with the platform name
* @returns {boolean}
*/
isPlatform(platformName: string): boolean; /**
* Get OS name
/** * @param {Boolean} [toLowerCase] return lower-cased value
* Parse full information about the browser * @return {String} name of the OS macOS, Windows, Linux, etc.
* @returns {Parser.Parser} */
*/
getOSName(toLowerCase?: boolean): string;
parse(): Parser.Parser;
/**
/** * Get OS version
* Get parsed browser object * @return {String} full version with dots ('10.11.12', '5.6', etc)
* @returns {BrowserDetails} */
*/
getOSVersion(): string;
parseBrowser(): BrowserDetails;
/**
/** * Get parsed platform
* Get parsed engine * @returns {PlatformDetails}
* @returns {EngineDetails} */
*/
getPlatform(): PlatformDetails;
parseEngine(): EngineDetails;
/**
/** * Get platform name
* Parse OS and save it to this.parsedResult.os * @param {boolean} toLowerCase
* @returns {OSDetails} */
*/
getPlatformType(toLowerCase?: boolean): string;
parseOS(): OSDetails;
/**
/** * Get parsed engine
* Get parsed platform * @returns {EngineDetails}
* @returns {PlatformDetails} */
*/
getEngine(): EngineDetails;
parsePlatform(): PlatformDetails;
/**
/** * Get parsed engine's name
* Check if parsed browser matches certain conditions * @returns {String} Engine's name or an empty string
* */
* @param {checkTree} checkTree It's one or two layered object,
* which can include a platform or an OS on the first layer getEngineName(): string;
* and should have browsers specs on the bottom-laying layer
* /**
* @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not. * Get parsed result
* Returns `undefined` when the browser is no described in the checkTree object. * @return {ParsedResult}
* */
* @example
* const browser = new Bowser(UA); getResult(): ParsedResult;
* if (browser.check({chrome: '>118.01.1322' }))
* // or with os /**
* if (browser.check({windows: { chrome: '>118.01.1322' } })) * Get UserAgent string of current Parser instance
* // or with platforms * @return {String} User-Agent String of the current <Parser> object
* if (browser.check({desktop: { chrome: '>118.01.1322' } })) */
*/
getUA(): string;
satisfies(checkTree: checkTree): boolean | undefined;
/**
/** * Is anything? Check if the browser is called "anything",
* Check if the browser name equals the passed string * the OS called "anything" or the platform called "anything"
* @param {string} browserName The string to compare with the browser name * @param {String} anything
* @param [includingAlias=false] The flag showing whether alias will be included into comparison * @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {boolean} * @returns {Boolean}
*/ */
isBrowser(browserName: string, includingAlias?: boolean): boolean; is(anything: any, includingAlias?: boolean): boolean;
/** /**
* Check if the engine name equals the passed string * Check if the browser name equals the passed string
* @param {string} engineName The string to compare with the engine name * @param browserName The string to compare with the browser name
* @returns {boolean} * @param [includingAlias=false] The flag showing whether alias will be included into comparison
*/ * @returns {boolean}
*/
isEngine(engineName: string): boolean;
isBrowser(browserName: string, includingAlias?: boolean): boolean;
/**
* Check if the platform type equals the passed string /**
* @param {string} platformType The string to compare with the platform type * Check if the engine name equals the passed string
* @returns {boolean} * @param engineName The string to compare with the engine name
*/ * @returns {boolean}
*/
isPlatform(platformType: string): boolean;
isEngine(engineName: string): boolean;
/**
* Check if the OS name equals the passed string /**
* @param {string} osName The string to compare with the OS name * Check if the OS name equals the passed string
* @returns {boolean} * @param OSName The string to compare with the OS name
*/ * @returns {boolean}
*/
isOS(osName: string): boolean;
isOS(OSName: string): boolean;
/**
* Check if any of the given values satisfies `.is(anything)` /**
* @param {string[]} anythings * Check if the platform name equals the passed string
* @returns {boolean} true if at least one condition is satisfied, false otherwise. * @param platformName The string to compare with the platform name
*/ * @returns {boolean}
*/
some(anythings: string[]): boolean | undefined;
isPlatform(platformName: string): boolean;
/**
* Test a UA string for a regexp /**
* @param regex * Parse full information about the browser
* @returns {boolean} true if the regex matches the UA, false otherwise. * @returns {Parser.Parser}
*/ */
test(regex: RegExp): boolean; parse(): Parser.Parser;
}
/**
interface ParsedResult { * Get parsed browser object
browser: BrowserDetails; * @returns {BrowserDetails}
os: OSDetails; */
platform: PlatformDetails;
engine: EngineDetails; parseBrowser(): BrowserDetails;
}
/**
interface Details { * Get parsed engine
name?: string; * @returns {EngineDetails}
version?: string; */
}
parseEngine(): EngineDetails;
interface OSDetails extends Details {
versionName?: string; /**
} * Parse OS and save it to this.parsedResult.os
* @returns {OSDetails}
interface PlatformDetails { */
type?: string;
vendor?: string; parseOS(): OSDetails;
model?: string;
} /**
* Get parsed platform
type BrowserDetails = Details; * @returns {PlatformDetails}
type EngineDetails = Details; */
interface checkTree { parsePlatform(): PlatformDetails;
[key: string]: any;
} /**
* Check if parsed browser matches certain conditions
*
* @param {checkTree} checkTree It's one or two layered object,
* which can include a platform or an OS on the first layer
* and should have browsers specs on the bottom-laying layer
*
* @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
* Returns `undefined` when the browser is no described in the checkTree object.
*
* @example
* const browser = new Bowser(UA);
* if (browser.check({chrome: '>118.01.1322' }))
* // or with os
* if (browser.check({windows: { chrome: '>118.01.1322' } }))
* // or with platforms
* if (browser.check({desktop: { chrome: '>118.01.1322' } }))
*/
satisfies(checkTree: checkTree): boolean | undefined;
/**
* Check if the browser name equals the passed string
* @param {string} browserName The string to compare with the browser name
* @param [includingAlias=false] The flag showing whether alias will be included into comparison
* @returns {boolean}
*/
isBrowser(browserName: string, includingAlias?: boolean): boolean;
/**
* Check if the engine name equals the passed string
* @param {string} engineName The string to compare with the engine name
* @returns {boolean}
*/
isEngine(engineName: string): boolean;
/**
* Check if the platform type equals the passed string
* @param {string} platformType The string to compare with the platform type
* @returns {boolean}
*/
isPlatform(platformType: string): boolean;
/**
* Check if the OS name equals the passed string
* @param {string} osName The string to compare with the OS name
* @returns {boolean}
*/
isOS(osName: string): boolean;
/**
* Check if any of the given values satisfies `.is(anything)`
* @param {string[]} anythings
* @returns {boolean} true if at least one condition is satisfied, false otherwise.
*/
some(anythings: string[]): boolean | undefined;
/**
* Test a UA string for a regexp
* @param regex
* @returns {boolean} true if the regex matches the UA, false otherwise.
*/
test(regex: RegExp): boolean;
}
interface ParsedResult {
browser: BrowserDetails;
os: OSDetails;
platform: PlatformDetails;
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;
} }
} }