Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

woothee

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

woothee - npm Package Compare versions

Comparing version 0.3.4 to 0.3.5

.gitmodules

1

lib/appliance.js

@@ -15,2 +15,3 @@ /* HEADER BEGIN */

else if (ua.indexOf('PLAYSTATION 3 ') >= 0 || ua.indexOf('PLAYSTATION 3;') >= 0) data = dataset.get('PS3');
else if (ua.indexOf('PlayStation 4 ') >= 0) data = dataset.get('PS4');

@@ -17,0 +18,0 @@ if (! data)

@@ -35,4 +35,3 @@ var KEY_LABEL = exports.KEY_LABEL = 'label',

var DATASET = {};
// GENERATED from dataset.yaml at Tue Sep 10 14:45:26 JST 2013 by tagomoris
// GENERATED from dataset.yaml at Tue Dec 3 19:48:46 JST 2013 by tagomoris
var obj;

@@ -204,2 +203,17 @@ obj = {label:'MSIE', name:'Internet Explorer', type:'browser'};

DATASET[obj.label] = obj;
obj = {label:'PS4', name:'PlayStation 4', type:'full'};
obj['vendor'] = 'Sony';
obj['category'] = 'appliance';
obj['os'] = 'PlayStation 4';
DATASET[obj.label] = obj;
obj = {label:'Xbox360', name:'Xbox 360', type:'full'};
obj['vendor'] = 'Microsoft';
obj['category'] = 'appliance';
obj['os'] = 'Xbox 360';
DATASET[obj.label] = obj;
obj = {label:'XboxOne', name:'Xbox One', type:'full'};
obj['vendor'] = 'Microsoft';
obj['category'] = 'appliance';
obj['os'] = 'Xbox One';
DATASET[obj.label] = obj;
obj = {label:'DigitalTV', name:'InternetTVBrowser', type:'full'};

@@ -338,5 +352,4 @@ obj['vendor'] = '';

DATASET[obj.label] = obj;
var get = exports.get = function(label) {
return DATASET[label];
};

@@ -16,2 +16,15 @@ /* HEADER BEGIN */

// Xbox Series
if (ua.indexOf('Xbox') > -1) {
var d;
if (ua.indexOf('Xbox; Xbox One)') > -1)
d = dataset.get("XboxOne");
else
d = dataset.get("Xbox360");
// overwrite browser detections as appliance
updateMap(result, d);
return true;
}
var data = dataset.get('Win');

@@ -18,0 +31,0 @@ var match = windowsPattern.exec(ua);

4

package.json
{
"name": "woothee",
"version": "0.3.4",
"version": "0.3.5",
"description": "User-Agent string parser (js implementation)",

@@ -17,3 +17,3 @@ "main": "./release/woothee",

"type": "git",
"url": "https://github.com/tagomoris/woothee"
"url": "https://github.com/woothee/woothee-js"
},

@@ -20,0 +20,0 @@ "author": "tagomoris",

@@ -1,1 +0,79 @@

see ../README.md
# Woothee javascript
The Javascript implementation of Project Woothee, which is multi-language user-agent strings parsers.
https://github.com/woothee/woothee
## Installation
$ npm install woothee
Or, download `release/woothee.js` and put it on your own directory for js files.
## Usage
### Parsing user-agent
In html, load `woothee.js` and call `woothee.parse()` directly.
```html
<script src="./your/own/path/woothee.js"></script>
<script>
woothee.parse('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)')
// => {name: 'Internet Explorer', category: 'pc', os: 'Windows 7', version: '8.0', vendor: 'Microsoft'}
</script>
```
In node.js code, require 'woothee' and call its `parse()`.
```javascript
var woothee = require('woothee');
woothee.parse('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)')
// => {name: 'Internet Explorer', category: 'pc', os: 'Windows 7', version: '8.0', vendor: 'Microsoft'}
```
Parse user-agent string and returns a object with keys `name`, `category`, `os`, `version` and `vendor`.
For unknown user-agent (or partially failed to parse), result objects may have value 'UNKNOWN'.
* `category`
* labels of user terminal type, one of 'pc', 'smartphone', 'mobilephone', 'appliance', 'crawler' or 'misc' (or 'UNKNOWN')
* `name`
* the name of browser, like 'Internet Explorer', 'Firefox', 'GoogleBot'
* `version`
* version string, like '8.0' for IE, '9.0.1' for Firefix, '0.2.149.27' for Chrome, and so on
* `os`
* ex: 'Windows 7', 'Mac OSX', 'iPhone', 'iPad', 'Android'
* This field used to indicate cellar phone carrier for category 'mobilephone'
* `vendor`
* optional field, shows browser vendor
### Finding crawlers (almost all, not all) in fast
```javascript
woothee.is_crawler('Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)')
// => false
```
Try to see useragent's category is 'crawler' or not, by casual(fast) method. Minor case of crawlers is not tested in this method. To check crawler strictly, use `woothee.parse(str).category === 'crawler'`.
* * * * *
## Authors
* TAGOMORI Satoshi <tagomoris@gmail.com>
## License
Copyright 2012- TAGOMORI Satoshi (tagomoris)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

