From 71b5300080dd0d07040446e768a4ade896b6f125 Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Sat, 15 Sep 2012 01:05:15 +0700 Subject: [PATCH] Replace UAParser.result object with UAParser.getResult() --- readme.md | 13 +++++-------- ua-parser.js | 9 ++++++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index af75017..feb7777 100644 --- a/readme.md +++ b/readme.md @@ -17,13 +17,10 @@ Extract detailed type of web browser, layout engine, operating system, and devic * `getDevice()` * `getEngine()` * `getOS()` +* `getResult()` * `getUA()` * `setUA(uastring)` -## Properties - -* `result` - ## Example ```html @@ -33,7 +30,7 @@ Extract detailed type of web browser, layout engine, operating system, and devic var parser = new UAParser(); // by default it takes ua string from current browser's window.navigator.userAgent - console.log(parser.result); + console.log(parser.getResult()); /* /// this will print an object structured like this: { @@ -61,9 +58,9 @@ Extract detailed type of web browser, layout engine, operating system, and devic var uastr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2"; parser.setUA(uastr); - console.log(parser.result.browser); // {name: "Chromium", major: "15", version: "15.0.874.106"} - console.log(parser.result.engine); // {name: "AppleWebKit", version: "535.2"} - console.log(parser.result.os); // {name: "Ubuntu", version: "11.10"} + console.log(parser.getResult().browser); // {name: "Chromium", major: "15", version: "15.0.874.106"} + console.log(parser.getResult().engine); // {name: "AppleWebKit", version: "535.2"} + console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"} // let's take another test please console.log(parser.setUA("Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)").getOS().name); // "OpenBSD" diff --git a/ua-parser.js b/ua-parser.js index d5145e8..d20f53a 100644 --- a/ua-parser.js +++ b/ua-parser.js @@ -232,14 +232,17 @@ return ua; }; - this.setUA = function (uastring) { - ua = uastring; - this.result = { + this.getResult = function() { + return { browser : this.getBrowser(), engine : this.getEngine(), os : this.getOS(), device : this.getDevice() }; + }; + + this.setUA = function (uastring) { + ua = uastring; return this; };