-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.json
73 lines (73 loc) · 14 KB
/
package.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
"name": "useragent",
"version": "2.0.7",
"description": "Fastest, most accurate & effecient user agent string parser, uses Browserscope's research for parsing",
"author": {
"name": "Arnout Kazemier"
},
"main": "./index.js",
"keywords": [
"agent",
"browser",
"browserscope",
"os",
"parse",
"parser",
"ua",
"ua-parse",
"ua-parser",
"user agent",
"user",
"user-agent",
"useragent",
"version"
],
"maintainers": [
{
"name": "Arnout Kazemier",
"email": "info@3rd-Eden.com",
"url": "http://www.3rd-Eden.com"
}
],
"license": {
"type": "MIT",
"url": "https://github.com/3rd-Eden/useragent/blob/master/LICENSE"
},
"repository": {
"type": "git",
"url": "http://github.com/3rd-Eden/useragent.git"
},
"devDependencies": {
"should": "*",
"mocha": "*",
"long-stack-traces": "0.1.x",
"yamlparser": "0.0.x",
"request": "2.9.x",
"semver": "1.0.x",
"pre-commit": "0.0.x"
},
"pre-commit": [
"test",
"update"
],
"scripts": {
"test": "mocha $(find test -name '*.test.js')",
"qa": "mocha --ui exports $(find test -name '*.qa.js')",
"update": "node ./bin/update.js"
},
"dependencies": {
"lru-cache": "2.2.x"
},
"readme": "# useragent - high performance user agent parser for Node.js\n\nUseragent originated as port of [browserscope.org][browserscope]'s user agent\nparser project also known as ua-parser. Useragent allows you to parse user agent\nstring with high accuracy by using hand tuned dedicated regular expressions for\nbrowser matching. This database is needed to ensure that every browser is\ncorrectly parsed as every browser vendor implements it's own user agent schema.\nThis is why regular user agent parsers have major issues because they will\nmost likely parse out the wrong browser name or confuse the render engine version\nwith the actual version of the browser.\n\n---\n\n### Build status [![BuildStatus](https://secure.travis-ci.org/3rd-Eden/useragent.png?branch=master)](http://travis-ci.org/3rd-Eden/useragent)\n\n---\n\n### High performance\n\nThe module has been developed with a benchmark driven approach. It has a\npre-compiled library that contains all the Regular Expressions and uses deferred\nor on demand parsing for Operating System and device information. All this\nengineering effort has been worth it as [this benchmark shows][benchmark]:\n\n```\nStarting the benchmark, parsing 62 useragent strings per run\n\nExecuted benchmark against node module: \"useragent\"\nCount (61), Cycles (5), Elapsed (5.559), Hz (1141.3739447904327)\n\nExecuted benchmark against node module: \"useragent_parser\"\nCount (29), Cycles (3), Elapsed (5.448), Hz (545.6817291171243)\n\nExecuted benchmark against node module: \"useragent-parser\"\nCount (16), Cycles (4), Elapsed (5.48), Hz (304.5373431830105)\n\nExecuted benchmark against node module: \"ua-parser\"\nCount (54), Cycles (3), Elapsed (5.512), Hz (1018.7561434659247)\n\nModule: \"useragent\" is the user agent fastest parser.\n```\n\n---\n\n### Installation\n\nInstallation is done using the Node Package Manager (NPM). If you don't have\nNPM installed on your system you can download it from\n[npmjs.org][npm]\n\n```\nnpm install useragent --save\n```\n\nThe `--save` flag tells NPM to automatically add it to your `package.json` file.\n\n---\n\n### API\n\n\nInclude the `useragent` parser in you node.js application:\n\n```js\nvar useragent = require('useragent');\n```\n\nThe `useragent` library allows you do use the automatically installed RegExp\nlibrary or you can fetch it live from the remote servers. So if you are\nparanoid and always want your RegExp library to be up to date to match with\nagent the widest range of `useragent` strings you can do:\n\n```js\nvar useragent = require('useragent');\nuseragent(true);\n```\n\nThis will async load the database from the server and compile it to a proper\nJavaScript supported format. If it fails to compile or load it from the remote\nlocation it will just fall back silently to the shipped version. If you want to\nuse this feature you need to add `yamlparser` and `request` to your package.json\n\n```\nnpm install yamlparser --save\nnpm install request --save\n```\n\n#### useragent.parse(useragent string[, js useragent]);\n\nThis is the actual user agent parser, this is where all the magic is happening.\nThe function accepts 2 arguments, both should be a `string`. The first argument\nshould the user agent string that is known on the server from the\n`req.headers.useragent` header. The other argument is optional and should be\nthe user agent string that you see in the browser, this can be send from the\nbrowser using a xhr request or something like this. This allows you detect if\nthe user is browsing the web using the `Chrome Frame` extension.\n\nThe parser returns a Agent instance, this allows you to output user agent\ninformation in different predefined formats. See the Agent section for more\ninformation.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\n\n// example for parsing both the useragent header and a optional js useragent\nvar agent2 = useragent.parse(req.headers['user-agent'], req.query.jsuseragent);\n```\n\nThe parse method returns a `Agent` instance which contains all details about the\nuser agent. See the Agent section of the API documentation for the available\nmethods.\n\n#### useragent.lookup(useragent string[, js useragent]);\n\nThis provides the same functionality as above, but it caches the user agent\nstring and it's parsed result in memory to provide faster lookups in the\nfuture. This can be handy if you expect to parse a lot of user agent strings.\n\nIt uses the same arguments as the `useragent.parse` method and returns exactly\nthe same result, but it's just cached.\n\n```js\nvar agent = useragent.lookup(req.headers['user-agent']);\n```\n\nAnd this is a serious performance improvement as shown in this benchmark:\n\n```\nExecuted benchmark against method: \"useragent.parse\"\nCount (49), Cycles (3), Elapsed (5.534), Hz (947.6844321931629)\n\nExecuted benchmark against method: \"useragent.lookup\"\nCount (11758), Cycles (3), Elapsed (5.395), Hz (229352.03831239208)\n```\n\n#### useragent.fromJSON(obj);\n\nTransforms the JSON representation of a `Agent` instance back in to a working\n`Agent` instance\n\n```js\nvar agent = useragent.parse(req.headers['user-agent'])\n , another = useragent.fromJSON(JSON.stringify(agent));\n\nconsole.log(agent == another);\n```\n\n#### useragent.is(useragent string).browsername;\n\nThis api provides you with a quick and dirty browser lookup. The underlying\ncode is usually found on client side scripts so it's not the same quality as\nour `useragent.parse` method but it might be needed for legacy reasons.\n\n`useragent.is` returns a object with potential matched browser names\n\n```js\nuseragent.is(req.headers['user-agent']).firefox // true\nuseragent.is(req.headers['user-agent']).safari // false\nvar ua = useragent.is(req.headers['user-agent'])\n\n// the object\n{\n version: '3'\n webkit: false\n opera: false\n ie: false\n chrome: false\n safari: false\n mobile_safari: false\n firefox: true\n}\n```\n\n---\n\n### Agents, OperatingSystem and Device instances\n\nMost of the methods mentioned above return a Agent instance. The Agent exposes\nthe parsed out information from the user agent strings. This allows us to\nextend the agent with more methods that do not necessarily need to be in the\ncore agent instance, allowing us to expose a plugin interface for third party\ndevelopers and at the same time create a uniform interface for all versioning.\n\nThe Agent has the following property\n\n- `family` The browser family, or browser name, it defaults to Other.\n- `major` The major version number of the family, it defaults to 0.\n- `minor` The minor version number of the family, it defaults to 0.\n- `patch` The patch version number of the family, it defaults to 0.\n\nIn addition to the properties mentioned above, it also has 2 special properties,\nwhich are:\n\n- `os` OperatingSystem instance\n- `device` Device instance\n\nWhen you access those 2 properties the agent will do on demand parsing of the\nOperating System or/and Device information.\n\nThe OperatingSystem has the same properties as the Agent, for the Device we\ndon't have any versioning information available, so only the `family` property is\nset there. If we cannot find the family, they will default to `Other`.\n\nThe following methods are available:\n\n#### Agent.toAgent();\n\nReturns the family and version number concatinated in a nice human readable\nstring.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.toAgent(); // 'Chrome 15.0.874'\n```\n\n#### Agent.toString();\n\nReturns the results of the `Agent.toAgent()` but also adds the parsed operating\nsystem to the string in a human readable format.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.toString(); // 'Chrome 15.0.874 / Mac OS X 10.8.1'\n\n// as it's a to string method you can also concat it with another string\n'your useragent is ' + agent;\n// 'your useragent is Chrome 15.0.874 / Mac OS X 10.8.1'\n```\n#### Agent.toVersion();\n\nReturns the version of the browser in a human readable string.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.toVersion(); // '15.0.874'\n```\n\n#### Agent.toJSON();\n\nGenerates a JSON representation of the Agent. By using the `toJSON` method we\nautomatically allow it to be stringified when supplying as to the\n`JSON.stringify` method.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.toJSON(); // returns an object\n\nJSON.stringify(agent);\n```\n\n#### OperatingSystem.toString();\n\nGenerates a stringified version of operating system;\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.os.toString(); // 'Mac OSX 10.8.1'\n```\n\n#### OperatingSystem.toVersion();\n\nGenerates a stringified version of operating system's version;\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.os.toVersion(); // '10.8.1'\n```\n\n#### OperatingSystem.toJSON();\n\nGenerates a JSON representation of the OperatingSystem. By using the `toJSON`\nmethod we automatically allow it to be stringified when supplying as to the\n`JSON.stringify` method.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.os.toJSON(); // returns an object\n\nJSON.stringify(agent.os);\n```\n\n#### Device.toString();\n\nGenerates a stringified version of device;\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.device.toString(); // 'Asus A100'\n```\n\n#### Device.toVersion();\n\nGenerates a stringified version of device's version;\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.device.toVersion(); // '' , no version found but could also be '0.0.0'\n```\n\n#### Device.toJSON();\n\nGenerates a JSON representation of the Device. By using the `toJSON` method we\nautomatically allow it to be stringified when supplying as to the\n`JSON.stringify` method.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.device.toJSON(); // returns an object\n\nJSON.stringify(agent.device);\n```\n\n### Adding more features to the useragent\n\nAs I wanted to keep the core of the user agent parser as clean and fast as\npossible I decided to move some of the initially planned features to a new\n`plugin` file.\n\nThese extensions to the Agent prototype can be loaded by requiring the\n`useragent/features` file:\n\n```js\nvar useragent = require('useragent');\nrequire('useragent/features');\n```\n\nThe initial release introduces 1 new method, satisfies, which allows you to see\nif the version number of the browser satisfies a certain range. It uses the\nsemver library to do all the range calculations but here is a small summary of\nthe supported range styles:\n\n* `>1.2.3` Greater than a specific version.\n* `<1.2.3` Less than.\n* `1.2.3 - 2.3.4` := `>=1.2.3 <=2.3.4`.\n* `~1.2.3` := `>=1.2.3 <1.3.0`.\n* `~1.2` := `>=1.2.0 <2.0.0`.\n* `~1` := `>=1.0.0 <2.0.0`.\n* `1.2.x` := `>=1.2.0 <1.3.0`.\n* `1.x` := `>=1.0.0 <2.0.0`.\n\nAs it requires the `semver` module to function you need to install it\nseperately:\n\n```\nnpm install semver --save\n```\n\n#### Agent.satisfies('range style here');\n\nCheck if the agent matches the supplied range.\n\n```js\nvar agent = useragent.parse(req.headers['user-agent']);\nagent.satisfies('15.x || >=19.5.0 || 25.0.0 - 17.2.3'); // true\nagent.satisfies('>16.12.0'); // false\n```\n---\n\n### Migrations\n\nFor small changes between version please review the [changelog][changelog].\n\n#### Upgrading from 1.10 to 2.0.0\n\n- `useragent.fromAgent` has been removed.\n- `agent.toJSON` now returns an Object, use `JSON.stringify(agent)` for the old\n behaviour.\n- `agent.os` is now an `OperatingSystem` instance with version numbers. If you\n still a string only representation do `agent.os.toString()`.\n- `semver` has been removed from the dependencies, so if you are using the\n `require('useragent/features')` you need to add it to your own dependencies\n\n#### Upgrading from 0.1.2 to 1.0.0\n\n- `useragent.browser(ua)` has been renamed to `useragent.is(ua)`.\n- `useragent.parser(ua, jsua)` has been renamed to `useragent.parse(ua, jsua)`.\n- `result.pretty()` has been renamed to `result.toAgent()`.\n- `result.V1` has been renamed to `result.major`.\n- `result.V2` has been renamed to `result.minor`.\n- `result.V3` has been renamed to `result.patch`.\n- `result.prettyOS()` has been removed.\n- `result.match` has been removed.\n\n---\n\n### License\n\nMIT\n\n[browserscope]: http://www.browserscope.org/\n[benchmark]: /3rd-Eden/useragent/blob/master/benchmark/run.js\n[changelog]: /3rd-Eden/useragent/blob/master/CHANGELOG.md\n[npm]: http://npmjs.org\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/3rd-Eden/useragent/issues"
},
"homepage": "https://github.com/3rd-Eden/useragent",
"_id": "useragent@2.0.7",
"dist": {
"shasum": "60b541ad90a61d9291d0782e4d51b5ffe916f2bf"
},
"_from": "useragent@2.0.7",
"_resolved": "https://registry.npmjs.org/useragent/-/useragent-2.0.7.tgz"
}