Skip to content
Browse files

Cleaning up JS.

  • Loading branch information...
1 parent de63c2d commit 55e68fa5c359284ea950d1e2983faf8c5b33b9ec @tobie committed Apr 6, 2012
Showing with 14 additions and 362 deletions.
  1. +3 −0 .npmignore
  2. +4 −3 { → js}/index.js
  3. +7 −5 package.json
  4. +0 −280 regexes.json
  5. +0 −74 scripts/update.js
View
3 .npmignore
@@ -0,0 +1,3 @@
+/php
+/py
+/test_resources
View
7 index.js → js/index.js
@@ -1,9 +1,10 @@
var path = require('path'),
- fs = require('fs');
+ fs = require('fs'),
+ yaml = require('yamlparser');
-var file = path.join(__dirname, 'regexes.json');
+var file = path.join(__dirname, '..', 'regexes.yaml');
var regexes = fs.readFileSync(file, 'utf8');
-regexes = JSON.parse(regexes);
+regexes = yaml.eval(regexes);
var ua_parsers = regexes.user_agent_parsers.map(function(obj) {
var regexp = new RegExp(obj.regex),
View
12 package.json
@@ -1,7 +1,7 @@
{
"name": "ua-parser",
"description": "A port of Browserscope's user agent parser.",
- "main": "index.js",
+ "main": "./js/index",
"version": "0.2.3",
"maintainers": [
{
@@ -25,6 +25,11 @@
"name": "Philip Tellis",
"email": "philip@bluesmoon.info",
"web": "http://bluesmoon.info"
+ },
+ {
+ "name": "Dave Olsen",
+ "email": "dmolsen@gmail.com",
+ "web": "http://dmolsen.com"
}
],
"repository": {
@@ -41,10 +46,7 @@
"url" : "http://github.com/tobie/ua-parser/raw/master/LICENSE"
}
],
- "scripts": {
- "update": "update.js"
- },
- "devDependencies": {
+ "dependencies": {
"yamlparser": ">=0.0.2"
}
}
View
280 regexes.json
@@ -1,280 +0,0 @@
-{
- "user_agent_parsers": [
- {
- "regex": "^(Opera)/(\\d+)\\.(\\d+) \\(Nintendo Wii",
- "family_replacement": "Wii"
- },
- {
- "regex": "(SeaMonkey|Fennec|Camino)/(\\d+)\\.(\\d+)\\.?([ab]?\\d+[a-z]*)"
- },
- {
- "regex": "(Namoroka|Shiretoko|Minefield)/(\\d+)\\.(\\d+)\\.(\\d+(?:pre)?)",
- "family_replacement": "Firefox ($1)"
- },
- {
- "regex": "(Firefox)/(\\d+)\\.(\\d+)([ab]\\d+[a-z]*)",
- "family_replacement": "Firefox Beta"
- },
- {
- "regex": "(Firefox)-(?:\\d+\\.\\d+)?/(\\d+)\\.(\\d+)([ab]\\d+[a-z]*)",
- "family_replacement": "Firefox Beta"
- },
- {
- "regex": "(Namoroka|Shiretoko|Minefield)/(\\d+)\\.(\\d+)([ab]\\d+[a-z]*)?",
- "family_replacement": "Firefox ($1)"
- },
- {
- "regex": "(Firefox).*Tablet browser (\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "MicroB"
- },
- {
- "regex": "(MozillaDeveloperPreview)/(\\d+)\\.(\\d+)([ab]\\d+[a-z]*)?"
- },
- {
- "regex": "(Flock)/(\\d+)\\.(\\d+)(b\\d+?)"
- },
- {
- "regex": "(RockMelt)/(\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(Fennec)/(\\d+)\\.(\\d+)(pre)"
- },
- {
- "regex": "(Navigator)/(\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "Netscape"
- },
- {
- "regex": "(Navigator)/(\\d+)\\.(\\d+)([ab]\\d+)",
- "family_replacement": "Netscape"
- },
- {
- "regex": "(Netscape6)/(\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "Netscape"
- },
- {
- "regex": "(MyIBrow)/(\\d+)\\.(\\d+)",
- "family_replacement": "My Internet Browser"
- },
- {
- "regex": "(Opera Tablet).*Version\\/(\\d+)\\.(\\d+)(?:\\.(\\d+))?"
- },
- {
- "regex": "(Opera)/.+Opera Mobi.+Version/(\\d+)\\.(\\d+)",
- "family_replacement": "Opera Mobile"
- },
- {
- "regex": "(Opera Mini)/(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(Opera)/9.80.*Version\\/(\\d+)\\.(\\d+)(?:\\.(\\d+))?"
- },
- {
- "regex": "(webOS)/(\\d+)\\.(\\d+)",
- "family_replacement": "Palm webOS"
- },
- {
- "regex": "(luakit)",
- "family_replacement": "LuaKit"
- },
- {
- "regex": "(Lightning)/(\\d+)\\.(\\d+)([ab]?\\d+[a-z]*)"
- },
- {
- "regex": "(Firefox)/(\\d+)\\.(\\d+)\\.(\\d+(?:pre)?) \\(Swiftfox\\)",
- "family_replacement": "Swiftfox"
- },
- {
- "regex": "(Firefox)/(\\d+)\\.(\\d+)([ab]\\d+[a-z]*)? \\(Swiftfox\\)",
- "family_replacement": "Swiftfox"
- },
- {
- "regex": "rekonq",
- "family_replacement": "Rekonq"
- },
- {
- "regex": "(conkeror|Conkeror)/(\\d+)\\.(\\d+)\\.?(\\d+)?",
- "family_replacement": "Conkeror"
- },
- {
- "regex": "(konqueror)/(\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "Konqueror"
- },
- {
- "regex": "(PlayBook).+RIM Tablet OS (\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(WeTab)-Browser"
- },
- {
- "regex": "(wOSBrowser).+TouchPad/(\\d+)\\.(\\d+)",
- "family_replacement": "webOS TouchPad"
- },
- {
- "regex": "(Comodo_Dragon)/(\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "Comodo Dragon"
- },
- {
- "regex": "(YottaaMonitor)"
- },
- {
- "regex": "(Kindle)/(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(AdobeAIR|Chromium|FireWeb|Jasmine|ANTGalio|Midori|Fresco|Lobo|PaleMoon|Maxthon|Lynx|OmniWeb|Dillo|Camino|Demeter|Fluid|Fennec|Shiira|Sunrise|Chrome|Flock|Netscape|Lunascape|Epiphany|WebPilot|Vodafone|NetFront|Konqueror|SeaMonkey|Kazehakase|Vienna|Iceape|Iceweasel|IceWeasel|Iron|K-Meleon|Sleipnir|Galeon|GranParadiso|Opera Mini|iCab|NetNewsWire|ThunderBrowse|Iron|Iris)/(\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(Bolt|Jasmine|IEMobile|IceCat|Skyfire|Midori|Maxthon|Lynx|Arora|IBrowse|Dillo|Camino|Shiira|Fennec|Phoenix|Chrome|Flock|Netscape|Lunascape|Epiphany|WebPilot|Opera Mini|Opera|Vodafone|NetFront|Konqueror|Googlebot|SeaMonkey|Kazehakase|Vienna|Iceape|Iceweasel|IceWeasel|Iron|K-Meleon|Sleipnir|Galeon|GranParadiso|iCab|NetNewsWire|Iron|Space Bison|Stainless|Orca|Dolfin|BOLT)/(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(iRider|Crazy Browser|SkipStone|iCab|Lunascape|Sleipnir|Maemo Browser) (\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(iCab|Lunascape|Opera|Android) (\\d+)\\.(\\d+)\\.?(\\d+)?"
- },
- {
- "regex": "(IEMobile) (\\d+)\\.(\\d+)",
- "family_replacement": "IE Mobile"
- },
- {
- "regex": "(Firefox)/(\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(Firefox)/(\\d+)\\.(\\d+)(pre|[ab]\\d+[a-z]*)?"
- },
- {
- "regex": "(Obigo|OBIGO)[^\\d]*(\\d+)(?:.(\\d+))?",
- "family_replacement": "Obigo"
- },
- {
- "regex": "(MAXTHON|Maxthon) (\\d+)\\.(\\d+)",
- "family_replacement": "Maxthon"
- },
- {
- "regex": "(Maxthon|MyIE2|Uzbl|Shiira)",
- "major_version_replacement": "0"
- },
- {
- "regex": "(PLAYSTATION) (\\d+)",
- "family_replacement": "PlayStation"
- },
- {
- "regex": "(PlayStation Portable)[^\\d]+(\\d+).(\\d+)"
- },
- {
- "regex": "(BrowseX) \\((\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(POLARIS)/(\\d+)\\.(\\d+)",
- "family_replacement": "Polaris"
- },
- {
- "regex": "(BonEcho)/(\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "Bon Echo"
- },
- {
- "regex": "(iPod).+Version/(\\d+)\\.(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(iPhone) OS (\\d+)_(\\d+)(?:_(\\d+))?"
- },
- {
- "regex": "(iPad).+ OS (\\d+)_(\\d+)(?:_(\\d+))?"
- },
- {
- "regex": "(Avant)",
- "major_version_replacement": "1"
- },
- {
- "regex": "(Nokia)[EN]?(\\d+)"
- },
- {
- "regex": "(Black[bB]erry).+Version\\/(\\d+)\\.(\\d+)\\.(\\d+)",
- "family_replacement": "Blackberry"
- },
- {
- "regex": "(Black[bB]erry)\\s?(\\d+)",
- "family_replacement": "Blackberry"
- },
- {
- "regex": "(OmniWeb)/v(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(Blazer)/(\\d+)\\.(\\d+)",
- "family_replacement": "Palm Blazer"
- },
- {
- "regex": "(Pre)/(\\d+)\\.(\\d+)",
- "family_replacement": "Palm Pre"
- },
- {
- "regex": "(Links) \\((\\d+)\\.(\\d+)"
- },
- {
- "regex": "(QtWeb) Internet Browser/(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(Version)/(\\d+)\\.(\\d+)(?:\\.(\\d+))?.*Safari/",
- "family_replacement": "Safari"
- },
- {
- "regex": "(Safari)/\\d+"
- },
- {
- "regex": "(OLPC)/Update(\\d+)\\.(\\d+)"
- },
- {
- "regex": "(OLPC)/Update()\\.(\\d+)",
- "major_version_replacement": "0"
- },
- {
- "regex": "(SamsungSGHi560)",
- "family_replacement": "Samsung SGHi560"
- },
- {
- "regex": "^(SonyEricssonK800i)",
- "family_replacement": "Sony Ericsson K800i"
- },
- {
- "regex": "(Teleca Q7)"
- },
- {
- "regex": "(MSIE) (\\d+)\\.(\\d+)",
- "family_replacement": "IE"
- }
- ],
- "os_parsers": [
- {
- "regex": "(Android)"
- },
- {
- "regex": "(Windows)"
- },
- {
- "regex": "(iPad)"
- },
- {
- "regex": "(iPhone OS) ([\\d_]+)",
- "os_replacement": "iOS"
- },
- {
- "regex": "(Mac OS X)"
- },
- {
- "regex": "(FreeBSD)"
- },
- {
- "regex": "(iPod)"
- },
- {
- "regex": "(iPhone Simulator)"
- },
- {
- "regex": "(Linux)"
- }
- ],
- "product_parsers": [
- {
- "regex": "(iPhone)"
- }
- ]
-}
View
74 scripts/update.js
@@ -1,74 +0,0 @@
-var fs = require('fs'),
- path = require('path'),
- http = require('http'),
- yaml = require('yamlparser');
-
-exports.YAML_FILE = path.join(__dirname, '..', 'regexes.yaml');
-exports.JSON_FILE = path.join(__dirname, '..', 'regexes.json');
-exports.SRC_PATH = '/svn/trunk/resources/user_agent_parser.yaml';
-exports.SRC_HOST = 'ua-parser.googlecode.com';
-
-exports.fetch = fetch;
-function fetch(callback) {
- fs.open(exports.YAML_FILE, 'w+', function(err, fd) {
- if (err) {
- callback(err);
- return;
- }
- var repo = http.createClient(80, exports.SRC_HOST);
- var request = repo.request('GET', exports.SRC_PATH, { host: exports.SRC_HOST });
- request.end();
- request.on('error', callback);
- request.on('response', function (response) {
- var position = 0;
- response.on('data', function (buffer) {
- fs.write(fd, buffer, 0, buffer.length, position)
- position += buffer.length;
- });
- response.on('end', callback);
- });
- });
-}
-
-exports.parse = parse;
-function parse(callback) {
- fs.readFile(exports.YAML_FILE, 'utf8', function(err, str) {
- if (err) {
- callback(err);
- } else {
- try {
- callback(null, yaml.eval(str));
- } catch(e) {
- callback(e);
- }
- }
- })
-}
-
-exports.dump = dump;
-function dump(json, callback) {
- json = JSON.stringify(json, null, 2);
- fs.writeFile(exports.JSON_FILE, json, callback);
-}
-
-if (require.main.id === module.id) {
- fetch(function(err) {
- if (err) {
- callback(err);
- return;
- }
- parse(function(err, json) {
- if (err) {
- callback(err);
- return;
- }
- dump(json, function(err) {
- if (err) {
- callback(err);
- return;
- }
- console.log('Fetched, parsed and dumped data into regexes.json.');
- })
- })
- });
-}

0 comments on commit 55e68fa

Please sign in to comment.
Something went wrong with that request. Please try again.