From d93c5e0af624abe1982c662db4ff669bf4cc3001 Mon Sep 17 00:00:00 2001 From: koba789 Date: Thu, 13 Dec 2012 16:34:01 +0900 Subject: [PATCH] write a little document and fix a few bugs --- README.md | 37 +++++++++++++++++++++++++++++++++++++ lib/enum.js | 11 ++++++++++- lib/index.js | 4 ++++ package.json | 2 +- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e69de29..cb97295 100644 --- a/README.md +++ b/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 +``` \ No newline at end of file diff --git a/lib/enum.js b/lib/enum.js index 99d6c9d..2c0312f 100644 --- a/lib/enum.js +++ b/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); }; diff --git a/lib/index.js b/lib/index.js index c46f0a4..b2e2983 100644 --- a/lib/index.js +++ b/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'), diff --git a/package.json b/package.json index 707fb30..c3f14e0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "0.0.0", + "version": "0.1.0", "license": "BSD", "description": "agent-line", "author": "KOBA789 (http://koba789.com/)",