mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 16:08:47 +03:00
Fix #660 - Add new helper method: getDeviceVendor()
to guess the device vendor from a model name
This commit is contained in:
parent
c391d8a73c
commit
62fb6c2925
2
src/helpers/ua-parser-helpers.d.ts
vendored
2
src/helpers/ua-parser-helpers.d.ts
vendored
@ -4,12 +4,14 @@
|
||||
|
||||
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 isFrozenUA(ua: string): boolean;
|
||||
declare function isStandalonePWA(): boolean;
|
||||
|
||||
export {
|
||||
getDeviceVendor,
|
||||
isAppleSilicon,
|
||||
isChromeFamily,
|
||||
isFrozenUA,
|
||||
|
@ -8,6 +8,9 @@
|
||||
/*jshint esversion: 6 */
|
||||
|
||||
const { CPU, OS, Engine } = require('../enums/ua-parser-enums');
|
||||
const { UAParser } = require('../main/ua-parser');
|
||||
|
||||
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) => {
|
||||
if (res.os.is(OS.MACOS)) {
|
||||
@ -44,6 +47,7 @@ const isStandalonePWA = () => window && (window.matchMedia('(display-mode: stand
|
||||
document.referrer.startsWith('app-info://platform/microsoft-store'));
|
||||
|
||||
module.exports = {
|
||||
getDeviceVendor,
|
||||
isAppleSilicon,
|
||||
isChromeFamily,
|
||||
isFrozenUA,
|
||||
|
@ -1,6 +1,23 @@
|
||||
const assert = require('assert');
|
||||
const { UAParser } = require('../src/main/ua-parser');
|
||||
const { isAppleSilicon, isChromeFamily } = require('../src/helpers/ua-parser-helpers');
|
||||
const { getDeviceVendor, isAppleSilicon, isChromeFamily } = require('../src/helpers/ua-parser-helpers');
|
||||
|
||||
describe('getDeviceVendor', () => {
|
||||
it('Can guess the device vendor from a model name', () => {
|
||||
|
||||
const modelSM = 'SM-A605G';
|
||||
const modelRedmi = 'Redmi Note 8';
|
||||
const modelNexus = 'Nexus 6P';
|
||||
const modelQuest = 'Quest 3';
|
||||
const modelAquos = 'AQUOS-TVX19B';
|
||||
|
||||
assert.equal(getDeviceVendor(modelSM), 'Samsung');
|
||||
assert.equal(getDeviceVendor(modelRedmi), 'Xiaomi');
|
||||
assert.equal(getDeviceVendor(modelNexus), 'Huawei');
|
||||
assert.equal(getDeviceVendor(modelQuest), 'Facebook');
|
||||
assert.equal(getDeviceVendor(modelAquos), 'Sharp');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAppleSilicon', () => {
|
||||
it('Can detect Apple Silicon device', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user