Revert back util.is to typeof

This commit is contained in:
Faisal Salman 2013-03-20 14:09:31 +07:00
parent 38f62b3d63
commit ce8f4977c0
5 changed files with 16 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "ua-parser-js", "name": "ua-parser-js",
"version": "0.5.23", "version": "0.5.24",
"description": "Lightweight JavaScript-based user-agent string parser", "description": "Lightweight JavaScript-based user-agent string parser",
"keywords": ["user-agent", "parser", "browser", "engine", "os", "device"], "keywords": ["user-agent", "parser", "browser", "engine", "os", "device"],
"scripts": ["src/ua-parser.js"], "scripts": ["src/ua-parser.js"],

View File

@ -1,7 +1,7 @@
{ {
"title": "UAParser.js", "title": "UAParser.js",
"name": "ua-parser-js", "name": "ua-parser-js",
"version": "0.5.23", "version": "0.5.24",
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)", "author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
"description": "Lightweight JavaScript-based user-agent string parser", "description": "Lightweight JavaScript-based user-agent string parser",
"keywords": [ "keywords": [

View File

@ -1,4 +1,4 @@
// UAParser.js v0.5.23 // UAParser.js v0.5.24
// Lightweight JavaScript-based User-Agent string parser // Lightweight JavaScript-based User-Agent string parser
// https://github.com/faisalman/ua-parser-js // https://github.com/faisalman/ua-parser-js
// //
@ -38,9 +38,6 @@
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;
},
is : function (obj, str) {
return typeof obj === str;
} }
}; };
@ -61,11 +58,11 @@
props = args[i + 1]; // odd sequence (1,3,5,..) props = args[i + 1]; // odd sequence (1,3,5,..)
// construct object barebones // construct object barebones
if (util.is(result, UNDEF_TYPE)) { if (typeof(result) === UNDEF_TYPE) {
result = {}; result = {};
for (p in props) { for (p in props) {
q = props[p]; q = props[p];
if (util.is(q, OBJ_TYPE)) { if (typeof(q) === OBJ_TYPE) {
result[q[0]] = undefined; result[q[0]] = undefined;
} else { } else {
result[q] = undefined; result[q] = undefined;
@ -81,13 +78,13 @@
match = matches[++k]; match = matches[++k];
q = props[p]; q = props[p];
// check if given property is actually array // check if given property is actually array
if (util.is(q, OBJ_TYPE)) { if (typeof(q) === OBJ_TYPE) {
if (q.length == 2) { if (q.length == 2) {
// 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 (util.is(q[1], FUNC_TYPE) && !(q[1].exec && q[1].test)) { if (typeof(q[1]) === FUNC_TYPE && !(q[1].exec && q[1].test)) {
// call function (usually string mapper) // call function (usually string mapper)
result[q[0]] = match ? q[1].call(this, match, q[2]) : undefined; result[q[0]] = match ? q[1].call(this, match, q[2]) : undefined;
} else { } else {
@ -112,7 +109,7 @@
for (var i in map) { for (var i in map) {
// check if array // check if array
if (util.is(map[i], OBJ_TYPE) && map[i].length > 0) { if (typeof(map[i]) === OBJ_TYPE && map[i].length > 0) {
for (var j in map[i]) { for (var j in map[i]) {
if (util.has(map[i][j], str)) { if (util.has(map[i][j], str)) {
return (i === UNKNOWN) ? undefined : i; return (i === UNKNOWN) ? undefined : i;
@ -467,13 +464,13 @@
// check js environment // check js environment
if (!util.is(exports, UNDEF_TYPE)) { if (typeof(exports) !== UNDEF_TYPE) {
// nodejs env // nodejs env
if (!util.is(module, UNDEF_TYPE) && module.exports) { if (typeof(module) !== UNDEF_TYPE && module.exports) {
exports = module.exports = UAParser; exports = module.exports = UAParser;
} }
exports.UAParser = UAParser; exports.UAParser = UAParser;
} else if (util.is(define, FUNC_TYPE) && define.amd) { } else if (typeof(define) === FUNC_TYPE && define.amd) {
// requirejs env // requirejs env
define(function() { define(function() {
return UAParser; return UAParser;
@ -482,7 +479,7 @@
// browser env // browser env
window.UAParser = UAParser; window.UAParser = UAParser;
// jQuery specific (optional) // jQuery specific (optional)
if (!util.is(window.jQuery, UNDEF_TYPE)) { if (typeof(window.jQuery) !== UNDEF_TYPE) {
var $ = window.jQuery; var $ = window.jQuery;
var parser = new UAParser(); var parser = new UAParser();
$.ua = parser.getResult(); $.ua = parser.getResult();

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
{ {
"title": "UA-Parser.JS", "title": "UAParser.js",
"name": "ua-parser-js", "name": "ua-parser-js",
"version": "0.5.23", "version": "0.5.24",
"description": "Lightweight JavaScript-based user-agent string parser", "description": "Lightweight JavaScript-based user-agent string parser",
"keywords": [ "keywords": [
"user-agent", "user-agent",