Skip to content

Commit

Permalink
write a little document and fix a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOBA789 committed Dec 13, 2012
1 parent ff05851 commit d93c5e0
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
37 changes: 37 additions & 0 deletions 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
```
11 changes: 10 additions & 1 deletion lib/enum.js
Expand Up @@ -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);
};
Expand Down
4 changes: 4 additions & 0 deletions lib/index.js
Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion 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/)",
Expand Down

0 comments on commit d93c5e0

Please sign in to comment.