2022-01-08 17:05:05 +00:00
|
|
|
(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){
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var replace = String.prototype.replace;
|
|
|
|
var percentTwenties = /%20/g;
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var Format = {
|
|
|
|
RFC1738: 'RFC1738',
|
|
|
|
RFC3986: 'RFC3986'
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
module.exports = {
|
2022-01-08 17:17:05 +00:00
|
|
|
'default': Format.RFC3986,
|
2022-01-08 17:05:05 +00:00
|
|
|
formatters: {
|
|
|
|
RFC1738: function (value) {
|
|
|
|
return replace.call(value, percentTwenties, '+');
|
|
|
|
},
|
|
|
|
RFC3986: function (value) {
|
2022-01-08 17:17:05 +00:00
|
|
|
return String(value);
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
|
|
|
},
|
2022-01-08 17:17:05 +00:00
|
|
|
RFC1738: Format.RFC1738,
|
|
|
|
RFC3986: Format.RFC3986
|
2022-01-08 17:05:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
},{}],2:[function(require,module,exports){
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var stringify = require('./stringify');
|
|
|
|
var parse = require('./parse');
|
|
|
|
var formats = require('./formats');
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
formats: formats,
|
|
|
|
parse: parse,
|
|
|
|
stringify: stringify
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"./formats":1,"./parse":3,"./stringify":4}],3:[function(require,module,exports){
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var utils = require('./utils');
|
|
|
|
|
|
|
|
var has = Object.prototype.hasOwnProperty;
|
2022-01-08 17:17:05 +00:00
|
|
|
var isArray = Array.isArray;
|
2022-01-08 17:05:05 +00:00
|
|
|
|
|
|
|
var defaults = {
|
|
|
|
allowDots: false,
|
|
|
|
allowPrototypes: false,
|
|
|
|
arrayLimit: 20,
|
2022-01-08 17:17:05 +00:00
|
|
|
charset: 'utf-8',
|
|
|
|
charsetSentinel: false,
|
|
|
|
comma: false,
|
2022-01-08 17:05:05 +00:00
|
|
|
decoder: utils.decode,
|
|
|
|
delimiter: '&',
|
|
|
|
depth: 5,
|
2022-01-08 17:17:05 +00:00
|
|
|
ignoreQueryPrefix: false,
|
|
|
|
interpretNumericEntities: false,
|
2022-01-08 17:05:05 +00:00
|
|
|
parameterLimit: 1000,
|
2022-01-08 17:17:05 +00:00
|
|
|
parseArrays: true,
|
2022-01-08 17:05:05 +00:00
|
|
|
plainObjects: false,
|
|
|
|
strictNullHandling: false
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var interpretNumericEntities = function (str) {
|
|
|
|
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
|
|
|
return String.fromCharCode(parseInt(numberStr, 10));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
var parseArrayValue = function (val, options) {
|
|
|
|
if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
|
|
|
|
return val.split(',');
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This is what browsers will submit when the ✓ character occurs in an
|
|
|
|
// application/x-www-form-urlencoded body and the encoding of the page containing
|
|
|
|
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
|
|
|
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
|
|
|
// the ✓ character, such as us-ascii.
|
|
|
|
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
|
|
|
|
|
|
|
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
|
|
|
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
var parseValues = function parseQueryStringValues(str, options) {
|
|
|
|
var obj = {};
|
|
|
|
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
|
|
|
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
|
|
|
var parts = cleanStr.split(options.delimiter, limit);
|
2022-01-08 17:17:05 +00:00
|
|
|
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
|
|
|
var i;
|
|
|
|
|
|
|
|
var charset = options.charset;
|
|
|
|
if (options.charsetSentinel) {
|
|
|
|
for (i = 0; i < parts.length; ++i) {
|
|
|
|
if (parts[i].indexOf('utf8=') === 0) {
|
|
|
|
if (parts[i] === charsetSentinel) {
|
|
|
|
charset = 'utf-8';
|
|
|
|
} else if (parts[i] === isoSentinel) {
|
|
|
|
charset = 'iso-8859-1';
|
|
|
|
}
|
|
|
|
skipIndex = i;
|
|
|
|
i = parts.length; // The eslint settings do not allow break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-08 17:05:05 +00:00
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
for (i = 0; i < parts.length; ++i) {
|
|
|
|
if (i === skipIndex) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-01-08 17:05:05 +00:00
|
|
|
var part = parts[i];
|
|
|
|
|
|
|
|
var bracketEqualsPos = part.indexOf(']=');
|
|
|
|
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
|
|
|
|
|
|
|
|
var key, val;
|
|
|
|
if (pos === -1) {
|
2022-01-08 17:17:05 +00:00
|
|
|
key = options.decoder(part, defaults.decoder, charset, 'key');
|
2022-01-08 17:05:05 +00:00
|
|
|
val = options.strictNullHandling ? null : '';
|
|
|
|
} else {
|
2022-01-08 17:17:05 +00:00
|
|
|
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
|
|
|
|
val = utils.maybeMap(
|
|
|
|
parseArrayValue(part.slice(pos + 1), options),
|
|
|
|
function (encodedVal) {
|
|
|
|
return options.decoder(encodedVal, defaults.decoder, charset, 'value');
|
|
|
|
}
|
|
|
|
);
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
2022-01-08 17:17:05 +00:00
|
|
|
|
|
|
|
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
|
|
|
val = interpretNumericEntities(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (part.indexOf('[]=') > -1) {
|
|
|
|
val = isArray(val) ? [val] : val;
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
if (has.call(obj, key)) {
|
2022-01-08 17:17:05 +00:00
|
|
|
obj[key] = utils.combine(obj[key], val);
|
2022-01-08 17:05:05 +00:00
|
|
|
} else {
|
|
|
|
obj[key] = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var parseObject = function (chain, val, options, valuesParsed) {
|
|
|
|
var leaf = valuesParsed ? val : parseArrayValue(val, options);
|
2022-01-08 17:05:05 +00:00
|
|
|
|
|
|
|
for (var i = chain.length - 1; i >= 0; --i) {
|
|
|
|
var obj;
|
|
|
|
var root = chain[i];
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (root === '[]' && options.parseArrays) {
|
|
|
|
obj = [].concat(leaf);
|
2022-01-08 17:05:05 +00:00
|
|
|
} else {
|
|
|
|
obj = options.plainObjects ? Object.create(null) : {};
|
|
|
|
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
|
|
var index = parseInt(cleanRoot, 10);
|
2022-01-08 17:17:05 +00:00
|
|
|
if (!options.parseArrays && cleanRoot === '') {
|
|
|
|
obj = { 0: leaf };
|
|
|
|
} else if (
|
2022-01-08 17:05:05 +00:00
|
|
|
!isNaN(index)
|
|
|
|
&& root !== cleanRoot
|
|
|
|
&& String(index) === cleanRoot
|
|
|
|
&& index >= 0
|
|
|
|
&& (options.parseArrays && index <= options.arrayLimit)
|
|
|
|
) {
|
|
|
|
obj = [];
|
|
|
|
obj[index] = leaf;
|
|
|
|
} else {
|
|
|
|
obj[cleanRoot] = leaf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
leaf = obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
return leaf;
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
|
2022-01-08 17:05:05 +00:00
|
|
|
if (!givenKey) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transform dot notation to bracket notation
|
|
|
|
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
|
|
|
|
|
|
|
// The regex chunks
|
|
|
|
|
|
|
|
var brackets = /(\[[^[\]]*])/;
|
|
|
|
var child = /(\[[^[\]]*])/g;
|
|
|
|
|
|
|
|
// Get the parent
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var segment = options.depth > 0 && brackets.exec(key);
|
2022-01-08 17:05:05 +00:00
|
|
|
var parent = segment ? key.slice(0, segment.index) : key;
|
|
|
|
|
|
|
|
// Stash the parent if it exists
|
|
|
|
|
|
|
|
var keys = [];
|
|
|
|
if (parent) {
|
2022-01-08 17:17:05 +00:00
|
|
|
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
2022-01-08 17:05:05 +00:00
|
|
|
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
|
|
if (!options.allowPrototypes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
keys.push(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop through children appending to the array until we hit depth
|
|
|
|
|
|
|
|
var i = 0;
|
2022-01-08 17:17:05 +00:00
|
|
|
while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
|
2022-01-08 17:05:05 +00:00
|
|
|
i += 1;
|
|
|
|
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
|
|
|
if (!options.allowPrototypes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keys.push(segment[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there's a remainder, just add whatever is left
|
|
|
|
|
|
|
|
if (segment) {
|
|
|
|
keys.push('[' + key.slice(segment.index) + ']');
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
return parseObject(keys, val, options, valuesParsed);
|
2022-01-08 17:05:05 +00:00
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var normalizeParseOptions = function normalizeParseOptions(opts) {
|
|
|
|
if (!opts) {
|
|
|
|
return defaults;
|
|
|
|
}
|
2022-01-08 17:05:05 +00:00
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
|
2022-01-08 17:05:05 +00:00
|
|
|
throw new TypeError('Decoder has to be a function.');
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
|
|
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
|
|
}
|
|
|
|
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
|
|
|
|
|
|
|
return {
|
|
|
|
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
|
|
|
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
|
|
|
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
|
|
|
charset: charset,
|
|
|
|
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
|
|
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
|
|
|
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
|
|
|
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
|
|
|
// eslint-disable-next-line no-implicit-coercion, no-extra-parens
|
|
|
|
depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
|
|
|
|
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
|
|
|
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
|
|
|
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
|
|
|
parseArrays: opts.parseArrays !== false,
|
|
|
|
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
|
|
|
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = function (str, opts) {
|
|
|
|
var options = normalizeParseOptions(opts);
|
2022-01-08 17:05:05 +00:00
|
|
|
|
|
|
|
if (str === '' || str === null || typeof str === 'undefined') {
|
|
|
|
return options.plainObjects ? Object.create(null) : {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
|
|
|
|
var obj = options.plainObjects ? Object.create(null) : {};
|
|
|
|
|
|
|
|
// Iterate over the keys and setup the new object
|
|
|
|
|
|
|
|
var keys = Object.keys(tempObj);
|
|
|
|
for (var i = 0; i < keys.length; ++i) {
|
|
|
|
var key = keys[i];
|
2022-01-08 17:17:05 +00:00
|
|
|
var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
|
2022-01-08 17:05:05 +00:00
|
|
|
obj = utils.merge(obj, newObj, options);
|
|
|
|
}
|
|
|
|
|
|
|
|
return utils.compact(obj);
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"./utils":5}],4:[function(require,module,exports){
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var utils = require('./utils');
|
|
|
|
var formats = require('./formats');
|
2022-01-08 17:17:05 +00:00
|
|
|
var has = Object.prototype.hasOwnProperty;
|
2022-01-08 17:05:05 +00:00
|
|
|
|
|
|
|
var arrayPrefixGenerators = {
|
2022-01-08 17:17:05 +00:00
|
|
|
brackets: function brackets(prefix) {
|
2022-01-08 17:05:05 +00:00
|
|
|
return prefix + '[]';
|
|
|
|
},
|
2022-01-08 17:17:05 +00:00
|
|
|
comma: 'comma',
|
|
|
|
indices: function indices(prefix, key) {
|
2022-01-08 17:05:05 +00:00
|
|
|
return prefix + '[' + key + ']';
|
|
|
|
},
|
2022-01-08 17:17:05 +00:00
|
|
|
repeat: function repeat(prefix) {
|
2022-01-08 17:05:05 +00:00
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var isArray = Array.isArray;
|
|
|
|
var push = Array.prototype.push;
|
|
|
|
var pushToArray = function (arr, valueOrArray) {
|
|
|
|
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
var toISO = Date.prototype.toISOString;
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var defaultFormat = formats['default'];
|
2022-01-08 17:05:05 +00:00
|
|
|
var defaults = {
|
2022-01-08 17:17:05 +00:00
|
|
|
addQueryPrefix: false,
|
|
|
|
allowDots: false,
|
|
|
|
charset: 'utf-8',
|
|
|
|
charsetSentinel: false,
|
2022-01-08 17:05:05 +00:00
|
|
|
delimiter: '&',
|
|
|
|
encode: true,
|
|
|
|
encoder: utils.encode,
|
|
|
|
encodeValuesOnly: false,
|
2022-01-08 17:17:05 +00:00
|
|
|
format: defaultFormat,
|
|
|
|
formatter: formats.formatters[defaultFormat],
|
|
|
|
// deprecated
|
|
|
|
indices: false,
|
|
|
|
serializeDate: function serializeDate(date) {
|
2022-01-08 17:05:05 +00:00
|
|
|
return toISO.call(date);
|
|
|
|
},
|
|
|
|
skipNulls: false,
|
|
|
|
strictNullHandling: false
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
|
|
|
|
return typeof v === 'string'
|
|
|
|
|| typeof v === 'number'
|
|
|
|
|| typeof v === 'boolean'
|
|
|
|
|| typeof v === 'symbol'
|
|
|
|
|| typeof v === 'bigint';
|
|
|
|
};
|
|
|
|
|
|
|
|
var stringify = function stringify(
|
2022-01-08 17:05:05 +00:00
|
|
|
object,
|
|
|
|
prefix,
|
|
|
|
generateArrayPrefix,
|
|
|
|
strictNullHandling,
|
|
|
|
skipNulls,
|
|
|
|
encoder,
|
|
|
|
filter,
|
|
|
|
sort,
|
|
|
|
allowDots,
|
|
|
|
serializeDate,
|
2022-01-08 17:17:05 +00:00
|
|
|
format,
|
2022-01-08 17:05:05 +00:00
|
|
|
formatter,
|
2022-01-08 17:17:05 +00:00
|
|
|
encodeValuesOnly,
|
|
|
|
charset
|
2022-01-08 17:05:05 +00:00
|
|
|
) {
|
|
|
|
var obj = object;
|
|
|
|
if (typeof filter === 'function') {
|
|
|
|
obj = filter(prefix, obj);
|
|
|
|
} else if (obj instanceof Date) {
|
|
|
|
obj = serializeDate(obj);
|
2022-01-08 17:17:05 +00:00
|
|
|
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
|
|
obj = utils.maybeMap(obj, function (value) {
|
|
|
|
if (value instanceof Date) {
|
|
|
|
return serializeDate(value);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (obj === null) {
|
2022-01-08 17:05:05 +00:00
|
|
|
if (strictNullHandling) {
|
2022-01-08 17:17:05 +00:00
|
|
|
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
obj = '';
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
if (encoder) {
|
2022-01-08 17:17:05 +00:00
|
|
|
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
|
|
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
|
|
|
return [formatter(prefix) + '=' + formatter(String(obj))];
|
|
|
|
}
|
|
|
|
|
|
|
|
var values = [];
|
|
|
|
|
|
|
|
if (typeof obj === 'undefined') {
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
var objKeys;
|
2022-01-08 17:17:05 +00:00
|
|
|
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
|
|
// we need to join elements in
|
|
|
|
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : undefined }];
|
|
|
|
} else if (isArray(filter)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
objKeys = filter;
|
|
|
|
} else {
|
|
|
|
var keys = Object.keys(obj);
|
|
|
|
objKeys = sort ? keys.sort(sort) : keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < objKeys.length; ++i) {
|
|
|
|
var key = objKeys[i];
|
2022-01-08 17:17:05 +00:00
|
|
|
var value = typeof key === 'object' && key.value !== undefined ? key.value : obj[key];
|
2022-01-08 17:05:05 +00:00
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (skipNulls && value === null) {
|
2022-01-08 17:05:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var keyPrefix = isArray(obj)
|
|
|
|
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix
|
|
|
|
: prefix + (allowDots ? '.' + key : '[' + key + ']');
|
|
|
|
|
|
|
|
pushToArray(values, stringify(
|
|
|
|
value,
|
|
|
|
keyPrefix,
|
|
|
|
generateArrayPrefix,
|
|
|
|
strictNullHandling,
|
|
|
|
skipNulls,
|
|
|
|
encoder,
|
|
|
|
filter,
|
|
|
|
sort,
|
|
|
|
allowDots,
|
|
|
|
serializeDate,
|
|
|
|
format,
|
|
|
|
formatter,
|
|
|
|
encodeValuesOnly,
|
|
|
|
charset
|
|
|
|
));
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return values;
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
|
|
|
if (!opts) {
|
|
|
|
return defaults;
|
|
|
|
}
|
2022-01-08 17:05:05 +00:00
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
|
2022-01-08 17:05:05 +00:00
|
|
|
throw new TypeError('Encoder has to be a function.');
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var charset = opts.charset || defaults.charset;
|
|
|
|
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
|
|
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
|
|
}
|
|
|
|
|
|
|
|
var format = formats['default'];
|
|
|
|
if (typeof opts.format !== 'undefined') {
|
|
|
|
if (!has.call(formats.formatters, opts.format)) {
|
|
|
|
throw new TypeError('Unknown format option provided.');
|
|
|
|
}
|
|
|
|
format = opts.format;
|
|
|
|
}
|
|
|
|
var formatter = formats.formatters[format];
|
|
|
|
|
|
|
|
var filter = defaults.filter;
|
|
|
|
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
|
|
filter = opts.filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
|
|
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
|
|
|
charset: charset,
|
|
|
|
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
|
|
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
|
|
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
|
|
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
|
|
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
|
|
filter: filter,
|
|
|
|
format: format,
|
|
|
|
formatter: formatter,
|
|
|
|
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
|
|
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
|
|
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
|
|
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = function (object, opts) {
|
|
|
|
var obj = object;
|
|
|
|
var options = normalizeStringifyOptions(opts);
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
var objKeys;
|
|
|
|
var filter;
|
|
|
|
|
|
|
|
if (typeof options.filter === 'function') {
|
|
|
|
filter = options.filter;
|
|
|
|
obj = filter('', obj);
|
2022-01-08 17:17:05 +00:00
|
|
|
} else if (isArray(options.filter)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
filter = options.filter;
|
|
|
|
objKeys = filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
var keys = [];
|
|
|
|
|
|
|
|
if (typeof obj !== 'object' || obj === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
var arrayFormat;
|
2022-01-08 17:17:05 +00:00
|
|
|
if (opts && opts.arrayFormat in arrayPrefixGenerators) {
|
|
|
|
arrayFormat = opts.arrayFormat;
|
|
|
|
} else if (opts && 'indices' in opts) {
|
|
|
|
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
2022-01-08 17:05:05 +00:00
|
|
|
} else {
|
|
|
|
arrayFormat = 'indices';
|
|
|
|
}
|
|
|
|
|
|
|
|
var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
|
|
|
|
|
|
|
|
if (!objKeys) {
|
|
|
|
objKeys = Object.keys(obj);
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (options.sort) {
|
|
|
|
objKeys.sort(options.sort);
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < objKeys.length; ++i) {
|
|
|
|
var key = objKeys[i];
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (options.skipNulls && obj[key] === null) {
|
2022-01-08 17:05:05 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-01-08 17:17:05 +00:00
|
|
|
pushToArray(keys, stringify(
|
2022-01-08 17:05:05 +00:00
|
|
|
obj[key],
|
|
|
|
key,
|
|
|
|
generateArrayPrefix,
|
2022-01-08 17:17:05 +00:00
|
|
|
options.strictNullHandling,
|
|
|
|
options.skipNulls,
|
|
|
|
options.encode ? options.encoder : null,
|
|
|
|
options.filter,
|
|
|
|
options.sort,
|
|
|
|
options.allowDots,
|
|
|
|
options.serializeDate,
|
|
|
|
options.format,
|
|
|
|
options.formatter,
|
|
|
|
options.encodeValuesOnly,
|
|
|
|
options.charset
|
2022-01-08 17:05:05 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var joined = keys.join(options.delimiter);
|
2022-01-08 17:05:05 +00:00
|
|
|
var prefix = options.addQueryPrefix === true ? '?' : '';
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (options.charsetSentinel) {
|
|
|
|
if (options.charset === 'iso-8859-1') {
|
|
|
|
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
|
|
prefix += 'utf8=%26%2310003%3B&';
|
|
|
|
} else {
|
|
|
|
// encodeURIComponent('✓')
|
|
|
|
prefix += 'utf8=%E2%9C%93&';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
return joined.length > 0 ? prefix + joined : '';
|
|
|
|
};
|
|
|
|
|
|
|
|
},{"./formats":1,"./utils":5}],5:[function(require,module,exports){
|
|
|
|
'use strict';
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var formats = require('./formats');
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
var has = Object.prototype.hasOwnProperty;
|
2022-01-08 17:17:05 +00:00
|
|
|
var isArray = Array.isArray;
|
2022-01-08 17:05:05 +00:00
|
|
|
|
|
|
|
var hexTable = (function () {
|
|
|
|
var array = [];
|
|
|
|
for (var i = 0; i < 256; ++i) {
|
|
|
|
array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}());
|
|
|
|
|
|
|
|
var compactQueue = function compactQueue(queue) {
|
2022-01-08 17:17:05 +00:00
|
|
|
while (queue.length > 1) {
|
2022-01-08 17:05:05 +00:00
|
|
|
var item = queue.pop();
|
2022-01-08 17:17:05 +00:00
|
|
|
var obj = item.obj[item.prop];
|
2022-01-08 17:05:05 +00:00
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (isArray(obj)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
var compacted = [];
|
|
|
|
|
|
|
|
for (var j = 0; j < obj.length; ++j) {
|
|
|
|
if (typeof obj[j] !== 'undefined') {
|
|
|
|
compacted.push(obj[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
item.obj[item.prop] = compacted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var arrayToObject = function arrayToObject(source, options) {
|
|
|
|
var obj = options && options.plainObjects ? Object.create(null) : {};
|
|
|
|
for (var i = 0; i < source.length; ++i) {
|
|
|
|
if (typeof source[i] !== 'undefined') {
|
|
|
|
obj[i] = source[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
};
|
|
|
|
|
|
|
|
var merge = function merge(target, source, options) {
|
2022-01-08 17:17:05 +00:00
|
|
|
/* eslint no-param-reassign: 0 */
|
2022-01-08 17:05:05 +00:00
|
|
|
if (!source) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof source !== 'object') {
|
2022-01-08 17:17:05 +00:00
|
|
|
if (isArray(target)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
target.push(source);
|
2022-01-08 17:17:05 +00:00
|
|
|
} else if (target && typeof target === 'object') {
|
|
|
|
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
target[source] = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return [target, source];
|
|
|
|
}
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (!target || typeof target !== 'object') {
|
2022-01-08 17:05:05 +00:00
|
|
|
return [target].concat(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
var mergeTarget = target;
|
2022-01-08 17:17:05 +00:00
|
|
|
if (isArray(target) && !isArray(source)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
mergeTarget = arrayToObject(target, options);
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
if (isArray(target) && isArray(source)) {
|
2022-01-08 17:05:05 +00:00
|
|
|
source.forEach(function (item, i) {
|
|
|
|
if (has.call(target, i)) {
|
2022-01-08 17:17:05 +00:00
|
|
|
var targetItem = target[i];
|
|
|
|
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
|
|
|
|
target[i] = merge(targetItem, item, options);
|
2022-01-08 17:05:05 +00:00
|
|
|
} else {
|
|
|
|
target.push(item);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
target[i] = item;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.keys(source).reduce(function (acc, key) {
|
|
|
|
var value = source[key];
|
|
|
|
|
|
|
|
if (has.call(acc, key)) {
|
|
|
|
acc[key] = merge(acc[key], value, options);
|
|
|
|
} else {
|
|
|
|
acc[key] = value;
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, mergeTarget);
|
|
|
|
};
|
|
|
|
|
|
|
|
var assign = function assignSingleSource(target, source) {
|
|
|
|
return Object.keys(source).reduce(function (acc, key) {
|
|
|
|
acc[key] = source[key];
|
|
|
|
return acc;
|
|
|
|
}, target);
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var decode = function (str, decoder, charset) {
|
|
|
|
var strWithoutPlus = str.replace(/\+/g, ' ');
|
|
|
|
if (charset === 'iso-8859-1') {
|
|
|
|
// unescape never throws, no try...catch needed:
|
|
|
|
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
|
|
|
}
|
|
|
|
// utf-8
|
2022-01-08 17:05:05 +00:00
|
|
|
try {
|
2022-01-08 17:17:05 +00:00
|
|
|
return decodeURIComponent(strWithoutPlus);
|
2022-01-08 17:05:05 +00:00
|
|
|
} catch (e) {
|
2022-01-08 17:17:05 +00:00
|
|
|
return strWithoutPlus;
|
2022-01-08 17:05:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var encode = function encode(str, defaultEncoder, charset, kind, format) {
|
2022-01-08 17:05:05 +00:00
|
|
|
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
|
|
|
|
// It has been adapted here for stricter adherence to RFC 3986
|
|
|
|
if (str.length === 0) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var string = str;
|
|
|
|
if (typeof str === 'symbol') {
|
|
|
|
string = Symbol.prototype.toString.call(str);
|
|
|
|
} else if (typeof str !== 'string') {
|
|
|
|
string = String(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (charset === 'iso-8859-1') {
|
|
|
|
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
|
|
|
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
|
|
|
});
|
|
|
|
}
|
2022-01-08 17:05:05 +00:00
|
|
|
|
|
|
|
var out = '';
|
|
|
|
for (var i = 0; i < string.length; ++i) {
|
|
|
|
var c = string.charCodeAt(i);
|
|
|
|
|
|
|
|
if (
|
|
|
|
c === 0x2D // -
|
|
|
|
|| c === 0x2E // .
|
|
|
|
|| c === 0x5F // _
|
|
|
|
|| c === 0x7E // ~
|
|
|
|
|| (c >= 0x30 && c <= 0x39) // 0-9
|
|
|
|
|| (c >= 0x41 && c <= 0x5A) // a-z
|
|
|
|
|| (c >= 0x61 && c <= 0x7A) // A-Z
|
2022-01-08 17:17:05 +00:00
|
|
|
|| (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
2022-01-08 17:05:05 +00:00
|
|
|
) {
|
|
|
|
out += string.charAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c < 0x80) {
|
|
|
|
out = out + hexTable[c];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c < 0x800) {
|
|
|
|
out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c < 0xD800 || c >= 0xE000) {
|
|
|
|
out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
i += 1;
|
|
|
|
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
|
|
|
out += hexTable[0xF0 | (c >> 18)]
|
|
|
|
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
|
|
|
|
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
|
|
|
+ hexTable[0x80 | (c & 0x3F)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
|
|
|
|
var compact = function compact(value) {
|
|
|
|
var queue = [{ obj: { o: value }, prop: 'o' }];
|
|
|
|
var refs = [];
|
|
|
|
|
|
|
|
for (var i = 0; i < queue.length; ++i) {
|
|
|
|
var item = queue[i];
|
|
|
|
var obj = item.obj[item.prop];
|
|
|
|
|
|
|
|
var keys = Object.keys(obj);
|
|
|
|
for (var j = 0; j < keys.length; ++j) {
|
|
|
|
var key = keys[j];
|
|
|
|
var val = obj[key];
|
|
|
|
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
|
|
|
|
queue.push({ obj: obj, prop: key });
|
|
|
|
refs.push(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
compactQueue(queue);
|
|
|
|
|
|
|
|
return value;
|
2022-01-08 17:05:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var isRegExp = function isRegExp(obj) {
|
|
|
|
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
|
|
};
|
|
|
|
|
|
|
|
var isBuffer = function isBuffer(obj) {
|
2022-01-08 17:17:05 +00:00
|
|
|
if (!obj || typeof obj !== 'object') {
|
2022-01-08 17:05:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
var combine = function combine(a, b) {
|
|
|
|
return [].concat(a, b);
|
|
|
|
};
|
|
|
|
|
|
|
|
var maybeMap = function maybeMap(val, fn) {
|
|
|
|
if (isArray(val)) {
|
|
|
|
var mapped = [];
|
|
|
|
for (var i = 0; i < val.length; i += 1) {
|
|
|
|
mapped.push(fn(val[i]));
|
|
|
|
}
|
|
|
|
return mapped;
|
|
|
|
}
|
|
|
|
return fn(val);
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:05:05 +00:00
|
|
|
module.exports = {
|
|
|
|
arrayToObject: arrayToObject,
|
|
|
|
assign: assign,
|
2022-01-08 17:17:05 +00:00
|
|
|
combine: combine,
|
2022-01-08 17:05:05 +00:00
|
|
|
compact: compact,
|
|
|
|
decode: decode,
|
|
|
|
encode: encode,
|
|
|
|
isBuffer: isBuffer,
|
|
|
|
isRegExp: isRegExp,
|
2022-01-08 17:17:05 +00:00
|
|
|
maybeMap: maybeMap,
|
2022-01-08 17:05:05 +00:00
|
|
|
merge: merge
|
|
|
|
};
|
|
|
|
|
2022-01-08 17:17:05 +00:00
|
|
|
},{"./formats":1}]},{},[2])(2)
|
2022-01-08 17:05:05 +00:00
|
|
|
});
|