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,
46 charsetSentinel: false,
48 decoder: utils.decode,
51 ignoreQueryPrefix: false,
52 interpretNumericEntities: false,
56 strictNullHandling: false
59 var interpretNumericEntities = function (str) {
60 return str.replace(/&#(\d+);/g, function ($0, numberStr) {
61 return String.fromCharCode(parseInt(numberStr, 10));
65 // This is what browsers will submit when the ✓ character occurs in an
66 // application/x-www-form-urlencoded body and the encoding of the page containing
67 // the form is iso-8859-1, or when the submitted form has an accept-charset
68 // attribute of iso-8859-1. Presumably also with other charsets that do not contain
69 // the ✓ character, such as us-ascii.
70 var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
72 // These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
73 var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
75 var parseValues = function parseQueryStringValues(str, options) {
77 var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
78 var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
79 var parts = cleanStr.split(options.delimiter, limit);
80 var skipIndex = -1; // Keep track of where the utf8 sentinel was found
83 var charset = options.charset;
84 if (options.charsetSentinel) {
85 for (i = 0; i < parts.length; ++i) {
86 if (parts[i].indexOf('utf8=') === 0) {
87 if (parts[i] === charsetSentinel) {
89 } else if (parts[i] === isoSentinel) {
90 charset = 'iso-8859-1';
93 i = parts.length; // The eslint settings do not allow break;
98 for (i = 0; i < parts.length; ++i) {
99 if (i === skipIndex) {
104 var bracketEqualsPos = part.indexOf(']=');
105 var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
109 key = options.decoder(part, defaults.decoder, charset);
110 val = options.strictNullHandling ? null : '';
112 key = options.decoder(part.slice(0, pos), defaults.decoder, charset);
113 val = options.decoder(part.slice(pos + 1), defaults.decoder, charset);
116 if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
117 val = interpretNumericEntities(val);
120 if (val && options.comma && val.indexOf(',') > -1) {
121 val = val.split(',');
124 if (has.call(obj, key)) {
125 obj[key] = utils.combine(obj[key], val);
134 var parseObject = function (chain, val, options) {
137 for (var i = chain.length - 1; i >= 0; --i) {
141 if (root === '[]' && options.parseArrays) {
142 obj = [].concat(leaf);
144 obj = options.plainObjects ? Object.create(null) : {};
145 var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
146 var index = parseInt(cleanRoot, 10);
147 if (!options.parseArrays && cleanRoot === '') {
151 && root !== cleanRoot
152 && String(index) === cleanRoot
154 && (options.parseArrays && index <= options.arrayLimit)
159 obj[cleanRoot] = leaf;
169 var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
174 // Transform dot notation to bracket notation
175 var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
179 var brackets = /(\[[^[\]]*])/;
180 var child = /(\[[^[\]]*])/g;
184 var segment = brackets.exec(key);
185 var parent = segment ? key.slice(0, segment.index) : key;
187 // Stash the parent if it exists
191 // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
192 if (!options.plainObjects && has.call(Object.prototype, parent)) {
193 if (!options.allowPrototypes) {
201 // Loop through children appending to the array until we hit depth
204 while ((segment = child.exec(key)) !== null && i < options.depth) {
206 if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
207 if (!options.allowPrototypes) {
211 keys.push(segment[1]);
214 // If there's a remainder, just add whatever is left
217 keys.push('[' + key.slice(segment.index) + ']');
220 return parseObject(keys, val, options);
223 var normalizeParseOptions = function normalizeParseOptions(opts) {
228 if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
229 throw new TypeError('Decoder has to be a function.');
232 if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
233 throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
235 var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
238 allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
239 allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
240 arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
242 charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
243 comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
244 decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
245 delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
246 depth: typeof opts.depth === 'number' ? opts.depth : defaults.depth,
247 ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
248 interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
249 parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
250 parseArrays: opts.parseArrays !== false,
251 plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
252 strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
256 module.exports = function (str, opts) {
257 var options = normalizeParseOptions(opts);
259 if (str === '' || str === null || typeof str === 'undefined') {
260 return options.plainObjects ? Object.create(null) : {};
263 var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
264 var obj = options.plainObjects ? Object.create(null) : {};
266 // Iterate over the keys and setup the new object
268 var keys = Object.keys(tempObj);
269 for (var i = 0; i < keys.length; ++i) {
271 var newObj = parseKeys(key, tempObj[key], options);
272 obj = utils.merge(obj, newObj, options);
275 return utils.compact(obj);
278 },{"./utils":5}],4:[function(require,module,exports){
281 var utils = require('./utils');
282 var formats = require('./formats');
283 var has = Object.prototype.hasOwnProperty;
285 var arrayPrefixGenerators = {
286 brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
287 return prefix + '[]';
290 indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
291 return prefix + '[' + key + ']';
293 repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
298 var isArray = Array.isArray;
299 var push = Array.prototype.push;
300 var pushToArray = function (arr, valueOrArray) {
301 push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
304 var toISO = Date.prototype.toISOString;
307 addQueryPrefix: false,
310 charsetSentinel: false,
313 encoder: utils.encode,
314 encodeValuesOnly: false,
315 formatter: formats.formatters[formats['default']],
318 serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
319 return toISO.call(date);
322 strictNullHandling: false
325 var stringify = function stringify( // eslint-disable-line func-name-matching
341 if (typeof filter === 'function') {
342 obj = filter(prefix, obj);
343 } else if (obj instanceof Date) {
344 obj = serializeDate(obj);
345 } else if (generateArrayPrefix === 'comma' && isArray(obj)) {
350 if (strictNullHandling) {
351 return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix;
357 if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
359 var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset);
360 return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))];
362 return [formatter(prefix) + '=' + formatter(String(obj))];
367 if (typeof obj === 'undefined') {
372 if (isArray(filter)) {
375 var keys = Object.keys(obj);
376 objKeys = sort ? keys.sort(sort) : keys;
379 for (var i = 0; i < objKeys.length; ++i) {
380 var key = objKeys[i];
382 if (skipNulls && obj[key] === null) {
387 pushToArray(values, stringify(
389 typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix,
403 pushToArray(values, stringify(
405 prefix + (allowDots ? '.' + key : '[' + key + ']'),
424 var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
429 if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
430 throw new TypeError('Encoder has to be a function.');
433 var charset = opts.charset || defaults.charset;
434 if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
435 throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
438 var format = formats['default'];
439 if (typeof opts.format !== 'undefined') {
440 if (!has.call(formats.formatters, opts.format)) {
441 throw new TypeError('Unknown format option provided.');
443 format = opts.format;
445 var formatter = formats.formatters[format];
447 var filter = defaults.filter;
448 if (typeof opts.filter === 'function' || isArray(opts.filter)) {
449 filter = opts.filter;
453 addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
454 allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
456 charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
457 delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
458 encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
459 encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
460 encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
462 formatter: formatter,
463 serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
464 skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
465 sort: typeof opts.sort === 'function' ? opts.sort : null,
466 strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
470 module.exports = function (object, opts) {
472 var options = normalizeStringifyOptions(opts);
477 if (typeof options.filter === 'function') {
478 filter = options.filter;
479 obj = filter('', obj);
480 } else if (isArray(options.filter)) {
481 filter = options.filter;
487 if (typeof obj !== 'object' || obj === null) {
492 if (opts && opts.arrayFormat in arrayPrefixGenerators) {
493 arrayFormat = opts.arrayFormat;
494 } else if (opts && 'indices' in opts) {
495 arrayFormat = opts.indices ? 'indices' : 'repeat';
497 arrayFormat = 'indices';
500 var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
503 objKeys = Object.keys(obj);
507 objKeys.sort(options.sort);
510 for (var i = 0; i < objKeys.length; ++i) {
511 var key = objKeys[i];
513 if (options.skipNulls && obj[key] === null) {
516 pushToArray(keys, stringify(
520 options.strictNullHandling,
522 options.encode ? options.encoder : null,
526 options.serializeDate,
528 options.encodeValuesOnly,
533 var joined = keys.join(options.delimiter);
534 var prefix = options.addQueryPrefix === true ? '?' : '';
536 if (options.charsetSentinel) {
537 if (options.charset === 'iso-8859-1') {
538 // encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
539 prefix += 'utf8=%26%2310003%3B&';
541 // encodeURIComponent('✓')
542 prefix += 'utf8=%E2%9C%93&';
546 return joined.length > 0 ? prefix + joined : '';
549 },{"./formats":1,"./utils":5}],5:[function(require,module,exports){
552 var has = Object.prototype.hasOwnProperty;
553 var isArray = Array.isArray;
555 var hexTable = (function () {
557 for (var i = 0; i < 256; ++i) {
558 array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
564 var compactQueue = function compactQueue(queue) {
565 while (queue.length > 1) {
566 var item = queue.pop();
567 var obj = item.obj[item.prop];
572 for (var j = 0; j < obj.length; ++j) {
573 if (typeof obj[j] !== 'undefined') {
574 compacted.push(obj[j]);
578 item.obj[item.prop] = compacted;
583 var arrayToObject = function arrayToObject(source, options) {
584 var obj = options && options.plainObjects ? Object.create(null) : {};
585 for (var i = 0; i < source.length; ++i) {
586 if (typeof source[i] !== 'undefined') {
594 var merge = function merge(target, source, options) {
599 if (typeof source !== 'object') {
600 if (isArray(target)) {
602 } else if (target && typeof target === 'object') {
603 if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
604 target[source] = true;
607 return [target, source];
613 if (!target || typeof target !== 'object') {
614 return [target].concat(source);
617 var mergeTarget = target;
618 if (isArray(target) && !isArray(source)) {
619 mergeTarget = arrayToObject(target, options);
622 if (isArray(target) && isArray(source)) {
623 source.forEach(function (item, i) {
624 if (has.call(target, i)) {
625 var targetItem = target[i];
626 if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
627 target[i] = merge(targetItem, item, options);
638 return Object.keys(source).reduce(function (acc, key) {
639 var value = source[key];
641 if (has.call(acc, key)) {
642 acc[key] = merge(acc[key], value, options);
650 var assign = function assignSingleSource(target, source) {
651 return Object.keys(source).reduce(function (acc, key) {
652 acc[key] = source[key];
657 var decode = function (str, decoder, charset) {
658 var strWithoutPlus = str.replace(/\+/g, ' ');
659 if (charset === 'iso-8859-1') {
660 // unescape never throws, no try...catch needed:
661 return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
665 return decodeURIComponent(strWithoutPlus);
667 return strWithoutPlus;
671 var encode = function encode(str, defaultEncoder, charset) {
672 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
673 // It has been adapted here for stricter adherence to RFC 3986
674 if (str.length === 0) {
678 var string = typeof str === 'string' ? str : String(str);
680 if (charset === 'iso-8859-1') {
681 return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
682 return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
687 for (var i = 0; i < string.length; ++i) {
688 var c = string.charCodeAt(i);
695 || (c >= 0x30 && c <= 0x39) // 0-9
696 || (c >= 0x41 && c <= 0x5A) // a-z
697 || (c >= 0x61 && c <= 0x7A) // A-Z
699 out += string.charAt(i);
704 out = out + hexTable[c];
709 out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
713 if (c < 0xD800 || c >= 0xE000) {
714 out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
719 c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
720 out += hexTable[0xF0 | (c >> 18)]
721 + hexTable[0x80 | ((c >> 12) & 0x3F)]
722 + hexTable[0x80 | ((c >> 6) & 0x3F)]
723 + hexTable[0x80 | (c & 0x3F)];
729 var compact = function compact(value) {
730 var queue = [{ obj: { o: value }, prop: 'o' }];
733 for (var i = 0; i < queue.length; ++i) {
735 var obj = item.obj[item.prop];
737 var keys = Object.keys(obj);
738 for (var j = 0; j < keys.length; ++j) {
741 if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
742 queue.push({ obj: obj, prop: key });
753 var isRegExp = function isRegExp(obj) {
754 return Object.prototype.toString.call(obj) === '[object RegExp]';
757 var isBuffer = function isBuffer(obj) {
758 if (!obj || typeof obj !== 'object') {
762 return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
765 var combine = function combine(a, b) {
766 return [].concat(a, b);
770 arrayToObject: arrayToObject,