Add new helper method: isFromEU() to detect whether user comes from an EU country

This commit is contained in:
Faisal Salman 2024-09-14 12:38:51 +07:00
parent b9f1bf6223
commit db1612401f
5 changed files with 31 additions and 1 deletions

22
package-lock.json generated
View File

@ -22,6 +22,9 @@
}
],
"license": "AGPL-3.0-or-later",
"dependencies": {
"detect-europe-js": "^0.1.1"
},
"bin": {
"ua-parser-js": "script/cli.js"
},
@ -1664,6 +1667,25 @@
"integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==",
"dev": true
},
"node_modules/detect-europe-js": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/detect-europe-js/-/detect-europe-js-0.1.1.tgz",
"integrity": "sha512-+bUXDf+tI3L4dcEuRdAFa44Amx9aEaJzoZssx7Xis4H1bXWc5fAcOP850BOj0wJPRzOdovOuOVEvrg6T+GflZA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/faisalman"
},
{
"type": "opencollective",
"url": "https://opencollective.com/ua-parser-js"
},
{
"type": "paypal",
"url": "https://paypal.me/faisalman"
}
]
},
"node_modules/detect-libc": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",

View File

@ -210,6 +210,9 @@
"test:mocha": "mocha test/mocha*js",
"test:playwright": "playwright test"
},
"dependencies": {
"detect-europe-js": "^0.1.1"
},
"devDependencies": {
"@babel/parser": "7.15.8",
"@babel/traverse": "7.23.2",

View File

@ -7,7 +7,8 @@ const generateMJS = (module) => {
let text = fs.readFileSync(src, 'utf-8');
replacements.push(
[/const (.+?)\s*=\s*require\(\'(.+)\'\)/ig, 'import $1 from \'$2.mjs\''],
[/const (.+?)\s*=\s*require\(\'\.(.+)\'\)/ig, 'import $1 from \'$2.mjs\''],
[/const (.+?)\s*=\s*require\(\'(.+)\'\)/ig, 'import $1 from \'$2\''],
[/module\.exports =/ig, 'export']
);
replacements.forEach(rep => {

View File

@ -7,6 +7,7 @@ import { IResult } from "../main/ua-parser";
declare function getDeviceVendor(model: string): string | undefined;
declare function isAppleSilicon(res: IResult): boolean;
declare function isChromeFamily(res: IResult): boolean;
declare function isFromEU(): boolean;
declare function isFrozenUA(ua: string): boolean;
declare function isStandalonePWA(): boolean;
@ -14,6 +15,7 @@ export {
getDeviceVendor,
isAppleSilicon,
isChromeFamily,
isFromEU,
isFrozenUA,
isStandalonePWA
}

View File

@ -9,6 +9,7 @@
const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
const { UAParser } = require('../main/ua-parser');
const { isFromEU } = require('detect-europe-js');
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;
@ -50,6 +51,7 @@ module.exports = {
getDeviceVendor,
isAppleSilicon,
isChromeFamily,
isFromEU,
isFrozenUA,
isStandalonePWA
}