Merge tag 'tags/2.0.0' into pro-enterprise

This commit is contained in:
Faisal Salman
2024-11-21 17:40:24 +07:00
23 changed files with 589 additions and 73 deletions

View File

@@ -1,13 +1,14 @@
// Type definitions for Helpers submodule of UAParser.js v2.0.0-rc.3
// Type definitions for Helpers submodule of UAParser.js v2.0.0
// Project: https://github.com/faisalman/ua-parser-js
// Definitions by: Faisal Salman <https://github.com/faisalman>
import { IResult } from "../main/ua-parser";
declare function getDeviceVendor(model: string): string | undefined;
declare function isAppleSilicon(res: IResult, useFeatureDetection?: boolean): boolean;
declare function isBot(res: IResult): boolean;
declare function isChromeFamily(res: IResult): boolean;
declare function isAppleSilicon(resultOrUA: IResult | string): boolean;
declare function isAIBot(resultOrUA: IResult | string): boolean;
declare function isBot(resultOrUA: IResult | string): boolean;
declare function isChromeFamily(resultOrUA: IResult | string): boolean;
declare function isElectron(): boolean;
declare function isFromEU(): boolean;
declare function isFrozenUA(ua: string): boolean;
@@ -16,6 +17,7 @@ declare function isStandalonePWA(): boolean;
export {
getDeviceVendor,
isAppleSilicon,
isAIBot,
isBot,
isChromeFamily,
isElectron,

View File

@@ -1,5 +1,5 @@
///////////////////////////////////////////////
/* Helpers for UAParser.js v2.0.0-rc.3
/* Helpers for UAParser.js v2.0.0
https://github.com/faisalman/ua-parser-js
Author: Faisal Salman <f@faisalman.com>
UAParser.js PRO Enterprise License */
@@ -9,18 +9,22 @@
const { UAParser } = require('../main/ua-parser');
const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
const { Bots } = require('../extensions/ua-parser-extensions');
const { isFromEU } = require('detect-europe-js');
const { isFrozenUA } = require('ua-is-frozen');
const { isStandalonePWA } = require('is-standalone-pwa');
const toResult = (value, head, ext) => typeof value === 'string' ? UAParser(value, head, ext) : value;
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 isAppleSilicon = (res, useFeatureDetection) => {
const isAppleSilicon = (resultOrUA) => {
const res = toResult(resultOrUA);
if (res.os.is(OS.MACOS)) {
if (res.cpu.is(CPU.ARM)) {
return true;
}
if (useFeatureDetection) {
if (typeof resultOrUA !== 'string' && typeof window !== 'undefined') {
try {
const canvas = document.createElement('canvas');
const webgl = canvas.getContext('webgl2') || canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
@@ -37,9 +41,85 @@ const isAppleSilicon = (res, useFeatureDetection) => {
return false;
}
const isBot = (res) => ['cli', 'crawler', 'fetcher', 'library'].includes(res.browser.type);
const isAIBot = (resultOrUA) => [
const isChromeFamily = (res) => res.engine.is(Engine.BLINK);
// AI2
'ai2bot',
// Amazon
'amazonbot',
// Anthropic
'anthropic-ai',
'claude-web',
'claudebot',
// Apple
'applebot',
'applebot-extended',
// ByteDance
'bytespider',
// Common Crawl
'ccbot',
// DataForSeo
'dataforseobot',
// Diffbot
'diffbot',
// Google
'googleother',
'googleother-image',
'googleother-video',
'google-extended',
// Hive AI
'imagesiftbot',
// Huawei
'petalbot',
// Meta
'facebookbot',
'meta-externalagent',
// OpenAI
'gptbot',
'oai-searchbot',
// Perplexity
'perplexitybot',
// Timpi
'timpibot',
// Velen.io
'velenpublicwebcrawler',
// Webz.io
'omgili',
'omgilibot',
'webzio-extended',
// You.com
'youbot',
// Zyte
'scrapy'
].includes(String(toResult(resultOrUA, Bots).browser.name).toLowerCase());
const isBot = (resultOrUA) => [
'cli',
'crawler',
'fetcher',
'library'
].includes(toResult(resultOrUA, Bots).browser.type);
const isChromeFamily = (resultOrUA) => toResult(resultOrUA).engine.is(Engine.BLINK);
const isElectron = () => !!(process?.versions?.hasOwnProperty('electron') || // node.js
/ electron\//i.test(navigator?.userAgent)); // browser
@@ -47,6 +127,7 @@ const isElectron = () => !!(process?.versions?.hasOwnProperty('electron') ||
module.exports = {
getDeviceVendor,
isAppleSilicon,
isAIBot,
isBot,
isChromeFamily,
isElectron,

View File

@@ -3,7 +3,7 @@
// Source: /src/helpers/ua-parser-helpers.js
///////////////////////////////////////////////
/* Helpers for UAParser.js v2.0.0-rc.3
/* Helpers for UAParser.js v2.0.0
https://github.com/faisalman/ua-parser-js
Author: Faisal Salman <f@faisalman.com>
UAParser.js PRO Enterprise License */
@@ -13,18 +13,22 @@
import { UAParser } from '../main/ua-parser.mjs';
import { CPU, OS, Engine } from '../enums/ua-parser-enums.mjs';
import { Bots } from '../extensions/ua-parser-extensions.mjs';
import { isFromEU } from 'detect-europe-js';
import { isFrozenUA } from 'ua-is-frozen';
import { isStandalonePWA } from 'is-standalone-pwa';
const toResult = (value, head, ext) => typeof value === 'string' ? UAParser(value, head, ext) : value;
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 isAppleSilicon = (res, useFeatureDetection) => {
const isAppleSilicon = (resultOrUA) => {
const res = toResult(resultOrUA);
if (res.os.is(OS.MACOS)) {
if (res.cpu.is(CPU.ARM)) {
return true;
}
if (useFeatureDetection) {
if (typeof resultOrUA !== 'string' && typeof window !== 'undefined') {
try {
const canvas = document.createElement('canvas');
const webgl = canvas.getContext('webgl2') || canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
@@ -41,9 +45,85 @@ const isAppleSilicon = (res, useFeatureDetection) => {
return false;
}
const isBot = (res) => ['cli', 'crawler', 'fetcher', 'library'].includes(res.browser.type);
const isAIBot = (resultOrUA) => [
const isChromeFamily = (res) => res.engine.is(Engine.BLINK);
// AI2
'ai2bot',
// Amazon
'amazonbot',
// Anthropic
'anthropic-ai',
'claude-web',
'claudebot',
// Apple
'applebot',
'applebot-extended',
// ByteDance
'bytespider',
// Common Crawl
'ccbot',
// DataForSeo
'dataforseobot',
// Diffbot
'diffbot',
// Google
'googleother',
'googleother-image',
'googleother-video',
'google-extended',
// Hive AI
'imagesiftbot',
// Huawei
'petalbot',
// Meta
'facebookbot',
'meta-externalagent',
// OpenAI
'gptbot',
'oai-searchbot',
// Perplexity
'perplexitybot',
// Timpi
'timpibot',
// Velen.io
'velenpublicwebcrawler',
// Webz.io
'omgili',
'omgilibot',
'webzio-extended',
// You.com
'youbot',
// Zyte
'scrapy'
].includes(String(toResult(resultOrUA, Bots).browser.name).toLowerCase());
const isBot = (resultOrUA) => [
'cli',
'crawler',
'fetcher',
'library'
].includes(toResult(resultOrUA, Bots).browser.type);
const isChromeFamily = (resultOrUA) => toResult(resultOrUA).engine.is(Engine.BLINK);
const isElectron = () => !!(process?.versions?.hasOwnProperty('electron') || // node.js
/ electron\//i.test(navigator?.userAgent)); // browser
@@ -51,6 +131,7 @@ const isElectron = () => !!(process?.versions?.hasOwnProperty('electron') ||
export {
getDeviceVendor,
isAppleSilicon,
isAIBot,
isBot,
isChromeFamily,
isElectron,