diff --git a/package.json b/package.json index 91e26bf..1ee952e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "title": "UA-Parser.JS", "name": "ua-parser-js", - "version": "0.5.0", + "version": "0.5.1", "author": "Faisal Salman (http://faisalman.com)", "description": "Lightweight JavaScript-based user-agent string parser", "keywords": [ diff --git a/test.js b/test.js index 25395b2..d3605ff 100644 --- a/test.js +++ b/test.js @@ -1238,6 +1238,17 @@ var os = [ version : '' } }]; +var devices = [ + { + desc : 'HTC Evo Shift 4G', + ua : 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0', + expect : + { + vendor : 'HTC', + model : 'Evo Shift 4G', + type : 'mobile' + } +}]; describe('getBrowser', function () { @@ -1311,3 +1322,32 @@ describe('getOS', function () { } } }); + +describe('getDevice', function () { + + for (var i in devices) { + + if (devices[i].ua) { + + describe('[' + devices[i].desc + ']', function () { + describe('"' + devices[i].ua + '"', function () { + + var expect = devices[i].expect; + var result = parser.setUA(devices[i].ua).getDevice(); + + it('should return device vendor: ' + expect.vendor, function () { + assert.equal(result.vendor, expect.vendor); + }); + + it('should return device model: ' + expect.model, function () { + assert.equal(result.model, expect.model); + }); + + it('should return device type: ' + expect.type, function () { + assert.equal(result.type, expect.type); + }); + }); + }); + } + } +}); diff --git a/ua-parser.js b/ua-parser.js index a999009..3091193 100644 --- a/ua-parser.js +++ b/ua-parser.js @@ -1,4 +1,4 @@ -// UA-Parser.JS v0.5.0 +// UA-Parser.JS v0.5.1 // Lightweight JavaScript-based User-Agent string parser // https://github.com/faisalman/ua-parser-js // @@ -97,11 +97,9 @@ }; var maps = { - - browser : { - oldsafari : { - + browser : { + oldsafari : { major : { '1' : ['/85', '/125', '/312'], '2' : ['/412', '/416', '/417', '/419'], @@ -120,20 +118,16 @@ } }, - device : { - - htc : { - + device : { + htc : { model : { 'Evo Shift 4G' : '7373KT' } } }, - os : { - - windows : { - + os : { + windows : { version : { 'ME' : '4.90', 'NT 3.11' : 'NT3.51', @@ -251,7 +245,7 @@ ], [VENDOR, MODEL, [TYPE, CONSOLE]], [ /(sprint\sapa)(\w+)/i - ], [[VENDOR, 'HTC'], [MODEL, maps.device.htc.model], [TYPE, MOBILE]], [ + ], [[VENDOR, 'HTC'], [MODEL, mapper.string, maps.device.htc.model], [TYPE, MOBILE]], [ /(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC /(zte)-(\w+)*/i // ZTE diff --git a/ua-parser.min.js b/ua-parser.min.js index 6ff9010..8404e78 100644 --- a/ua-parser.min.js +++ b/ua-parser.min.js @@ -1,7 +1,7 @@ -// UA-Parser.JS v0.5.0 +// UA-Parser.JS v0.5.1 // Lightweight JavaScript-based User-Agent string parser // https://github.com/faisalman/ua-parser-js // // Copyright © 2012 Faisalman // Dual licensed under GPLv2 & MIT -(function(e,t){"use strict";var n="",r="function",i="undefined",s="object",o="major",u="model",a="name",f="type",l="vendor",c="version",h="console",p="mobile",d="tablet",v={regex:function(){var e,o,u,a,f,l,c=arguments;for(o=0;o0){for(var o=0;o0){for(var o=0;o