Browse files

Added machine variants of family and os

  • Loading branch information...
1 parent 8e3d9e9 commit e3e4178ea0ec2d3771dd2deb61222c4dbfcc964d @tj committed Oct 2, 2011
Showing with 23 additions and 4 deletions.
  1. +4 −4 Readme.md
  2. +19 −0 lib/connect-useragent.js
View
8 Readme.md
@@ -25,11 +25,11 @@ connect()
provides details such as the following:
```js
-{ family: 'Chrome',
- major: '16',
+{ family: { name: 'Safari', machine: 'safari' },
+ major: '5',
minor: '0',
- patch: '891',
- os: 'Mac OS X' }
+ patch: '4',
+ os: { name: 'Mac OS X', machine: 'mac-os-x' } }
```
## License
View
19 lib/connect-useragent.js
@@ -26,6 +26,25 @@ module.exports = useragent;
function useragent() {
return function(req, res, next){
req.agent = ua.parse(req.headers['user-agent'] || '');
+ var family = req.agent.family
+ , os = req.agent.os;
+ req.agent.family = { name: family, machine: machine(family) };
+ req.agent.os = { name: os, machine: machine(os) };
next();
}
+}
+
+/**
+ * Convert the given `str` to a machine-readable string
+ * suitable for use as an html class name etc.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+function machine(str) {
+ return str
+ .toLowerCase()
+ .replace(/ +/g, '-');
}

0 comments on commit e3e4178

Please sign in to comment.