@@ -5,3 +5,3 @@ (function (){

// GENERATED at Mon Sep 2 20:00:02 JST 2013 by tagomoris
// GENERATED from dataset.yaml at Tue Dec 3 19:48:46 JST 2013 by tagomoris
var dataset = {};

@@ -18,7 +18,5 @@ (function(){

KEY_VERSION = exports.KEY_VERSION = 'version';
var TYPE_BROWSER = 'browser',
TYPE_OS = 'os',
TYPE_FULL = 'full';
var CATEGORY_PC = exports.CATEGORY_PC = 'pc',

@@ -30,3 +28,2 @@ CATEGORY_SMARTPHONE = exports.CATEGORY_SMARTPHONE = 'smartphone',

CATEGORY_MISC = exports.CATEGORY_MISC = 'misc';
var ATTRIBUTE_NAME = exports.ATTRIBUTE_NAME = 'name',

@@ -37,5 +34,3 @@ ATTRIBUTE_CATEGORY = exports.ATTRIBUTE_CATEGORY = 'category',

ATTRIBUTE_VERSION = exports.ATTRIBUTE_VERSION = 'version';
var VALUE_UNKNOWN = exports.VALUE_UNKNOWN = 'UNKNOWN';
var CATEGORY_LIST = exports.CATEGORY_LIST = [

@@ -46,6 +41,4 @@ CATEGORY_PC, CATEGORY_SMARTPHONE, CATEGORY_MOBILEPHONE,

var ATTRIBUTE_LIST = exports.ATTRIBUTE_LIST = [ATTRIBUTE_NAME, ATTRIBUTE_CATEGORY, ATTRIBUTE_OS, ATTRIBUTE_VENDOR, ATTRIBUTE_VERSION];
var DATASET = {};
// GENERATED from dataset.yaml at Mon Sep 2 19:53:25 JST 2013 by tagomoris
// GENERATED from dataset.yaml at Tue Dec 3 19:48:46 JST 2013 by tagomoris
var obj;

@@ -136,2 +129,5 @@ obj = {label:'MSIE', name:'Internet Explorer', type:'browser'};

DATASET[obj.label] = obj;
obj = {label:'FirefoxOS', name:'Firefox OS', type:'os'};
obj['category'] = 'smartphone';
DATASET[obj.label] = obj;
obj = {label:'BlackBerry', name:'BlackBerry', type:'os'};

@@ -215,2 +211,17 @@ obj['category'] = 'smartphone';

DATASET[obj.label] = obj;
obj = {label:'PS4', name:'PlayStation 4', type:'full'};
obj['vendor'] = 'Sony';
obj['category'] = 'appliance';
obj['os'] = 'PlayStation 4';
DATASET[obj.label] = obj;
obj = {label:'Xbox360', name:'Xbox 360', type:'full'};
obj['vendor'] = 'Microsoft';
obj['category'] = 'appliance';
obj['os'] = 'Xbox 360';
DATASET[obj.label] = obj;
obj = {label:'XboxOne', name:'Xbox One', type:'full'};
obj['vendor'] = 'Microsoft';
obj['category'] = 'appliance';
obj['os'] = 'Xbox One';
DATASET[obj.label] = obj;
obj = {label:'DigitalTV', name:'InternetTVBrowser', type:'full'};

@@ -349,3 +360,2 @@ obj['vendor'] = '';

DATASET[obj.label] = obj;
var get = exports.get = function(label) {

@@ -360,3 +370,2 @@ return DATASET[label];

/* CODE: util.js */
var updateMap = exports.updateMap = function(target, source) {

@@ -370,11 +379,8 @@ for (var key in source) {

};
var updateCategory = exports.updateCategory = function(target, category) {
target[dataset.ATTRIBUTE_CATEGORY] = category;
};
var updateVersion = exports.updateVersion = function(target, version) {
target[dataset.ATTRIBUTE_VERSION] = version;
};
var updateOs = exports.updateOs = function(target, os) {

@@ -389,3 +395,2 @@ target[dataset.ATTRIBUTE_OS] = os;

/* CODE: browser.js */
var msiePattern = /MSIE ([.0-9]+);/;

@@ -396,3 +401,2 @@ var tridentPattern = /Trident\/[.0-9]+; rv ([.0-9]+)/;

return false;
var version;

@@ -408,3 +412,2 @@ var match;

};
var chromePattern = /(?:Chrome|CrMo|CriOS)\/([.0-9]+)/;

@@ -415,5 +418,3 @@ var safariPattern = /Version\/([.0-9]+)/;

return false;
var version = dataset.VALUE_UNKNOWN;
var match;

@@ -427,7 +428,5 @@ if ((match = chromePattern.exec(ua))) {

}
if ((match = safariPattern.exec(ua))) {
version = match[1];
}
updateMap(result, dataset.get('Safari'));

@@ -437,3 +436,2 @@ updateVersion(result, version);

};
var firefoxPattern = /Firefox\/([.0-9]+)/;

@@ -443,3 +441,2 @@ var challengeFirefox = exports.challengeFirefox = function(ua, result) {

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -453,3 +450,2 @@ var match = firefoxPattern.exec(ua);

};
var operaPattern1 = /Version\/([.0-9]+)/;

@@ -460,3 +456,2 @@ var operaPattern2 = /Opera[\/ ]([.0-9]+)/;

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -475,3 +470,2 @@ var match = operaPattern1.exec(ua);

};
var sleipnirPattern = /Sleipnir\/([.0-9]+)/;

@@ -481,3 +475,2 @@ var challengeSleipnir = exports.challengeSleipnir = function(ua, result) {

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -489,3 +482,2 @@ var match = sleipnirPattern.exec(ua);

updateVersion(result, version);
/*

@@ -498,3 +490,2 @@ Sleipnir's user-agent doesn't contain Windows version, so put 'Windows UNKNOWN Ver'.

updateOs(result, win[dataset.KEY_NAME]);
return true;

@@ -508,3 +499,2 @@ };

/* CODE: os.js */
var windowsPattern = /Windows ([ .a-zA-Z0-9]+)[;\\)]/;

@@ -515,3 +505,13 @@ var windowsPhonePattern = /^Phone OS/;

return false;
// Xbox Series
if (ua.indexOf('Xbox') > -1) {
var d;
if (ua.indexOf('Xbox; Xbox One)') > -1)
d = dataset.get("XboxOne");
else
d = dataset.get("Xbox360");
// overwrite browser detections as appliance
updateMap(result, d);
return true;
}
var data = dataset.get('Win');

@@ -545,7 +545,5 @@ var match = windowsPattern.exec(ua);

};
var challengeOSX = exports.challengeOSX = function(ua, result) {
if (ua.indexOf('Mac OS X') < 0)
return false;
var data = dataset.get('OSX');

@@ -561,7 +559,5 @@ if (ua.indexOf('like Mac OS X') >= 0) {

};
var challengeLinux = exports.challengeLinux = function(ua, result) {
if (ua.indexOf('Linux') < 0)
return false;
var data = dataset.get('Linux');

@@ -574,3 +570,2 @@ if (ua.indexOf('Android') >= 0)

};
var challengeSmartPhone = exports.challengeSmartPhone = function(ua, result) {

@@ -584,6 +579,11 @@ var data = null;

else if (ua.indexOf('BlackBerry') >= 0) data = dataset.get('BlackBerry');
if (result[dataset.KEY_NAME] && result[dataset.KEY_NAME] === dataset.get('Firefox')[dataset.KEY_NAME]) {
// Firefox OS specific pattern
// http://lawrencemandel.com/2012/07/27/decision-made-firefox-os-user-agent-string/
if (/^Mozilla\/[.0-9]+ \(Mobile;(.*;)? rv:[.0-9]+\) Gecko\/[.0-9]+ Firefox\/[.0-9]+$/.exec(ua)) {
data = dataset.get('FirefoxOS');
}
}
if (!data)
return false;
updateCategory(result, data[dataset.KEY_CATEGORY]);

@@ -593,3 +593,2 @@ updateOs(result, data[dataset.KEY_NAME]);

};
var challengeMobilePhone = exports.challengeMobilePhone = function(ua, result) {

@@ -633,6 +632,4 @@ var data,match;

}
return false;
};
var challengeAppliance = exports.challengeAppliance = function(ua, result) {

@@ -654,3 +651,2 @@ var data;

};
var challengeMisc = exports.challengeMisc = function(ua, result) {

@@ -662,3 +658,2 @@ var data;

else if (ua.indexOf('X11; FreeBSD ') >= 0) data = dataset.get('BSD');
if (data) {

@@ -669,3 +664,2 @@ updateCategory(result, data[dataset.KEY_CATEGORY]);

}
return false;

@@ -679,3 +673,2 @@ };

/* CODE: mobilephone.js */
var docomoPattern = /DoCoMo\/[.0-9]+[ \/]([^- \/;()"']+)/;

@@ -686,3 +679,2 @@ var fomaPattern = /\(([^;)]+);FOMA;/;

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -699,3 +691,2 @@ var match;

};
var kddiPattern = /KDDI-([^- \/;()"']+)/;

@@ -705,3 +696,2 @@ var challengeAu = exports.challengeAu = function(ua, result) {

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -715,3 +705,2 @@ var match = kddiPattern.exec(ua);

};
var softbankPattern = /(?:SoftBank|Vodafone|J-PHONE)\/[.0-9]+\/([^ \/;()]+)/;

@@ -721,3 +710,2 @@ var challengeSoftbank = exports.challengeSoftbank = function(ua, result) {

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -731,3 +719,2 @@ var match = softbankPattern.exec(ua);

};
var willcomPattern = /(?:WILLCOM|DDIPOCKET);[^\/]+\/([^ \/;()]+)/;

@@ -737,3 +724,2 @@ var challengeWillcom = exports.challengeWillcom = function(ua, result) {

return false;
var version = dataset.VALUE_UNKNOWN;

@@ -747,3 +733,2 @@ var match = willcomPattern.exec(ua);

};
var challengeMisc = exports.challengeMisc = function(ua, result) {

@@ -784,7 +769,5 @@ var match;

/* CODE: crawler.js */
var challengeGoogle = exports.challengeGoogle = function(ua, result) {
if (ua.indexOf('Google') < 0)
return false;
if (ua.indexOf('compatible; Googlebot') >= 0) {

@@ -821,6 +804,4 @@ if (ua.indexOf('compatible; Googlebot-Mobile') >= 0) {

}
return false;
};
var challengeCrawlers = exports.challengeCrawlers = function(ua, result) {

@@ -939,6 +920,4 @@ if (ua.indexOf('Yahoo') >= 0

}
return false;
};
var challengeMaybeCrawler = exports.challengeMaybeCrawler = function(ua, result) {

@@ -970,3 +949,2 @@ if (/(bot|crawler|spider)(?:[-_ .\/;@()]|$)/i.exec(ua)) {

/* CODE: appliance.js */
var challengePlaystation = exports.challengePlaystation = function(ua, result) {

@@ -977,10 +955,8 @@ var data = null;

else if (ua.indexOf('PLAYSTATION 3 ') >= 0 || ua.indexOf('PLAYSTATION 3;') >= 0) data = dataset.get('PS3');
else if (ua.indexOf('PlayStation 4 ') >= 0) data = dataset.get('PS4');
if (! data)
return false;
updateMap(result, data);
return true;
};
var challengeNintendo = exports.challengeNintendo = function(ua, result) {

@@ -992,20 +968,16 @@ var data = null;

else if (ua.indexOf('(Nintendo WiiU)') >= 0) data = dataset.get('NintendoWiiU');
if (! data)
return false;
updateMap(result, data);
return true;
};
var challengeDigitalTV = exports.challengeDigitalTV = function(ua, result) {
var data = null;
if (ua.indexOf('InettvBrowser/') >= 0) data = dataset.get('DigitalTV');
if (! data)
return false;
updateMap(result, data);
return true;
};
})();

@@ -1016,3 +988,2 @@ var misc = {};

/* CODE: misc.js */
var challengeDesktopTools = exports.challengeDesktopTools = function(ua, result){

@@ -1023,10 +994,7 @@ var data = null;

else if (ua.indexOf('Windows-RSS-Platform') >= 0) data = dataset.get('WindowsRSSReader');
if (!data)
return false;
updateMap(result, data);
return true;
};
var challengeSmartPhonePatterns = exports.challengeSmartPhonePatterns = function(ua, result){

@@ -1040,6 +1008,4 @@ var data;

}
return false;
};
var challengeHTTPLibrary = exports.challengeHTTPLibrary = function(ua, result){

@@ -1064,6 +1030,4 @@ var data,version;

}
if (! data)
return false;
updateMap(result, data);

@@ -1073,3 +1037,2 @@ updateVersion(result, version);

};
var challengeMaybeRSSReader = exports.challengeMaybeRSSReader = function(ua, result){

@@ -1084,6 +1047,4 @@ var data = null;

}
if (! data)
return false;
updateMap(result, data);

@@ -1098,20 +1059,14 @@ return true;

/* CODE: woothee.js */
var parse = exports.parse = function(userAgent) {
return fillResult(execParse(userAgent));
};
var isCrawler = exports.isCrawler = function(userAgent) {
return false;
};
function execParse(userAgent) {
var result = {};
if (userAgent.length < 1 || userAgent === '-')
return result;
if (tryCrawler(userAgent, result))
return result;
if (tryBrowser(userAgent, result)) {

@@ -1123,136 +1078,95 @@ if (tryOS(userAgent, result))

}
if (tryMobilePhone(userAgent, result))
return result;
if (tryAppliance(userAgent, result))
return result;
if (tryMisc(userAgent, result))
return result;
// browser unknown, check os only
if (tryOS(userAgent, result))
return result;
if (tryRareCases(userAgent, result))
return result;
return result;
};
function tryCrawler(userAgent, result) {
if (crawler.challengeGoogle(userAgent, result))
return true;
if (crawler.challengeCrawlers(userAgent, result))
return true;
return false;
}
function tryBrowser(userAgent, result) {
if (browser.challengeMSIE(userAgent, result))
return true;
if (browser.challengeSafariChrome(userAgent, result))
return true;
if (browser.challengeFirefox(userAgent, result))
return true;
if (browser.challengeOpera(userAgent, result))
return true;
return false;
}
function tryOS(userAgent, result) {
if (os.challengeWindows(userAgent, result))
return true;
// OSX PC and iOS devices (strict check)
if (os.challengeOSX(userAgent, result))
return true;
// Linux PC and Android
if (os.challengeLinux(userAgent, result))
return true;
// all useragents matches /(iPhone|iPad|iPod|Android|BlackBerry)/
if (os.challengeSmartPhone(userAgent, result))
return true;
// mobile phones like KDDI-.*
if (os.challengeMobilePhone(userAgent, result))
return true;
// Nintendo DSi/Wii with Opera
if (os.challengeAppliance(userAgent, result))
return true;
if (os.challengeMisc(userAgent, result))
return true;
return false;
}
function tryMobilePhone(userAgent, result) {
if (mobilephone.challengeDocomo(userAgent, result))
return true;
if (mobilephone.challengeAu(userAgent, result))
return true;
if (mobilephone.challengeSoftbank(userAgent, result))
return true;
if (mobilephone.challengeWillcom(userAgent, result))
return true;
if (mobilephone.challengeMisc(userAgent, result))
return true;
return false;
}
function tryAppliance(userAgent, result) {
if (appliance.challengePlaystation(userAgent, result))
return true;
if (appliance.challengeNintendo(userAgent, result))
return true;
if (appliance.challengeDigitalTV(userAgent, result))
return true;
return false;
}
function tryMisc(userAgent, result) {
if (misc.challengeDesktopTools(userAgent, result))
return true;
return false;
}
function tryRareCases(userAgent, result) {
if (misc.challengeSmartPhonePatterns(userAgent, result))
return true;
if (browser.challengeSleipnir(userAgent, result))
return true;
if (misc.challengeHTTPLibrary(userAgent, result))
return true;
if (misc.challengeMaybeRSSReader(userAgent, result))
return true;
if (crawler.challengeMaybeCrawler(userAgent, result))
return true;
return false;
}
var filled = {};

@@ -1264,3 +1178,2 @@ filled[dataset.ATTRIBUTE_NAME] = dataset.VALUE_UNKNOWN;

filled[dataset.ATTRIBUTE_VENDOR] = dataset.VALUE_UNKNOWN;
function fillResult(result) {

@@ -1279,4 +1192,4 @@ if (! result[dataset.ATTRIBUTE_NAME])

};
})();
var updateMap = util.updateMap,

@@ -1283,0 +1196,0 @@ updateCategory = util.updateCategory,

@@ -8,3 +8,3 @@ var expect = require('chai').expect;

var TESTSET_DIR = process.cwd() + '/../testsets/',
var TESTSET_DIR = __dirname + '/../woothee/testsets/',
TARGETS = [

@@ -11,0 +11,0 @@ ['crawler.yaml','Crawler'],['crawler_google.yaml','Crawler/Google'],

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc