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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
4 var replace = String.prototype.replace;
5 var percentTwenties = /%20/g;
10 RFC1738: function (value) {
11 return replace.call(value, percentTwenties, '+');
13 RFC3986: function (value) {
21 },{}],2:[function(require,module,exports){
24 var stringify = require('./stringify');
25 var parse = require('./parse');
26 var formats = require('./formats');
34 },{"./formats":1,"./parse":3,"./stringify":4}],3:[function(require,module,exports){
37 var utils = require('./utils');
39 var has = Object.prototype.hasOwnProperty;
43 allowPrototypes: false,
45 decoder: utils.decode,
50 strictNullHandling: false
53 var parseValues = function parseQueryStringValues(str, options) {
55 var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
56 var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
57 var parts = cleanStr.split(options.delimiter, limit);
59 for (var i = 0; i < parts.length; ++i) {
62 var bracketEqualsPos = part.indexOf(']=');
63 var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
67 key = options.decoder(part, defaults.decoder);
68 val = options.strictNullHandling ? null : '';
70 key = options.decoder(part.slice(0, pos), defaults.decoder);
71 val = options.decoder(part.slice(pos + 1), defaults.decoder);
73 if (has.call(obj, key)) {
74 obj[key] = [].concat(obj[key]).concat(val);
83 var parseObject = function (chain, val, options) {
86 for (var i = chain.length - 1; i >= 0; --i) {
92 obj = obj.concat(leaf);
94 obj = options.plainObjects ? Object.create(null) : {};
95 var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
96 var index = parseInt(cleanRoot, 10);
100 && String(index) === cleanRoot
102 && (options.parseArrays && index <= options.arrayLimit)
107 obj[cleanRoot] = leaf;
117 var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
122 // Transform dot notation to bracket notation
123 var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
127 var brackets = /(\[[^[\]]*])/;
128 var child = /(\[[^[\]]*])/g;
132 var segment = brackets.exec(key);
133 var parent = segment ? key.slice(0, segment.index) : key;
135 // Stash the parent if it exists
139 // If we aren't using plain objects, optionally prefix keys
140 // that would overwrite object prototype properties
141 if (!options.plainObjects && has.call(Object.prototype, parent)) {
142 if (!options.allowPrototypes) {
150 // Loop through children appending to the array until we hit depth
153 while ((segment = child.exec(key)) !== null && i < options.depth) {
155 if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
156 if (!options.allowPrototypes) {
160 keys.push(segment[1]);
163 // If there's a remainder, just add whatever is left
166 keys.push('[' + key.slice(segment.index) + ']');
169 return parseObject(keys, val, options);
172 module.exports = function (str, opts) {
173 var options = opts ? utils.assign({}, opts) : {};
175 if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') {
176 throw new TypeError('Decoder has to be a function.');
179 options.ignoreQueryPrefix = options.ignoreQueryPrefix === true;
180 options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter;
181 options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth;
182 options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults.arrayLimit;
183 options.parseArrays = options.parseArrays !== false;
184 options.decoder = typeof options.decoder === 'function' ? options.decoder : defaults.decoder;
185 options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : defaults.allowDots;
186 options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : defaults.plainObjects;
187 options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : defaults.allowPrototypes;
188 options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : defaults.parameterLimit;
189 options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
191 if (str === '' || str === null || typeof str === 'undefined') {
192 return options.plainObjects ? Object.create(null) : {};
195 var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
196 var obj = options.plainObjects ? Object.create(null) : {};
198 // Iterate over the keys and setup the new object
200 var keys = Object.keys(tempObj);
201 for (var i = 0; i < keys.length; ++i) {
203 var newObj = parseKeys(key, tempObj[key], options);
204 obj = utils.merge(obj, newObj, options);
207 return utils.compact(obj);
210 },{"./utils":5}],4:[function(require,module,exports){
213 var utils = require('./utils');
214 var formats = require('./formats');
216 var arrayPrefixGenerators = {
217 brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
218 return prefix + '[]';
220 indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
221 return prefix + '[' + key + ']';
223 repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
228 var toISO = Date.prototype.toISOString;
233 encoder: utils.encode,
234 encodeValuesOnly: false,
235 serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
236 return toISO.call(date);
239 strictNullHandling: false
242 var stringify = function stringify( // eslint-disable-line func-name-matching
257 if (typeof filter === 'function') {
258 obj = filter(prefix, obj);
259 } else if (obj instanceof Date) {
260 obj = serializeDate(obj);
261 } else if (obj === null) {
262 if (strictNullHandling) {
263 return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix;
269 if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
271 var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder);
272 return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))];
274 return [formatter(prefix) + '=' + formatter(String(obj))];
279 if (typeof obj === 'undefined') {
284 if (Array.isArray(filter)) {
287 var keys = Object.keys(obj);
288 objKeys = sort ? keys.sort(sort) : keys;
291 for (var i = 0; i < objKeys.length; ++i) {
292 var key = objKeys[i];
294 if (skipNulls && obj[key] === null) {
298 if (Array.isArray(obj)) {
299 values = values.concat(stringify(
301 generateArrayPrefix(prefix, key),
314 values = values.concat(stringify(
316 prefix + (allowDots ? '.' + key : '[' + key + ']'),
334 module.exports = function (object, opts) {
336 var options = opts ? utils.assign({}, opts) : {};
338 if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
339 throw new TypeError('Encoder has to be a function.');
342 var delimiter = typeof options.delimiter === 'undefined' ? defaults.delimiter : options.delimiter;
343 var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
344 var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
345 var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
346 var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder;
347 var sort = typeof options.sort === 'function' ? options.sort : null;
348 var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots;
349 var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
350 var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
351 if (typeof options.format === 'undefined') {
352 options.format = formats['default'];
353 } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
354 throw new TypeError('Unknown format option provided.');
356 var formatter = formats.formatters[options.format];
360 if (typeof options.filter === 'function') {
361 filter = options.filter;
362 obj = filter('', obj);
363 } else if (Array.isArray(options.filter)) {
364 filter = options.filter;
370 if (typeof obj !== 'object' || obj === null) {
375 if (options.arrayFormat in arrayPrefixGenerators) {
376 arrayFormat = options.arrayFormat;
377 } else if ('indices' in options) {
378 arrayFormat = options.indices ? 'indices' : 'repeat';
380 arrayFormat = 'indices';
383 var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
386 objKeys = Object.keys(obj);
393 for (var i = 0; i < objKeys.length; ++i) {
394 var key = objKeys[i];
396 if (skipNulls && obj[key] === null) {
400 keys = keys.concat(stringify(
406 encode ? encoder : null,
416 var joined = keys.join(delimiter);
417 var prefix = options.addQueryPrefix === true ? '?' : '';
419 return joined.length > 0 ? prefix + joined : '';
422 },{"./formats":1,"./utils":5}],5:[function(require,module,exports){
425 var has = Object.prototype.hasOwnProperty;
427 var hexTable = (function () {
429 for (var i = 0; i < 256; ++i) {
430 array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
436 var compactQueue = function compactQueue(queue) {
439 while (queue.length) {
440 var item = queue.pop();
441 obj = item.obj[item.prop];
443 if (Array.isArray(obj)) {
446 for (var j = 0; j < obj.length; ++j) {
447 if (typeof obj[j] !== 'undefined') {
448 compacted.push(obj[j]);
452 item.obj[item.prop] = compacted;
459 var arrayToObject = function arrayToObject(source, options) {
460 var obj = options && options.plainObjects ? Object.create(null) : {};
461 for (var i = 0; i < source.length; ++i) {
462 if (typeof source[i] !== 'undefined') {
470 var merge = function merge(target, source, options) {
475 if (typeof source !== 'object') {
476 if (Array.isArray(target)) {
478 } else if (typeof target === 'object') {
479 if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
480 target[source] = true;
483 return [target, source];
489 if (typeof target !== 'object') {
490 return [target].concat(source);
493 var mergeTarget = target;
494 if (Array.isArray(target) && !Array.isArray(source)) {
495 mergeTarget = arrayToObject(target, options);
498 if (Array.isArray(target) && Array.isArray(source)) {
499 source.forEach(function (item, i) {
500 if (has.call(target, i)) {
501 if (target[i] && typeof target[i] === 'object') {
502 target[i] = merge(target[i], item, options);
513 return Object.keys(source).reduce(function (acc, key) {
514 var value = source[key];
516 if (has.call(acc, key)) {
517 acc[key] = merge(acc[key], value, options);
525 var assign = function assignSingleSource(target, source) {
526 return Object.keys(source).reduce(function (acc, key) {
527 acc[key] = source[key];
532 var decode = function (str) {
534 return decodeURIComponent(str.replace(/\+/g, ' '));
540 var encode = function encode(str) {
541 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
542 // It has been adapted here for stricter adherence to RFC 3986
543 if (str.length === 0) {
547 var string = typeof str === 'string' ? str : String(str);
550 for (var i = 0; i < string.length; ++i) {
551 var c = string.charCodeAt(i);
558 || (c >= 0x30 && c <= 0x39) // 0-9
559 || (c >= 0x41 && c <= 0x5A) // a-z
560 || (c >= 0x61 && c <= 0x7A) // A-Z
562 out += string.charAt(i);
567 out = out + hexTable[c];
572 out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
576 if (c < 0xD800 || c >= 0xE000) {
577 out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
582 c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
583 out += hexTable[0xF0 | (c >> 18)]
584 + hexTable[0x80 | ((c >> 12) & 0x3F)]
585 + hexTable[0x80 | ((c >> 6) & 0x3F)]
586 + hexTable[0x80 | (c & 0x3F)];
592 var compact = function compact(value) {
593 var queue = [{ obj: { o: value }, prop: 'o' }];
596 for (var i = 0; i < queue.length; ++i) {
598 var obj = item.obj[item.prop];
600 var keys = Object.keys(obj);
601 for (var j = 0; j < keys.length; ++j) {
604 if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
605 queue.push({ obj: obj, prop: key });
611 return compactQueue(queue);
614 var isRegExp = function isRegExp(obj) {
615 return Object.prototype.toString.call(obj) === '[object RegExp]';
618 var isBuffer = function isBuffer(obj) {
619 if (obj === null || typeof obj === 'undefined') {
623 return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
627 arrayToObject: arrayToObject,