mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
/**
|
|
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, ' ') );
|
|
}
|
|
};
|
|
})(); |