@cainiaofe/cn-utils
Version:
菜鸟前端基础工具库
189 lines (188 loc) • 5.32 kB
JavaScript
import match from "../../common/match";
import helper from './helper';
import { OS_MAP } from "../../constants";
var osList = [
/* Roku */
{
test: [/Roku\/DVP/],
describe: function (ua) {
var version = match.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i, ua);
return {
name: OS_MAP.Roku,
version: version,
};
},
},
/* Windows Phone */
{
test: [/windows phone/i],
describe: function (ua) {
var version = match.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
return {
name: OS_MAP.WindowsPhone,
version: version,
};
},
},
/* Windows */
{
test: [/windows /i],
describe: function (ua) {
var version = match.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua);
var versionName = helper.getWindowsVersionName(version);
return {
name: OS_MAP.Windows,
version: version,
versionName: versionName,
};
},
},
/* Firefox on iPad */
{
test: [/Macintosh(.*?) FxiOS(.*?)\//],
describe: function (ua) {
var result = {
name: OS_MAP.iOS,
version: '',
};
var version = match.getSecondMatch(/(Version\/)(\d[\d.]+)/, ua);
if (version) {
result.version = version;
}
return result;
},
},
/* macOS */
{
test: [/macintosh/i],
describe: function (ua) {
var version = match
.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua)
.replace(/[_\s]/g, '.');
var versionName = helper.getMacOSVersionName(version);
var os = {
name: OS_MAP.MacOS,
version: version,
versionName: '',
};
if (versionName) {
os.versionName = versionName;
}
return os;
},
},
/* iOS */
{
test: [/(ipod|iphone|ipad)/i],
describe: function (ua) {
var version = match
.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua)
.replace(/[_\s]/g, '.');
return {
name: OS_MAP.iOS,
version: version,
};
},
},
/* Android */
{
test: function (parser) {
var notLikeAndroid = !parser.test(/like android/i);
var butAndroid = parser.test(/android/i);
return notLikeAndroid && butAndroid;
},
describe: function (ua) {
var version = match.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
var versionName = helper.getAndroidVersionName(version);
var os = {
name: OS_MAP.Android,
version: version,
versionName: '',
};
if (versionName) {
os.versionName = versionName;
}
return os;
},
},
/* WebOS */
{
test: [/(web|hpw)[o0]s/i],
describe: function (ua) {
var version = match.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
var os = {
name: OS_MAP.WebOS,
version: '',
};
if (version && version.length) {
os.version = version;
}
return os;
},
},
/* BlackBerry */
{
test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
describe: function (ua) {
var version = match.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i, ua) ||
match.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i, ua) ||
match.getFirstMatch(/\bbb(\d+)/i, ua);
return {
name: OS_MAP.BlackBerry,
version: version,
};
},
},
/* Bada */
{
test: [/bada/i],
describe: function (ua) {
var version = match.getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);
return {
name: OS_MAP.Bada,
version: version,
};
},
},
/* Tizen */
{
test: [/tizen/i],
describe: function (ua) {
var version = match.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
return {
name: OS_MAP.Tizen,
version: version,
};
},
},
/* Linux */
{
test: [/linux/i],
describe: function () {
return {
name: OS_MAP.Linux,
};
},
},
/* Chrome OS */
{
test: [/CrOS/],
describe: function () {
return {
name: OS_MAP.ChromeOS,
};
},
},
/* Playstation 4 */
{
test: [/PlayStation 4/],
describe: function (ua) {
var version = match.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua);
return {
name: OS_MAP.PlayStation4,
version: version,
};
},
},
];
export default osList;