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');
12 },{"./parse":2,"./stringify":3}],2:[function(require,module,exports){
15 var Utils = require('./utils');
22 strictNullHandling: false,
24 allowPrototypes: false,
28 var has = Object.prototype.hasOwnProperty;
30 internals.parseValues = function (str, options) {
32 var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
34 for (var i = 0; i < parts.length; ++i) {
36 var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
39 obj[Utils.decode(part)] = '';
41 if (options.strictNullHandling) {
42 obj[Utils.decode(part)] = null;
45 var key = Utils.decode(part.slice(0, pos));
46 var val = Utils.decode(part.slice(pos + 1));
48 if (has.call(obj, key)) {
49 obj[key] = [].concat(obj[key]).concat(val);
59 internals.parseObject = function (chain, val, options) {
64 var root = chain.shift();
69 obj = obj.concat(internals.parseObject(chain, val, options));
71 obj = options.plainObjects ? Object.create(null) : {};
72 var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
73 var index = parseInt(cleanRoot, 10);
77 String(index) === cleanRoot &&
79 (options.parseArrays && index <= options.arrayLimit)
82 obj[index] = internals.parseObject(chain, val, options);
84 obj[cleanRoot] = internals.parseObject(chain, val, options);
91 internals.parseKeys = function (givenKey, val, options) {
96 // Transform dot notation to bracket notation
97 var key = options.allowDots ? givenKey.replace(/\.([^\.\[]+)/g, '[$1]') : givenKey;
101 var brackets = /(\[[^[\]]*])/;
102 var child = /(\[[^[\]]*])/g;
106 var segment = brackets.exec(key);
107 var parent = segment ? key.slice(0, segment.index) : key;
109 // Stash the parent if it exists
113 // If we aren't using plain objects, optionally prefix keys
114 // that would overwrite object prototype properties
115 if (!options.plainObjects && has.call(Object.prototype, parent)) {
116 if (!options.allowPrototypes) {
124 // Loop through children appending to the array until we hit depth
127 while ((segment = child.exec(key)) !== null && i < options.depth) {
129 if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
130 if (!options.allowPrototypes) {
134 keys.push(segment[1]);
137 // If there's a remainder, just add whatever is left
140 keys.push('[' + key.slice(segment.index) + ']');
143 return internals.parseObject(keys, val, options);
146 module.exports = function (str, opts) {
147 var options = opts || {};
148 options.delimiter = typeof options.delimiter === 'string' || Utils.isRegExp(options.delimiter) ? options.delimiter : internals.delimiter;
149 options.depth = typeof options.depth === 'number' ? options.depth : internals.depth;
150 options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : internals.arrayLimit;
151 options.parseArrays = options.parseArrays !== false;
152 options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : internals.allowDots;
153 options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : internals.plainObjects;
154 options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : internals.allowPrototypes;
155 options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : internals.parameterLimit;
156 options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
161 typeof str === 'undefined'
163 return options.plainObjects ? Object.create(null) : {};
166 var tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
167 var obj = options.plainObjects ? Object.create(null) : {};
169 // Iterate over the keys and setup the new object
171 var keys = Object.keys(tempObj);
172 for (var i = 0; i < keys.length; ++i) {
174 var newObj = internals.parseKeys(key, tempObj[key], options);
175 obj = Utils.merge(obj, newObj, options);
178 return Utils.compact(obj);
181 },{"./utils":4}],3:[function(require,module,exports){
184 var Utils = require('./utils');
188 arrayPrefixGenerators: {
189 brackets: function (prefix) {
190 return prefix + '[]';
192 indices: function (prefix, key) {
193 return prefix + '[' + key + ']';
195 repeat: function (prefix) {
199 strictNullHandling: false,
204 internals.stringify = function (object, prefix, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter, sort) {
206 if (typeof filter === 'function') {
207 obj = filter(prefix, obj);
208 } else if (Utils.isBuffer(obj)) {
210 } else if (obj instanceof Date) {
211 obj = obj.toISOString();
212 } else if (obj === null) {
213 if (strictNullHandling) {
214 return encode ? Utils.encode(prefix) : prefix;
220 if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean') {
222 return [Utils.encode(prefix) + '=' + Utils.encode(obj)];
224 return [prefix + '=' + obj];
229 if (typeof obj === 'undefined') {
234 if (Array.isArray(filter)) {
237 var keys = Object.keys(obj);
238 objKeys = sort ? keys.sort(sort) : keys;
241 for (var i = 0; i < objKeys.length; ++i) {
242 var key = objKeys[i];
244 if (skipNulls && obj[key] === null) {
248 if (Array.isArray(obj)) {
249 values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, skipNulls, encode, filter));
251 values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, skipNulls, encode, filter));
258 module.exports = function (object, opts) {
260 var options = opts || {};
261 var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
262 var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
263 var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : internals.skipNulls;
264 var encode = typeof options.encode === 'boolean' ? options.encode : internals.encode;
265 var sort = typeof options.sort === 'function' ? options.sort : null;
268 if (typeof options.filter === 'function') {
269 filter = options.filter;
270 obj = filter('', obj);
271 } else if (Array.isArray(options.filter)) {
272 objKeys = filter = options.filter;
277 if (typeof obj !== 'object' || obj === null) {
282 if (options.arrayFormat in internals.arrayPrefixGenerators) {
283 arrayFormat = options.arrayFormat;
284 } else if ('indices' in options) {
285 arrayFormat = options.indices ? 'indices' : 'repeat';
287 arrayFormat = 'indices';
290 var generateArrayPrefix = internals.arrayPrefixGenerators[arrayFormat];
293 objKeys = Object.keys(obj);
300 for (var i = 0; i < objKeys.length; ++i) {
301 var key = objKeys[i];
303 if (skipNulls && obj[key] === null) {
307 keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter, sort));
310 return keys.join(delimiter);
313 },{"./utils":4}],4:[function(require,module,exports){
316 var hexTable = (function () {
317 var array = new Array(256);
318 for (var i = 0; i < 256; ++i) {
319 array[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase();
325 var has = Object.prototype.hasOwnProperty;
327 exports.arrayToObject = function (source, options) {
328 var obj = options.plainObjects ? Object.create(null) : {};
329 for (var i = 0; i < source.length; ++i) {
330 if (typeof source[i] !== 'undefined') {
338 exports.merge = function (target, source, options) {
343 if (typeof source !== 'object') {
344 if (Array.isArray(target)) {
346 } else if (typeof target === 'object') {
347 if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
348 target[source] = true;
351 return [target, source];
357 if (typeof target !== 'object') {
358 return [target].concat(source);
361 var mergeTarget = target;
362 if (Array.isArray(target) && !Array.isArray(source)) {
363 mergeTarget = exports.arrayToObject(target, options);
366 return Object.keys(source).reduce(function (acc, key) {
367 var value = source[key];
369 if (has.call(acc, key)) {
370 acc[key] = exports.merge(acc[key], value, options);
378 exports.decode = function (str) {
380 return decodeURIComponent(str.replace(/\+/g, ' '));
386 exports.encode = function (str) {
387 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
388 // It has been adapted here for stricter adherence to RFC 3986
389 if (str.length === 0) {
393 var string = typeof str === 'string' ? str : String(str);
396 for (var i = 0; i < string.length; ++i) {
397 var c = string.charCodeAt(i);
404 (c >= 0x30 && c <= 0x39) || // 0-9
405 (c >= 0x41 && c <= 0x5A) || // a-z
406 (c >= 0x61 && c <= 0x7A) // A-Z
408 out += string.charAt(i);
413 out = out + hexTable[c];
418 out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
422 if (c < 0xD800 || c >= 0xE000) {
423 out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
428 c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
429 out += (hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
435 exports.compact = function (obj, references) {
436 if (typeof obj !== 'object' || obj === null) {
440 var refs = references || [];
441 var lookup = refs.indexOf(obj);
448 if (Array.isArray(obj)) {
451 for (var i = 0; i < obj.length; ++i) {
452 if (typeof obj[i] !== 'undefined') {
453 compacted.push(obj[i]);
460 var keys = Object.keys(obj);
461 for (var j = 0; j < keys.length; ++j) {
463 obj[key] = exports.compact(obj[key], refs);
469 exports.isRegExp = function (obj) {
470 return Object.prototype.toString.call(obj) === '[object RegExp]';
473 exports.isBuffer = function (obj) {
474 if (obj === null || typeof obj === 'undefined') {
478 return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));