From 07462efb6a92a1872a0617c0e45488072106d524 Mon Sep 17 00:00:00 2001 From: Amelie <35846199+cwenwen@users.noreply.github.com> Date: Sat, 18 Nov 2023 03:01:45 +0800 Subject: [PATCH] feat: update types of parser methods (#449) --- index.d.ts | 38 ++++++++++++++++++++++++++++++++++++-- src/parser.js | 17 ++++++++++++++++- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 794328a..d5b72c4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -138,10 +138,11 @@ declare namespace Bowser { * 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): boolean; + is(anything: any, includingAlias?: boolean): boolean; /** * Check if the browser name equals the passed string @@ -233,7 +234,40 @@ declare namespace Bowser { satisfies(checkTree: checkTree): boolean | undefined; /** - * Check if any of the given values satifies `.is(anything)` + * 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. */ diff --git a/src/parser.js b/src/parser.js index 8cebb3e..db10657 100644 --- a/src/parser.js +++ b/src/parser.js @@ -408,7 +408,7 @@ class Parser { /** * Check if the browser name equals the passed string - * @param browserName The string to compare with the browser name + * @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} */ @@ -459,14 +459,29 @@ class Parser { ) > -1; } + /** + * Check if the OS name equals the passed string + * @param {string} osName The string to compare with the OS name + * @returns {boolean} + */ isOS(osName) { return this.getOSName(true) === String(osName).toLowerCase(); } + /** + * Check if the platform type equals the passed string + * @param {string} platformType The string to compare with the platform type + * @returns {boolean} + */ isPlatform(platformType) { return this.getPlatformType(true) === String(platformType).toLowerCase(); } + /** + * Check if the engine name equals the passed string + * @param {string} engineName The string to compare with the engine name + * @returns {boolean} + */ isEngine(engineName) { return this.getEngineName(true) === String(engineName).toLowerCase(); }