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 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 parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
57 for (var i = 0; i < parts.length; ++i) {
59 var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
63 key = options.decoder(part);
64 val = options.strictNullHandling ? null : '';
66 key = options.decoder(part.slice(0, pos));
67 val = options.decoder(part.slice(pos + 1));
69 if (has.call(obj, key)) {
70 obj[key] = [].concat(obj[key]).concat(val);
79 var parseObject = function parseObjectRecursive(chain, val, options) {
84 var root = chain.shift();
89 obj = obj.concat(parseObject(chain, val, options));
91 obj = options.plainObjects ? Object.create(null) : {};
92 var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
93 var index = parseInt(cleanRoot, 10);
97 String(index) === cleanRoot &&
99 (options.parseArrays && index <= options.arrayLimit)
102 obj[index] = parseObject(chain, val, options);
104 obj[cleanRoot] = parseObject(chain, val, options);
111 var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
116 // Transform dot notation to bracket notation
117 var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
121 var brackets = /(\[[^[\]]*])/;
122 var child = /(\[[^[\]]*])/g;
126 var segment = brackets.exec(key);
127 var parent = segment ? key.slice(0, segment.index) : 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 && has.call(Object.prototype, parent)) {
136 if (!options.allowPrototypes) {
144 // Loop through children appending to the array until we hit depth
147 while ((segment = child.exec(key)) !== null && i < options.depth) {
149 if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
150 if (!options.allowPrototypes) {
154 keys.push(segment[1]);
157 // If there's a remainder, just add whatever is left
160 keys.push('[' + key.slice(segment.index) + ']');
163 return parseObject(keys, val, options);
166 module.exports = function (str, opts) {
167 var options = opts || {};
169 if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') {
170 throw new TypeError('Decoder has to be a function.');
173 options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter;
174 options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth;
175 options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults.arrayLimit;
176 options.parseArrays = options.parseArrays !== false;
177 options.decoder = typeof options.decoder === 'function' ? options.decoder : defaults.decoder;
178 options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : defaults.allowDots;
179 options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : defaults.plainObjects;
180 options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : defaults.allowPrototypes;
181 options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : defaults.parameterLimit;
182 options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
184 if (str === '' || str === null || typeof str === 'undefined') {
185 return options.plainObjects ? Object.create(null) : {};
188 var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
189 var obj = options.plainObjects ? Object.create(null) : {};
191 // Iterate over the keys and setup the new object
193 var keys = Object.keys(tempObj);
194 for (var i = 0; i < keys.length; ++i) {
196 var newObj = parseKeys(key, tempObj[key], options);
197 obj = utils.merge(obj, newObj, options);
200 return utils.compact(obj);
203 },{"./utils":5}],4:[function(require,module,exports){
206 var utils = require('./utils');
207 var formats = require('./formats');
209 var arrayPrefixGenerators = {
210 brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
211 return prefix + '[]';
213 indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
214 return prefix + '[' + key + ']';
216 repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
221 var toISO = Date.prototype.toISOString;
226 encoder: utils.encode,
227 serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
228 return toISO.call(date);
231 strictNullHandling: false
234 var stringify = function stringify( // eslint-disable-line func-name-matching
248 if (typeof filter === 'function') {
249 obj = filter(prefix, obj);
250 } else if (obj instanceof Date) {
251 obj = serializeDate(obj);
252 } else if (obj === null) {
253 if (strictNullHandling) {
254 return encoder ? encoder(prefix) : prefix;
260 if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
262 return [formatter(encoder(prefix)) + '=' + formatter(encoder(obj))];
264 return [formatter(prefix) + '=' + formatter(String(obj))];
269 if (typeof obj === 'undefined') {
274 if (Array.isArray(filter)) {
277 var keys = Object.keys(obj);
278 objKeys = sort ? keys.sort(sort) : keys;
281 for (var i = 0; i < objKeys.length; ++i) {
282 var key = objKeys[i];
284 if (skipNulls && obj[key] === null) {
288 if (Array.isArray(obj)) {
289 values = values.concat(stringify(
291 generateArrayPrefix(prefix, key),
303 values = values.concat(stringify(
305 prefix + (allowDots ? '.' + key : '[' + key + ']'),
322 module.exports = function (object, opts) {
324 var options = opts || {};
326 if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
327 throw new TypeError('Encoder has to be a function.');
330 var delimiter = typeof options.delimiter === 'undefined' ? defaults.delimiter : options.delimiter;
331 var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
332 var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
333 var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
334 var encoder = encode ? (typeof options.encoder === 'function' ? options.encoder : defaults.encoder) : null;
335 var sort = typeof options.sort === 'function' ? options.sort : null;
336 var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots;
337 var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
338 if (typeof options.format === 'undefined') {
339 options.format = formats.default;
340 } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
341 throw new TypeError('Unknown format option provided.');
343 var formatter = formats.formatters[options.format];
347 if (typeof options.filter === 'function') {
348 filter = options.filter;
349 obj = filter('', obj);
350 } else if (Array.isArray(options.filter)) {
351 filter = options.filter;
357 if (typeof obj !== 'object' || obj === null) {
362 if (options.arrayFormat in arrayPrefixGenerators) {
363 arrayFormat = options.arrayFormat;
364 } else if ('indices' in options) {
365 arrayFormat = options.indices ? 'indices' : 'repeat';
367 arrayFormat = 'indices';
370 var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
373 objKeys = Object.keys(obj);
380 for (var i = 0; i < objKeys.length; ++i) {
381 var key = objKeys[i];
383 if (skipNulls && obj[key] === null) {
387 keys = keys.concat(stringify(
402 return keys.join(delimiter);
405 },{"./formats":1,"./utils":5}],5:[function(require,module,exports){
408 var has = Object.prototype.hasOwnProperty;
410 var hexTable = (function () {
412 for (var i = 0; i < 256; ++i) {
413 array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
419 exports.arrayToObject = function (source, options) {
420 var obj = options && options.plainObjects ? Object.create(null) : {};
421 for (var i = 0; i < source.length; ++i) {
422 if (typeof source[i] !== 'undefined') {
430 exports.merge = function (target, source, options) {
435 if (typeof source !== 'object') {
436 if (Array.isArray(target)) {
438 } else if (typeof target === 'object') {
439 if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
440 target[source] = true;
443 return [target, source];
449 if (typeof target !== 'object') {
450 return [target].concat(source);
453 var mergeTarget = target;
454 if (Array.isArray(target) && !Array.isArray(source)) {
455 mergeTarget = exports.arrayToObject(target, options);
458 if (Array.isArray(target) && Array.isArray(source)) {
459 source.forEach(function (item, i) {
460 if (has.call(target, i)) {
461 if (target[i] && typeof target[i] === 'object') {
462 target[i] = exports.merge(target[i], item, options);
473 return Object.keys(source).reduce(function (acc, key) {
474 var value = source[key];
476 if (Object.prototype.hasOwnProperty.call(acc, key)) {
477 acc[key] = exports.merge(acc[key], value, options);
485 exports.decode = function (str) {
487 return decodeURIComponent(str.replace(/\+/g, ' '));
493 exports.encode = function (str) {
494 // This code was originally written by Brian White (mscdex) for the io.js core querystring library.
495 // It has been adapted here for stricter adherence to RFC 3986
496 if (str.length === 0) {
500 var string = typeof str === 'string' ? str : String(str);
503 for (var i = 0; i < string.length; ++i) {
504 var c = string.charCodeAt(i);
511 (c >= 0x30 && c <= 0x39) || // 0-9
512 (c >= 0x41 && c <= 0x5A) || // a-z
513 (c >= 0x61 && c <= 0x7A) // A-Z
515 out += string.charAt(i);
520 out = out + hexTable[c];
525 out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
529 if (c < 0xD800 || c >= 0xE000) {
530 out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
535 c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
536 out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
542 exports.compact = function (obj, references) {
543 if (typeof obj !== 'object' || obj === null) {
547 var refs = references || [];
548 var lookup = refs.indexOf(obj);
555 if (Array.isArray(obj)) {
558 for (var i = 0; i < obj.length; ++i) {
559 if (obj[i] && typeof obj[i] === 'object') {
560 compacted.push(exports.compact(obj[i], refs));
561 } else if (typeof obj[i] !== 'undefined') {
562 compacted.push(obj[i]);
569 var keys = Object.keys(obj);
570 keys.forEach(function (key) {
571 obj[key] = exports.compact(obj[key], refs);
577 exports.isRegExp = function (obj) {
578 return Object.prototype.toString.call(obj) === '[object RegExp]';
581 exports.isBuffer = function (obj) {
582 if (obj === null || typeof obj === 'undefined') {
586 return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));