Initial commit
[yaffs-website] / node_modules / tiny-lr / lib / middleware / query.js
1 /*! Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca> */
2 /* > https://raw.githubusercontent.com/visionmedia/express/master/lib/middleware/query.js */
3
4 /**
5  * Module dependencies.
6  */
7
8 var qs = require('qs');
9 var parseUrl = require('parseurl');
10
11 /**
12  * Query:
13  *
14  * Automatically parse the query-string when available,
15  * populating the `req.query` object using
16  * [qs](https://github.com/visionmedia/node-querystring).
17  *
18  * Examples:
19  *
20  *       .use(connect.query())
21  *       .use(function(req, res){
22  *         res.end(JSON.stringify(req.query));
23  *       });
24  *
25  *  The `options` passed are provided to qs.parse function.
26  *
27  * @param {Object} options
28  * @return {Function}
29  * @api public
30  */
31
32 module.exports = function query(options){
33   return function query(req, res, next){
34     if (!req.query) {
35       req.query = ~req.url.indexOf('?')
36         ? qs.parse(parseUrl(req).query, options)
37         : {};
38     }
39
40     next();
41   };
42 };