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

158 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-06-30 16:40:10 +00:00
import {
getFirstMatch,
getWindowsVersionName,
getAndroidVersionName,
2018-06-30 16:40:10 +00:00
} from './utils';
2017-05-18 20:14:31 +00:00
2017-04-15 19:46:18 +00:00
export default [
2017-05-18 20:56:26 +00:00
/* Windows Phone */
2017-04-15 19:46:18 +00:00
{
test: [/windows phone/i],
describe(ua) {
2017-04-15 19:46:18 +00:00
const version = getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
return {
name: 'Windows Phone',
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
{
test: [/windows/i],
describe(ua) {
const version = getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua);
const versionName = getWindowsVersionName(version);
return {
name: 'Windows',
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
/* macOS */
2017-04-15 19:46:18 +00:00
{
test: [/macintosh/i],
describe(ua) {
2017-08-17 20:48:44 +00:00
const version = getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, '.');
2017-04-15 19:46:18 +00:00
return {
name: 'macOS',
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
},
/* iOS */
{
test: [/(ipod|iphone|ipad)/i],
describe(ua) {
const version = getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, '.');
return {
name: '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) {
2017-12-20 21:29:06 +00:00
const version = getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
const versionName = getAndroidVersionName(version);
const os = {
2017-05-18 20:56:26 +00:00
name: '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 = getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
const os = {
2017-05-18 20:56:26 +00:00
name: 'WebOS',
};
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 = getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i, ua)
|| getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i, ua)
|| getFirstMatch(/\bbb(\d+)/i, ua);
return {
name: '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 = getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);
return {
name: '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) {
2017-12-20 21:29:06 +00:00
const version = getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
2017-05-18 20:56:26 +00:00
return {
name: '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 {
2017-12-20 21:29:06 +00:00
name: 'Linux',
};
},
},
/* Chrome OS */
{
test: [/CrOS/],
describe() {
return {
name: 'Chrome OS',
};
},
},
2017-12-20 21:29:06 +00:00
];