Skip to content

Commit

Permalink
Move isFrozenUA() & isStandalonePWA() to its own npm module
Browse files Browse the repository at this point in the history
  • Loading branch information
faisalman committed Nov 5, 2024
1 parent 5097b80 commit e954f19
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@
"test:playwright": "playwright test"
},
"dependencies": {
"detect-europe-js": "^0.1.1"
"detect-europe-js": "^0.1.1",
"is-standalone-pwa": "^0.1.0",
"ua-is-frozen": "^0.1.1"
},
"devDependencies": {
"@babel/parser": "7.15.8",
Expand Down
16 changes: 3 additions & 13 deletions src/helpers/ua-parser-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

/*jshint esversion: 6 */

const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
const { UAParser } = require('../main/ua-parser');
const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
const { isFromEU } = require('detect-europe-js');
const { isFrozenUA } = require('ua-is-frozen');
const { isStandalonePWA } = require('is-standalone-pwa');

const getDeviceVendor = (model) => UAParser(`Mozilla/5.0 (Linux; Android 10; ${model}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36`).device.vendor;

Expand Down Expand Up @@ -40,18 +42,6 @@ const isChromeFamily = (res) => res.engine.is(Engine.BLINK);
const isElectron = () => !!(process?.versions?.hasOwnProperty('electron') || // node.js
/ electron\//i.test(navigator?.userAgent)); // browser

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 isStandalonePWA = () => window && (window.matchMedia('(display-mode: standalone)').matches ||
// iOS
navigator.standalone ||
// Android
document.referrer.startsWith('android-app://') ||
// Windows
window.Windows ||
/trident.+(msapphost|webview)\//i.test(navigator.userAgent) ||
document.referrer.startsWith('app-info://platform/microsoft-store'));

module.exports = {
getDeviceVendor,
isAppleSilicon,
Expand Down

0 comments on commit e954f19

Please sign in to comment.