From 21162f127745bef088d4ecb7fd93e27bc43a6dfb Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Sat, 22 Jun 2024 22:26:58 +0700 Subject: [PATCH] BREAKING CHANGE - Rename `isChromiumBased` -> `isChromeFamily` & `isPWA` -> `isStandalonePWA` --- src/helpers/ua-parser-helpers.d.ts | 8 ++++---- src/helpers/ua-parser-helpers.js | 8 ++++---- test/dts-test.ts | 4 ++-- test/mocha-test-helpers.js | 8 ++++---- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/helpers/ua-parser-helpers.d.ts b/src/helpers/ua-parser-helpers.d.ts index f467c31..905e5ed 100644 --- a/src/helpers/ua-parser-helpers.d.ts +++ b/src/helpers/ua-parser-helpers.d.ts @@ -5,13 +5,13 @@ import { IResult } from "../main/ua-parser"; declare function isAppleSilicon(res: IResult): boolean; -declare function isChromiumBased(res: IResult): boolean; +declare function isChromeFamily(res: IResult): boolean; declare function isFrozenUA(ua: string): boolean; -declare function isPWA(): boolean; +declare function isStandalonePWA(): boolean; export { isAppleSilicon, - isChromiumBased, + isChromeFamily, isFrozenUA, - isPWA + isStandalonePWA } \ No newline at end of file diff --git a/src/helpers/ua-parser-helpers.js b/src/helpers/ua-parser-helpers.js index a862ec5..74923e1 100644 --- a/src/helpers/ua-parser-helpers.js +++ b/src/helpers/ua-parser-helpers.js @@ -11,11 +11,11 @@ const { CPU, OS, Engine } = require('../enums/ua-parser-enums'); const isAppleSilicon = (res) => res.os.is(OS.MACOS) && res.cpu.is(CPU.ARM); -const isChromiumBased = (res) => res.engine.is(Engine.BLINK); +const isChromeFamily = (res) => res.engine.is(Engine.BLINK); const isFrozenUA = (ua) => /^Mozilla\/5\.0 \((Windows NT 10\.0; Win64; x64|Macintosh; Intel Mac OS X 10_15_7|X11; Linux x86_64|X11; CrOS x86_64 14541\.0\.0|Fuchsia|Linux; Android 10; K)\) AppleWebKit\/537\.36 \(KHTML, like Gecko\) Chrome\/\d+\.0\.0\.0 (Mobile )?Safari\/537\.36/.test(ua); -const isPWA = () => window && (window.matchMedia('(display-mode: standalone)').matches || +const isStandalonePWA = () => window && (window.matchMedia('(display-mode: standalone)').matches || // iOS navigator.standalone || // Android @@ -27,7 +27,7 @@ const isPWA = () => window && (window.matchMedia('(display-mode: standalone)').m module.exports = { isAppleSilicon, - isChromiumBased, + isChromeFamily, isFrozenUA, - isPWA + isStandalonePWA } \ No newline at end of file diff --git a/test/dts-test.ts b/test/dts-test.ts index e5c5065..edf1d47 100644 --- a/test/dts-test.ts +++ b/test/dts-test.ts @@ -1,6 +1,6 @@ import { expectType } from 'tsd'; import { UAParser, IResult, IBrowser, ICPU, IEngine, IDevice, IOS } from "../src/main/ua-parser"; -import { isAppleSilicon, isChromiumBased } from "../src/helpers/ua-parser-helpers"; +import { isAppleSilicon, isChromeFamily } from "../src/helpers/ua-parser-helpers"; const uastring = 'Mozilla/5.0 (X11; MyCustomOS; Linux i686; rv:19.0) Gecko/20100101 Firefox/19.0'; const extensions = { @@ -46,4 +46,4 @@ expectType(parser.setUA(uastring)); const result = parser.getResult(); expectType(isAppleSilicon(result)); -expectType(isChromiumBased(result)); \ No newline at end of file +expectType(isChromeFamily(result)); \ No newline at end of file diff --git a/test/mocha-test-helpers.js b/test/mocha-test-helpers.js index faacf61..1cfffea 100644 --- a/test/mocha-test-helpers.js +++ b/test/mocha-test-helpers.js @@ -1,6 +1,6 @@ const assert = require('assert'); const { UAParser } = require('../src/main/ua-parser'); -const { isAppleSilicon, isChromiumBased } = require('../src/helpers/ua-parser-helpers'); +const { isAppleSilicon, isChromeFamily } = require('../src/helpers/ua-parser-helpers'); describe('isAppleSilicon', () => { it('Can detect Apple Silicon device', () => { @@ -14,13 +14,13 @@ describe('isAppleSilicon', () => { }); }); -describe('isChromiumBased', () => { +describe('isChromeFamily', () => { it('Can detect Chromium-based browser', () => { const edge = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.2151.58'; const firefox = 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0'; - assert.equal(isChromiumBased(UAParser(edge)), true); - assert.equal(isChromiumBased(UAParser(firefox)), false); + assert.equal(isChromeFamily(UAParser(edge)), true); + assert.equal(isChromeFamily(UAParser(firefox)), false); }); }); \ No newline at end of file