Skip to content

Commit

Permalink
BREAKING CHANGE - Rename isChromiumBased -> isChromeFamily & `isP…
Browse files Browse the repository at this point in the history
…WA` -> `isStandalonePWA`
  • Loading branch information
faisalman committed Jun 22, 2024
1 parent 50c15ad commit 21162f1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/helpers/ua-parser-helpers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions src/helpers/ua-parser-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,7 +27,7 @@ const isPWA = () => window && (window.matchMedia('(display-mode: standalone)').m

module.exports = {
isAppleSilicon,
isChromiumBased,
isChromeFamily,
isFrozenUA,
isPWA
isStandalonePWA
}
4 changes: 2 additions & 2 deletions test/dts-test.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -46,4 +46,4 @@ expectType<UAParser>(parser.setUA(uastring));
const result = parser.getResult();

expectType<boolean>(isAppleSilicon(result));
expectType<boolean>(isChromiumBased(result));
expectType<boolean>(isChromeFamily(result));
8 changes: 4 additions & 4 deletions test/mocha-test-helpers.js
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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);
});
});

0 comments on commit 21162f1

Please sign in to comment.