mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Improved query string handling
This commit is contained in:
parent
e51f8533bd
commit
e1ffad5694
8
main.js
8
main.js
@ -123,13 +123,7 @@ function main() {
|
||||
env.opts = jsdoc.opts.parser.parse(env.args);
|
||||
|
||||
if (env.opts.query) {
|
||||
var q = env.opts.query;
|
||||
env.opts.query = {};
|
||||
var queryString = {};
|
||||
q.replace( // thanks Steven Benner
|
||||
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
|
||||
function($0, $1, $2, $3) { env.opts.query[$1] = $3; }
|
||||
);
|
||||
env.opts.query = require('common/query').toObject(env.opts.query);
|
||||
}
|
||||
|
||||
if (env.opts.help) {
|
||||
|
||||
42
modules/common/query.js
Normal file
42
modules/common/query.js
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
Support parsing of command line querystrings into JS objects.
|
||||
@module common/query
|
||||
@example
|
||||
|
||||
-q 'format=xml&root+node=documentation&publish='
|
||||
|
||||
> becomes
|
||||
|
||||
{
|
||||
"format": "xml",
|
||||
"root node": "documentation",
|
||||
"publish": true
|
||||
}
|
||||
*/
|
||||
(function() {
|
||||
var query = module.exports = {
|
||||
/**
|
||||
@name module:common/query.toObject
|
||||
@param {string} querystring
|
||||
@returns {object}
|
||||
*/
|
||||
toObject: function(querystring) {
|
||||
var object = {};
|
||||
|
||||
querystring.replace(
|
||||
new RegExp('([^?=&]+)(?:=([^&]*))?', 'g'),
|
||||
function($0, key, val) {
|
||||
object[query._decode(key)] =
|
||||
(typeof val !== 'undefined')? query._decode(val) : true;
|
||||
}
|
||||
);
|
||||
|
||||
return object;
|
||||
},
|
||||
|
||||
/** @private */
|
||||
_decode: function(string) {
|
||||
return decodeURIComponent( string.replace(/\+/g, ' ') );
|
||||
}
|
||||
};
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user