From 1f21d35ab8b7fe160a146ac59865cd1e637ea95e Mon Sep 17 00:00:00 2001 From: Faisal Salman Date: Sat, 4 Aug 2012 05:14:17 +0700 Subject: [PATCH] Restore UAParser --- package.json | 2 +- readme.md | 22 ++++++++++++---------- ua-parser.js | 12 +++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index f801f72..3f19442 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "name": "ua-parser-js", "version": "0.3.1", "author": "Faisal Salman (http://faisalman.com)", - "description": "Lightweight JavaScript-based user-agent parser", + "description": "Light-weight JavaScript-based all-in-one user-agent parser", "keywords": [ "user agent", "parser", diff --git a/readme.md b/readme.md index 22203b1..0e70a5a 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ # UA-Parser.js -Lightweight JavaScript-based user-agent parser +Light-weight JavaScript-based all-in-one user-agent parser * Author : Faisalman <> * Home : http://faisalman.github.com/ua-parser-js @@ -29,8 +29,10 @@ Get detailed type and version of web browser, layout engine, operating system, a ``` ## Using node.js ```js -var parser = require('ua-parser'); - +var UAParser = require('ua-parser'); +var parser = new UAParser(); var ua1 = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11'; var ua2 = 'Midori/0.2 (X11; Linux; U; cs-cz) WebKit/531.2+'; @@ -94,4 +96,4 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. +GNU General Public License for more details. \ No newline at end of file diff --git a/ua-parser.js b/ua-parser.js index 66db570..4b77d1b 100644 --- a/ua-parser.js +++ b/ua-parser.js @@ -1,14 +1,14 @@ // UA-Parser.js v0.3.1 -// Lightweight JavaScript-based user-agent parser +// Light-weight JavaScript-based all-in-one user-agent parser // https://github.com/faisalman/ua-parser-js // // Copyright © 2012 Faisalman // Licensed under GPLv2 & MIT -(function () { - function UAParser (undefined) { +(function (undefined) { + var parser = function UAParser (uastring) { - var ua = typeof window !== 'undefined' ? window.navigator.userAgent : ""; + var ua = uastring || typeof window !== 'undefined' ? window.navigator.userAgent : ""; // regexp mapper var regxMap = function (ua) { @@ -228,9 +228,7 @@ this.setUA(ua); }; - - var parser = new UAParser(); - + // check whether script is running inside node.js export as module if (typeof exports !== 'undefined' && this.toString() !== '[object DOMWindow]') { if (typeof module !== 'undefined' && module.exports) {