1
0
mirror of https://github.com/lancedikson/bowser synced 2024-10-27 20:34:22 +00:00
lancedikson_bowser/src/parser-engines.js

121 lines
2.2 KiB
JavaScript
Raw Normal View History

import Utils from './utils.js';
import { ENGINE_MAP } from './constants.js';
2017-06-09 20:04:43 +00:00
/*
* More specific goes first
*/
export default [
/* EdgeHTML */
{
test(parser) {
return parser.getBrowserName(true) === 'microsoft edge';
},
describe(ua) {
const isBlinkBased = /\sedg\//i.test(ua);
// return blink if it's blink-based one
if (isBlinkBased) {
return {
name: ENGINE_MAP.Blink,
};
}
// otherwise match the version and return EdgeHTML
const version = Utils.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua);
2017-06-09 20:04:43 +00:00
return {
name: ENGINE_MAP.EdgeHTML,
2017-12-20 21:29:06 +00:00
version,
2017-06-09 20:04:43 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-09 20:04:43 +00:00
},
/* Trident */
{
test: [/trident/i],
describe(ua) {
const engine = {
name: ENGINE_MAP.Trident,
2017-06-09 20:04:43 +00:00
};
const version = Utils.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua);
2017-06-09 20:04:43 +00:00
if (version) {
engine.version = version;
}
return engine;
2017-12-20 21:29:06 +00:00
},
2017-06-09 20:04:43 +00:00
},
/* Presto */
{
test(parser) {
return parser.test(/presto/i);
},
describe(ua) {
const engine = {
name: ENGINE_MAP.Presto,
2017-06-09 20:04:43 +00:00
};
const version = Utils.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua);
2017-06-09 20:04:43 +00:00
if (version) {
engine.version = version;
}
return engine;
2017-12-20 21:29:06 +00:00
},
2017-06-09 20:04:43 +00:00
},
/* Gecko */
{
test(parser) {
const isGecko = parser.test(/gecko/i);
const likeGecko = parser.test(/like gecko/i);
return isGecko && !likeGecko;
},
describe(ua) {
const engine = {
name: ENGINE_MAP.Gecko,
2017-06-09 20:04:43 +00:00
};
const version = Utils.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua);
2017-06-09 20:04:43 +00:00
if (version) {
engine.version = version;
}
return engine;
2017-12-20 21:29:06 +00:00
},
2017-06-09 20:04:43 +00:00
},
/* Blink */
{
test: [/(apple)?webkit\/537\.36/i],
describe() {
return {
name: ENGINE_MAP.Blink,
2017-06-09 20:04:43 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-09 20:04:43 +00:00
},
/* WebKit */
{
test: [/(apple)?webkit/i],
describe(ua) {
const engine = {
name: ENGINE_MAP.WebKit,
2017-06-09 20:04:43 +00:00
};
const version = Utils.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua);
2017-06-09 20:04:43 +00:00
if (version) {
engine.version = version;
}
return engine;
2017-12-20 21:29:06 +00:00
},
},
2017-06-09 20:04:43 +00:00
];