Skip to content

Commit

Permalink
Add Client side version
Browse files Browse the repository at this point in the history
  • Loading branch information
biggora committed May 14, 2015
1 parent 8d430bd commit 761d974
Show file tree
Hide file tree
Showing 22 changed files with 924 additions and 179 deletions.
23 changes: 20 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/.idea
/nbproject
node_modules/
# Editor
.idea
nbproject

# Windows
Thumbs.db
ehthumbs.db
Desktop.ini

# Linux
.directory
*~

# npm
node_modules
*.log
*.gz

# Coveralls
coverage
23 changes: 23 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"node": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"jquery": true,
"white": true,
"multistr": true
}
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.idea/*
nbproject/*
node_modules/*
dist/*
Gruntfile.js
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ language: node_js
node_js:
- 0.10
- 0.11
- 0.12
54 changes: 54 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Created by Alex on 5/14/2015.
*/

module.exports = function(grunt) {
'use strict';

// Force use of Unix newlines
grunt.util.linefeed = '\n';
grunt.file.defaultEncoding = 'utf8';

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*!\n' +
' * express-useragent.js v<%= pkg.version %> (<%= pkg.homepage %>)\n' +
' * Copyright 2011-<%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
' * Licensed under <%= _.pluck(pkg.licenses, "type") %> (<%= _.pluck(pkg.licenses, "url") %>)\n' +
' */\n',
clean: {
build: ["dist/*.js"]
},
'string-replace': {
dist: {
files: [{
src: 'lib/express-useragent.js',
dest: 'dist/express-useragent.js'
}],
options: {
replacements: [{
pattern: 'module.exports.UserAgent',
replacement: 'window.UserAgent'
}]
}
}
},
uglify: {
options: {
banner: '<%= banner %>'
},
forbrowser: {
src: 'dist/<%= pkg.name %>.js',
dest: 'dist/<%= pkg.name %>.min.js'
}
}
});

require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
grunt.registerTask('build', [
'clean:build',
'string-replace',
'uglify'
]);
grunt.registerTask('default', 'build');
};
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2014 Alexey Gordeyev

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 changes: 43 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ To install express-useragent:

## Usage overview

### Simple
### Simple Node App

```js
var http = require('http')
Expand All @@ -39,7 +39,7 @@ is permanently included
var useragent = require('express-useragent');

module.exports = function (app, express) {
app.configure(function () {
app.use(function () {
app.use(useragent.express());
});
};
Expand All @@ -48,9 +48,9 @@ module.exports = function (app, express) {
### for [ExpressJS](http://expressjs.com/)

```js
var express = require('express')
, app = express.createServer()
, useragent = require('express-useragent');
var express = require('express');
var app = express();
var useragent = require('express-useragent');

app.use(useragent.express());
app.get('/', function(req, res){
Expand All @@ -59,24 +59,6 @@ app.get('/', function(req, res){
app.listen(3000);
```

### for [CompoundJS](http://compoundjs.com)

$ compound install https://github.com/biggora/express-useragent.git

#### or manual setup in project config/environment.js

```js
var useragent = require('express-useragent');

app.configure(function () {

// init useragent
app.use(useragent.express());

app.use(app.router);
});
```

module provides details such as the following:

```js
Expand All @@ -89,7 +71,7 @@ module provides details such as the following:
"Version":"17.0.963.79",
"OS":"Windows 7",
"Platform":"Microsoft Windows",
"source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11"
"source":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79..."
}

```
Expand All @@ -102,6 +84,43 @@ provides an easy way to access the user-agent as:
- `req.useragent` from your app server
- `useragent` helper accessible from your `express` views.

## Client Side

* Clone the repo: `git clone git://github.com/biggora/express-useragent.git`
* Or Install with [Bower](http://twitter.github.com/bower): `bower install express-useragent`.

The client side version of express-useragent available in the `dist/` subdirectory.

#### Include file in your HTML. The minimum required for this plugin are:
```
<script type="text/javascript" src="/path/to/express-useragent.js"></script>
```
#### Execute the plugin:
```javascript
var userAgent = new UserAgent().parse(navigator.userAgent);
```


## Running Tests

To run the test suite, first install the dependencies, then run `npm test`:

```bash
npm install
npm test
```

#### Run Example Node App

```bash
npm run-script http
```

#### Run Example Express App

```bash
npm run-script express
```

## In the Wild

Expand Down
67 changes: 67 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "express-useragent",
"description": "Fast User-Agent exposing",
"version": "0.1.8",
"homepage": "https://github.com/biggora/express-useragent/",
"repository": {
"type": "git",
"url": "git://github.com/biggora/express-useragent.git"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/biggora/express-useragent/blob/master/LICENSE"
}
],
"author": {
"name": "Alexey Gordeyev",
"email": "aleksej@gordejev.lv",
"url": "https://github.com/biggora"
},
"contributors": [
{
"name": "Kacper Glowacki",
"url": "https://github.com/kacperus"
},
{
"name": "elisee",
"url": "https://github.com/elisee"
},
{
"name": "Bitdeli Chef",
"url": "https://github.com/bitdeli-chef"
},
{
"name": "Nicolas Tobo",
"url": "https://github.com/nicolastobo"
},
{
"name": "Samy Pess?",
"url": "https://github.com/SamyPesse"
},
{
"name": "Artem Nezvigin",
"url": "https://github.com/artnez"
}
],
"keywords": [
"useragent",
"user-agent",
"express",
"trinte",
"compound",
"middleware"
],
"ignore": [
"**/.*",
"node_modules",
"test",
"lib",
".idea",
"Gruntfile.js",
"index.js",
"index.js"
],
"dependencies": {},
"devDependencies": {}
}
Loading

0 comments on commit 761d974

Please sign in to comment.