mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Add new helper method: isFromEU()
to detect whether user comes from an EU country
This commit is contained in:
parent
b9f1bf6223
commit
db1612401f
22
package-lock.json
generated
22
package-lock.json
generated
@ -22,6 +22,9 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
|
"dependencies": {
|
||||||
|
"detect-europe-js": "^0.1.1"
|
||||||
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"ua-parser-js": "script/cli.js"
|
"ua-parser-js": "script/cli.js"
|
||||||
},
|
},
|
||||||
@ -1664,6 +1667,25 @@
|
|||||||
"integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==",
|
"integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==",
|
||||||
"dev": true
|
"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": {
|
"node_modules/detect-libc": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz",
|
||||||
|
@ -210,6 +210,9 @@
|
|||||||
"test:mocha": "mocha test/mocha*js",
|
"test:mocha": "mocha test/mocha*js",
|
||||||
"test:playwright": "playwright test"
|
"test:playwright": "playwright test"
|
||||||
},
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"detect-europe-js": "^0.1.1"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/parser": "7.15.8",
|
"@babel/parser": "7.15.8",
|
||||||
"@babel/traverse": "7.23.2",
|
"@babel/traverse": "7.23.2",
|
||||||
|
@ -7,7 +7,8 @@ const generateMJS = (module) => {
|
|||||||
let text = fs.readFileSync(src, 'utf-8');
|
let text = fs.readFileSync(src, 'utf-8');
|
||||||
|
|
||||||
replacements.push(
|
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']
|
[/module\.exports =/ig, 'export']
|
||||||
);
|
);
|
||||||
replacements.forEach(rep => {
|
replacements.forEach(rep => {
|
||||||
|
2
src/helpers/ua-parser-helpers.d.ts
vendored
2
src/helpers/ua-parser-helpers.d.ts
vendored
@ -7,6 +7,7 @@ import { IResult } from "../main/ua-parser";
|
|||||||
declare function getDeviceVendor(model: string): string | undefined;
|
declare function getDeviceVendor(model: string): string | undefined;
|
||||||
declare function isAppleSilicon(res: IResult): boolean;
|
declare function isAppleSilicon(res: IResult): boolean;
|
||||||
declare function isChromeFamily(res: IResult): boolean;
|
declare function isChromeFamily(res: IResult): boolean;
|
||||||
|
declare function isFromEU(): boolean;
|
||||||
declare function isFrozenUA(ua: string): boolean;
|
declare function isFrozenUA(ua: string): boolean;
|
||||||
declare function isStandalonePWA(): boolean;
|
declare function isStandalonePWA(): boolean;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ export {
|
|||||||
getDeviceVendor,
|
getDeviceVendor,
|
||||||
isAppleSilicon,
|
isAppleSilicon,
|
||||||
isChromeFamily,
|
isChromeFamily,
|
||||||
|
isFromEU,
|
||||||
isFrozenUA,
|
isFrozenUA,
|
||||||
isStandalonePWA
|
isStandalonePWA
|
||||||
}
|
}
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
|
const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
|
||||||
const { UAParser } = require('../main/ua-parser');
|
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;
|
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,
|
getDeviceVendor,
|
||||||
isAppleSilicon,
|
isAppleSilicon,
|
||||||
isChromeFamily,
|
isChromeFamily,
|
||||||
|
isFromEU,
|
||||||
isFrozenUA,
|
isFrozenUA,
|
||||||
isStandalonePWA
|
isStandalonePWA
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user