Browse files

write a little document and fix a few bugs

  • Loading branch information...
1 parent ff05851 commit d93c5e0af624abe1982c662db4ff669bf4cc3001 @KOBA789 committed Dec 13, 2012
Showing with 52 additions and 2 deletions.
  1. +37 −0 README.md
  2. +10 −1 lib/enum.js
  3. +4 −0 lib/index.js
  4. +1 −1 package.json
View
37 README.md
@@ -0,0 +1,37 @@
+# Agent-Line
+
+## install
+
+```
+npm install agent-install
+```
+
+## code
+
+```
+var asset = require('assert'),
+ agent = require('agent-line'),
+ Device = agent.Device,
+ OS = agent.OS,
+ Carrier = agent.Carrier;
+
+var iPhone = agent.lookup('Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25');
+
+assert.ok(iPhone.os.isEqual(OS.iOS));
+assert.ok(iPhone.device.isEqual(Device.SmartPhone));
+assert.ok(iPhone.device.isA(Device.Phone)); // Phone = SmartPhone | FeaturePhone
+assert.ok(iPhone.device.isA(Device.Mobile)); // Mobile = Tablet | Phone
+
+var iPad = agent.lookup('Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A403 Safari/8536.25');
+
+assert.ok(iPad.os.isEqual(OS.iOS));
+assert.ok(iPad.device.isEqual(Device.Tablet));
+assert.ok(iPad.device.isA(Device.Mobile)); // Mobile = Tablet | Phone
+
+var SH06A3 = agent.lookup('DoCoMo/2.0 SH06A3(c500;TC;W30H18)');
+
+assert.ok(SH06A3.device.isEqual(Device.FeaturePhone));
+assert.ok(SH06A3.device.isA(Device.Phone));
+assert.ok(SH06A3.device.isA(Device.Mobile));
+assert.ok(SH06A3.carrier.isA(Carrier.Docomo)); // a feature phone has carrier info
+```
View
11 lib/enum.js
@@ -14,13 +14,22 @@ EnumItem.prototype.valueOf = function () {
EnumItem.prototype.hasFlag = function (item) {
if (item instanceof EnumItem) {
- if (item.parent === this.parent ) {
+ if (item.parent === this.parent) {
return (this.id & item.id) === item.id;
}
}
return false;
};
+EnumItem.prototype.isA = function (item) {
+ if (item instanceof EnumItem) {
+ if (item.parent === this.parent) {
+ return (this.id & item.id) === this.id;
+ }
+ }
+ return false;
+};
+
EnumItem.prototype.isEqual = function (item) {
return (item instanceof EnumItem) && (this.id === item.id);
};
View
4 lib/index.js
@@ -13,6 +13,10 @@ agent.lookup = function (ua) {
return agentsDef[agentsDef.length - 1];
};
+agent.Device = require('./device');
+agent.OS = require('./os');
+agent.Carrier = require('./carrier');
+
if (!module.parent) {
var assert = require('assert'),
OS = require('./os'),
View
2 package.json
@@ -1,5 +1,5 @@
{
- "version": "0.0.0",
+ "version": "0.1.0",
"license": "BSD",
"description": "agent-line",
"author": "KOBA789 <kobahide789@gmail.com> (http://koba789.com/)",

0 comments on commit d93c5e0

Please sign in to comment.