1 (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
4 var Stringify = require('./stringify');
5 var Parse = require('./parse');
18 },{"./parse":2,"./stringify":3}],2:[function(require,module,exports){
21 var Utils = require('./utils');
31 strictNullHandling: false,
33 allowPrototypes: false,
38 internals.parseValues = function (str, options) {
41 var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
43 for (var i = 0, il = parts.length; i < il; ++i) {
45 var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
48 obj[Utils.decode(part)] = '';
50 if (options.strictNullHandling) {
51 obj[Utils.decode(part)] = null;
55 var key = Utils.decode(part.slice(0, pos));
56 var val = Utils.decode(part.slice(pos + 1));
58 if (!Object.prototype.hasOwnProperty.call(obj, key)) {
62 obj[key] = [].concat(obj[key]).concat(val);
71 internals.parseObject = function (chain, val, options) {
77 var root = chain.shift();
82 obj = obj.concat(internals.parseObject(chain, val, options));
85 obj = options.plainObjects ? Object.create(null) : {};
86 var cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
87 var index = parseInt(cleanRoot, 10);
88 var indexString = '' + index;
91 indexString === cleanRoot &&
93 (options.parseArrays &&
94 index <= options.arrayLimit)) {
97 obj[index] = internals.parseObject(chain, val, options);
100 obj[cleanRoot] = internals.parseObject(chain, val, options);
108 internals.parseKeys = function (key, val, options) {
114 // Transform dot notation to bracket notation
116 if (options.allowDots) {
117 key = key.replace(/\.([^\.\[]+)/g, '[$1]');
122 var parent = /^([^\[\]]*)/;
123 var child = /(\[[^\[\]]*\])/g;
127 var segment = parent.exec(key);
129 // Stash the parent if it exists
133 // If we aren't using plain objects, optionally prefix keys
134 // that would overwrite object prototype properties
135 if (!options.plainObjects &&
136 Object.prototype.hasOwnProperty(segment[1])) {
138 if (!options.allowPrototypes) {
143 keys.push(segment[1]);
146 // Loop through children appending to the array until we hit depth
149 while ((segment = child.exec(key)) !== null && i < options.depth) {
152 if (!options.plainObjects &&
153 Object.prototype.hasOwnProperty(segment[1].replace(/\[|\]/g, ''))) {
155 if (!options.allowPrototypes) {
159 keys.push(segment[1]);
162 // If there's a remainder, just add whatever is left
165 keys.push('[' + key.slice(segment.index) + ']');
168 return internals.parseObject(keys, val, options);
172 module.exports = function (str, options) {
174 options = options || {};
175 options.delimiter = typeof options.delimiter === 'string' || Utils.isRegExp(options.delimiter) ? options.delimiter : internals.delimiter;
176 options.depth = typeof options.depth === 'number' ? options.depth : internals.depth;
177 options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : internals.arrayLimit;
178 options.parseArrays = options.parseArrays !== false;
179 options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : internals.allowDots;
180 options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : internals.plainObjects;
181 options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : internals.allowPrototypes;
182 options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : internals.parameterLimit;
183 options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
187 typeof str === 'undefined') {
189 return options.plainObjects ? Object.create(null) : {};
192 var tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
193 var obj = options.plainObjects ? Object.create(null) : {};
195 // Iterate over the keys and setup the new object
197 var keys = Object.keys(tempObj);
198 for (var i = 0, il = keys.length; i < il; ++i) {
200 var newObj = internals.parseKeys(key, tempObj[key], options);
201 obj = Utils.merge(obj, newObj, options);
204 return Utils.compact(obj);
207 },{"./utils":4}],3:[function(require,module,exports){
210 var Utils = require('./utils');
217 arrayPrefixGenerators: {
218 brackets: function (prefix, key) {
220 return prefix + '[]';
222 indices: function (prefix, key) {
224 return prefix + '[' + key + ']';
226 repeat: function (prefix, key) {
231 strictNullHandling: false
235 internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, filter) {
237 if (typeof filter === 'function') {
238 obj = filter(prefix, obj);
240 else if (Utils.isBuffer(obj)) {
241 obj = obj.toString();
243 else if (obj instanceof Date) {
244 obj = obj.toISOString();
246 else if (obj === null) {
247 if (strictNullHandling) {
248 return Utils.encode(prefix);
254 if (typeof obj === 'string' ||
255 typeof obj === 'number' ||
256 typeof obj === 'boolean') {
258 return [Utils.encode(prefix) + '=' + Utils.encode(obj)];
263 if (typeof obj === 'undefined') {
267 var objKeys = Array.isArray(filter) ? filter : Object.keys(obj);
268 for (var i = 0, il = objKeys.length; i < il; ++i) {
269 var key = objKeys[i];
271 if (Array.isArray(obj)) {
272 values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, filter));
275 values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, filter));
283 module.exports = function (obj, options) {
285 options = options || {};
286 var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
287 var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
290 if (typeof options.filter === 'function') {
291 filter = options.filter;
292 obj = filter('', obj);
294 else if (Array.isArray(options.filter)) {
295 objKeys = filter = options.filter;
300 if (typeof obj !== 'object' ||
307 if (options.arrayFormat in internals.arrayPrefixGenerators) {
308 arrayFormat = options.arrayFormat;
310 else if ('indices' in options) {
311 arrayFormat = options.indices ? 'indices' : 'repeat';
314 arrayFormat = 'indices';
317 var generateArrayPrefix = internals.arrayPrefixGenerators[arrayFormat];
320 objKeys = Object.keys(obj);
322 for (var i = 0, il = objKeys.length; i < il; ++i) {
323 var key = objKeys[i];
324 keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, filter));
327 return keys.join(delimiter);
330 },{"./utils":4}],4:[function(require,module,exports){
337 internals.hexTable = new Array(256);
338 for (var h = 0; h < 256; ++h) {
339 internals.hexTable[h] = '%' + ((h < 16 ? '0' : '') + h.toString(16)).toUpperCase();
343 exports.arrayToObject = function (source, options) {
345 var obj = options.plainObjects ? Object.create(null) : {};
346 for (var i = 0, il = source.length; i < il; ++i) {
347 if (typeof source[i] !== 'undefined') {
357 exports.merge = function (target, source, options) {
363 if (typeof source !== 'object') {
364 if (Array.isArray(target)) {
367 else if (typeof target === 'object') {
368 target[source] = true;
371 target = [target, source];
377 if (typeof target !== 'object') {
378 target = [target].concat(source);
382 if (Array.isArray(target) &&
383 !Array.isArray(source)) {
385 target = exports.arrayToObject(target, options);
388 var keys = Object.keys(source);
389 for (var k = 0, kl = keys.length; k < kl; ++k) {
391 var value = source[key];
393 if (!Object.prototype.hasOwnProperty.call(target, key)) {
397 target[key] = exports.merge(target[key], value, options);
405 exports.decode = function (str) {
408 return decodeURIComponent(str.replace(/\+/g, ' '));
414 exports.encode = function (str) {
416 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
417 // It has been adapted here for stricter adherence to RFC 3986
418 if (str.length === 0) {
422 if (typeof str !== 'string') {
427 for (var i = 0, il = str.length; i < il; ++i) {
428 var c = str.charCodeAt(i);
430 if (c === 0x2D || // -
434 (c >= 0x30 && c <= 0x39) || // 0-9
435 (c >= 0x41 && c <= 0x5A) || // a-z
436 (c >= 0x61 && c <= 0x7A)) { // A-Z
443 out += internals.hexTable[c];
448 out += internals.hexTable[0xC0 | (c >> 6)] + internals.hexTable[0x80 | (c & 0x3F)];
452 if (c < 0xD800 || c >= 0xE000) {
453 out += internals.hexTable[0xE0 | (c >> 12)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)];
458 c = 0x10000 + (((c & 0x3FF) << 10) | (str.charCodeAt(i) & 0x3FF));
459 out += internals.hexTable[0xF0 | (c >> 18)] + internals.hexTable[0x80 | ((c >> 12) & 0x3F)] + internals.hexTable[0x80 | ((c >> 6) & 0x3F)] + internals.hexTable[0x80 | (c & 0x3F)];
465 exports.compact = function (obj, refs) {
467 if (typeof obj !== 'object' ||
474 var lookup = refs.indexOf(obj);
481 if (Array.isArray(obj)) {
484 for (var i = 0, il = obj.length; i < il; ++i) {
485 if (typeof obj[i] !== 'undefined') {
486 compacted.push(obj[i]);
493 var keys = Object.keys(obj);
494 for (i = 0, il = keys.length; i < il; ++i) {
496 obj[key] = exports.compact(obj[key], refs);
503 exports.isRegExp = function (obj) {
505 return Object.prototype.toString.call(obj) === '[object RegExp]';
509 exports.isBuffer = function (obj) {
512 typeof obj === 'undefined') {
517 return !!(obj.constructor &&
518 obj.constructor.isBuffer &&
519 obj.constructor.isBuffer(obj));