1
0
mirror of https://github.com/lancedikson/bowser synced 2024-09-28 14:20:45 +00:00
lancedikson_bowser/src/parser-os.js

200 lines
3.9 KiB
JavaScript
Raw Normal View History

import Utils from './utils.js';
import { OS_MAP } from './constants.js';
2017-05-18 20:14:31 +00:00
2017-04-15 19:46:18 +00:00
export default [
/* Roku */
{
test: [/Roku\/DVP/],
describe(ua) {
const version = Utils.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i, ua);
return {
name: OS_MAP.Roku,
version,
};
},
},
2017-05-18 20:56:26 +00:00
/* Windows Phone */
2017-04-15 19:46:18 +00:00
{
test: [/windows phone/i],
describe(ua) {
const version = Utils.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
2017-04-15 19:46:18 +00:00
return {
name: OS_MAP.WindowsPhone,
2017-12-20 21:29:06 +00:00
version,
};
},
2017-04-15 19:46:18 +00:00
},
2017-05-18 20:56:26 +00:00
/* Windows */
2017-05-18 20:14:31 +00:00
{
2019-12-17 08:24:04 +00:00
test: [/windows /i],
2017-05-18 20:14:31 +00:00
describe(ua) {
const version = Utils.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua);
const versionName = Utils.getWindowsVersionName(version);
2017-05-18 20:14:31 +00:00
return {
name: OS_MAP.Windows,
2017-05-18 20:14:31 +00:00
version,
2017-12-20 21:29:06 +00:00
versionName,
2017-05-18 20:14:31 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:14:31 +00:00
},
2017-05-18 20:56:26 +00:00
2019-12-13 22:36:53 +00:00
/* Firefox on iPad */
{
2020-04-28 09:37:01 +00:00
test: [/Macintosh(.*?) FxiOS(.*?)\//],
2019-12-13 22:36:53 +00:00
describe(ua) {
2020-04-28 09:37:01 +00:00
const result = {
2019-12-13 22:36:53 +00:00
name: OS_MAP.iOS,
};
2020-04-28 09:37:01 +00:00
const version = Utils.getSecondMatch(/(Version\/)(\d[\d.]+)/, ua);
if (version) {
result.version = version;
}
return result;
2019-12-13 22:36:53 +00:00
},
},
2017-05-18 20:56:26 +00:00
/* macOS */
2017-04-15 19:46:18 +00:00
{
test: [/macintosh/i],
describe(ua) {
const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.');
2019-07-17 11:14:23 +00:00
const versionName = Utils.getMacOSVersionName(version);
const os = {
name: OS_MAP.MacOS,
2017-12-20 21:29:06 +00:00
version,
2017-05-18 20:56:26 +00:00
};
2019-07-17 11:14:23 +00:00
if (versionName) {
os.versionName = versionName;
}
return os;
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:56:26 +00:00
},
/* iOS */
{
test: [/(ipod|iphone|ipad)/i],
describe(ua) {
const version = Utils.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, '.');
2017-05-18 20:56:26 +00:00
return {
name: OS_MAP.iOS,
2017-12-20 21:29:06 +00:00
version,
2017-05-18 20:56:26 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:56:26 +00:00
},
/* Android */
{
test(parser) {
2017-06-08 20:32:11 +00:00
const notLikeAndroid = !parser.test(/like android/i);
2017-05-18 20:56:26 +00:00
const butAndroid = parser.test(/android/i);
return notLikeAndroid && butAndroid;
},
describe(ua) {
const version = Utils.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
const versionName = Utils.getAndroidVersionName(version);
const os = {
name: OS_MAP.Android,
2018-12-30 08:18:58 +00:00
version,
2017-05-18 20:56:26 +00:00
};
if (versionName) {
2018-12-30 08:10:33 +00:00
os.versionName = versionName;
}
return os;
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:56:26 +00:00
},
/* WebOS */
{
test: [/(web|hpw)[o0]s/i],
2017-05-18 20:56:26 +00:00
describe(ua) {
const version = Utils.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
const os = {
name: OS_MAP.WebOS,
2017-05-18 20:56:26 +00:00
};
if (version && version.length) {
os.version = version;
}
return os;
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:56:26 +00:00
},
/* BlackBerry */
{
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
describe(ua) {
const version = Utils.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i, ua)
|| Utils.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i, ua)
|| Utils.getFirstMatch(/\bbb(\d+)/i, ua);
2017-05-18 20:56:26 +00:00
return {
name: OS_MAP.BlackBerry,
2017-12-20 21:29:06 +00:00
version,
2017-05-18 20:56:26 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:56:26 +00:00
},
/* Bada */
{
test: [/bada/i],
describe(ua) {
const version = Utils.getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);
2017-05-18 20:56:26 +00:00
return {
name: OS_MAP.Bada,
2017-12-20 21:29:06 +00:00
version,
2017-05-18 20:56:26 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-05-18 20:56:26 +00:00
},
/* Tizen */
{
test: [/tizen/i],
describe(ua) {
const version = Utils.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
2017-05-18 20:56:26 +00:00
return {
name: OS_MAP.Tizen,
2017-12-20 21:29:06 +00:00
version,
2017-05-18 20:56:26 +00:00
};
2017-12-20 21:29:06 +00:00
},
2017-06-08 20:35:08 +00:00
},
/* Linux */
{
test: [/linux/i],
describe() {
return {
name: OS_MAP.Linux,
2017-12-20 21:29:06 +00:00
};
},
},
/* Chrome OS */
{
test: [/CrOS/],
describe() {
return {
name: OS_MAP.ChromeOS,
};
},
},
2019-02-06 08:47:28 +00:00
/* Playstation 4 */
{
test: [/PlayStation 4/],
describe(ua) {
2019-03-06 12:27:35 +00:00
const version = Utils.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua);
2019-02-06 08:47:28 +00:00
return {
name: OS_MAP.PlayStation4,
2019-02-06 08:47:28 +00:00
version,
};
},
},
2017-12-20 21:29:06 +00:00
];