Add new getCPU() method to detect CPU architecture

This commit is contained in:
Faisal Salman 2013-04-03 18:00:27 +07:00
parent 9cad6a0f2d
commit 376541a383

View File

@ -25,6 +25,7 @@
TYPE = 'type', TYPE = 'type',
VENDOR = 'vendor', VENDOR = 'vendor',
VERSION = 'version', VERSION = 'version',
ARCHITECTURE= 'architecture',
CONSOLE = 'console', CONSOLE = 'console',
MOBILE = 'mobile', MOBILE = 'mobile',
TABLET = 'tablet'; TABLET = 'tablet';
@ -38,6 +39,9 @@
var util = { var util = {
has : function (str1, str2) { has : function (str1, str2) {
return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1; return str2.toLowerCase().indexOf(str1.toLowerCase()) !== -1;
},
lowerize : function (str) {
return str.toLowerCase();
} }
}; };
@ -80,8 +84,13 @@
// check if given property is actually array // check if given property is actually array
if (typeof(q) === OBJ_TYPE && q.length > 0) { if (typeof(q) === OBJ_TYPE && q.length > 0) {
if (q.length == 2) { if (q.length == 2) {
if (typeof(q[1]) == FUNC_TYPE) {
// assign modified match
result[q[0]] = q[1].call(this, match);
} else {
// assign given value, ignore regex match // assign given value, ignore regex match
result[q[0]] = q[1]; result[q[0]] = q[1];
}
} else if (q.length == 3) { } else if (q.length == 3) {
// check whether function or regex // check whether function or regex
if (typeof(q[1]) === FUNC_TYPE && !(q[1].exec && q[1].test)) { if (typeof(q[1]) === FUNC_TYPE && !(q[1].exec && q[1].test)) {
@ -266,6 +275,24 @@
], [NAME, VERSION, MAJOR] ], [NAME, VERSION, MAJOR]
], ],
cpu : [[
/(?:(amd|x(?:(?:86|64)[_-])?|wow|win)64)[;\)]/i // AMD64
], [[ARCHITECTURE, 'amd64']], [
/((?:i[346]|x)86)[;\)]/i // IA32
], [[ARCHITECTURE, 'ia32']], [
/((?:ppc|powerpc)(?:64)?)(?:\smac|;|\))/i // PowerPC
], [[ARCHITECTURE, /ower/, '']], [
/(sun4\w)[;\)]/i // SPARC
], [[ARCHITECTURE, 'sparc']], [
/(ia64(?=;)|68k(?=\))|arm(?=v\d+;)|(?:irix|mips|sparc)(?:64)?(?=;)|pa-risc)/i
// IA64, 68K, ARM, IRIX, MIPS, SPARC, PA-RISC
], [ARCHITECTURE, util.lowerize]
],
device : [[ device : [[
/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook /\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook
@ -431,6 +458,9 @@
this.getBrowser = function () { this.getBrowser = function () {
return mapper.rgx.apply(this, regexes.browser); return mapper.rgx.apply(this, regexes.browser);
}; };
this.getCPU = function () {
return mapper.rgx.apply(this, regexes.cpu);
};
this.getDevice = function () { this.getDevice = function () {
return mapper.rgx.apply(this, regexes.device); return mapper.rgx.apply(this, regexes.device);
}; };
@ -445,7 +475,8 @@
browser : this.getBrowser(), browser : this.getBrowser(),
engine : this.getEngine(), engine : this.getEngine(),
os : this.getOS(), os : this.getOS(),
device : this.getDevice() device : this.getDevice(),
cpu : this.getCPU()
}; };
}; };
this.getUA = function () { this.getUA = function () {