1
0
mirror of https://github.com/lancedikson/bowser synced 2024-09-28 22:30:44 +00:00
lancedikson_bowser/src/parser-platforms.js

236 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-06-27 20:09:45 +00:00
import { getFirstMatch } from './utils';
2017-06-08 22:12:44 +00:00
2017-12-20 20:48:23 +00:00
const TYPES_LABELS = {
2017-06-08 22:12:44 +00:00
tablet: 'tablet',
mobile: 'mobile',
2017-12-20 21:29:06 +00:00
desktop: 'desktop',
2017-06-08 22:12:44 +00:00
};
2017-06-09 18:58:44 +00:00
/*
* Tablets go first since usually they have more specific
* signs to detect.
*/
2017-06-08 22:12:44 +00:00
export default [
/* Googlebot */
{
test: [/googlebot/i],
describe() {
return {
type: 'bot',
vendor: 'Google',
};
},
},
/* Huawei */
{
test: [/huawei/i],
describe(ua) {
2018-12-30 08:18:58 +00:00
const model = getFirstMatch(/(can-l01)/i, ua) && 'Nova';
const platform = {
type: TYPES_LABELS.mobile,
2018-12-30 08:18:58 +00:00
vendor: 'Huawei',
};
if (model) {
2018-12-30 08:18:58 +00:00
platform.model = model;
}
return platform;
},
},
2017-06-08 22:12:44 +00:00
/* Nexus Tablet */
{
test: [/nexus\s*(?:7|8|9|10).*/i],
2017-06-08 22:12:44 +00:00
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.tablet,
2017-06-08 22:12:44 +00:00
vendor: 'Nexus',
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* iPad */
{
test: [/ipad/i],
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.tablet,
2017-06-08 22:12:44 +00:00
vendor: 'Apple',
2017-12-20 21:29:06 +00:00
model: 'iPad',
};
},
2017-06-08 22:12:44 +00:00
},
/* Amazon Kindle Fire */
{
test: [/kftt build/i],
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.tablet,
vendor: 'Amazon',
2017-12-20 21:29:06 +00:00
model: 'Kindle Fire HD 7',
};
},
},
/* Another Amazon Tablet with Silk */
2017-06-08 22:12:44 +00:00
{
test: [/silk/i],
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.tablet,
2017-12-20 21:29:06 +00:00
vendor: 'Amazon',
};
},
2017-06-08 22:12:44 +00:00
},
/* Tablet */
{
test: [/tablet/i],
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.tablet,
2017-06-08 22:12:44 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* iPod/iPhone */
{
2017-06-09 20:49:08 +00:00
test(parser) {
const iDevice = parser.test(/ipod|iphone/i);
const likeIDevice = parser.test(/like (ipod|iphone)/i);
return iDevice && !likeIDevice;
},
2017-06-08 22:12:44 +00:00
describe(ua) {
const model = getFirstMatch(/(ipod|iphone)/i, ua);
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.mobile,
2017-06-08 22:12:44 +00:00
vendor: 'Apple',
2017-12-20 21:29:06 +00:00
model,
2017-06-08 22:12:44 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* Nexus Mobile */
{
test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
2017-06-08 22:12:44 +00:00
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.mobile,
2017-12-20 21:29:06 +00:00
vendor: 'Nexus',
2017-06-08 22:12:44 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* Mobile */
{
test: [/[^-]mobi/i],
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.mobile,
2017-06-08 22:12:44 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* BlackBerry */
{
test(parser) {
return parser.getBrowserName(true) === 'blackberry';
},
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.mobile,
2017-12-20 21:29:06 +00:00
vendor: 'BlackBerry',
2017-06-08 22:12:44 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* Bada */
{
test(parser) {
return parser.getBrowserName(true) === 'bada';
},
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.mobile,
};
},
2017-06-08 22:12:44 +00:00
},
/* Windows Phone */
{
test(parser) {
return parser.getBrowserName() === 'windows phone';
},
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.mobile,
2017-12-20 21:29:06 +00:00
vendor: 'Microsoft',
};
},
2017-06-08 22:12:44 +00:00
},
/* Android Tablet */
{
test(parser) {
const osMajorVersion = Number(String(parser.getOSVersion()).split('.')[0]);
return parser.getOSName(true) === 'android' && (osMajorVersion >= 3);
},
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.tablet,
};
},
2017-06-08 22:12:44 +00:00
},
/* Android Mobile */
{
test(parser) {
return parser.getOSName(true) === 'android';
},
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.mobile,
};
},
2017-06-08 22:12:44 +00:00
},
/* desktop */
{
test(parser) {
return parser.getOSName(true) === 'macos';
},
describe() {
return {
2017-12-20 20:48:23 +00:00
type: TYPES_LABELS.desktop,
2017-12-20 21:29:06 +00:00
vendor: 'Apple',
2017-06-08 22:12:44 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 22:12:44 +00:00
},
/* Windows */
{
test(parser) {
return parser.getOSName(true) === 'windows';
},
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.desktop,
};
},
2017-06-08 22:12:44 +00:00
},
/* Linux */
{
test(parser) {
return parser.getOSName(true) === 'linux';
},
describe() {
return {
2017-12-20 21:29:06 +00:00
type: TYPES_LABELS.desktop,
};
},
},
2017-06-08 22:12:44 +00:00
];