Make sure the result only get constructed once

This commit is contained in:
Faisal Salman 2012-09-15 02:16:02 +07:00
parent ec40433c5c
commit 51822ad172
2 changed files with 15 additions and 9 deletions

View File

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

View File

@ -1,4 +1,4 @@
// UA-Parser.JS v0.3.4
// UA-Parser.JS v0.3.5
// Lightweight JavaScript-based User-Agent string parser
// https://github.com/faisalman/ua-parser-js
//
@ -9,7 +9,7 @@
var regexMapper = function (ua, args) {
var result = {}, i, j, k, l, m;
var result, i, j, k, l, m;
// loop through all regexes maps
for (i = 1; i < arguments.length; i += 2) {
@ -18,6 +18,8 @@
props = arguments[i + 1]; // odd sequence (2,4,6,..)
// build object barebones
if (typeof result === 'undefined') {
result = {};
for (k = 0; k < props.length; k++) {
if (typeof props[k] === 'object') {
result[props[k][0]] = undefined;
@ -25,6 +27,10 @@
result[props[k]] = undefined;
}
}
if (ua.toString() === '') {
return result;
}
}
// try matching uastring with regexes
for (j = 0; j < regex.length; j++) {
@ -217,7 +223,7 @@
/sec-((sgh\w+))/i
], [['name', 'Samsung'], 'version'], [
/((transfo[prime\s]{4,10}\s\w+|(?:android.*)eeepc))/i // Asus
/((transfo[prime\s]{4,10}\s\w+))|(?:android.*)((eeepc))/i // Asus
], [['name', 'Asus'], 'version'], [
/(sie)-(\w+)*/i // Siemens