qs 6.9.5 → 6.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -0
- package/dist/qs.js +832 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/qs.js
ADDED
|
@@ -0,0 +1,832 @@
|
|
|
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){
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var replace = String.prototype.replace;
|
|
5
|
+
var percentTwenties = /%20/g;
|
|
6
|
+
|
|
7
|
+
var Format = {
|
|
8
|
+
RFC1738: 'RFC1738',
|
|
9
|
+
RFC3986: 'RFC3986'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
module.exports = {
|
|
13
|
+
'default': Format.RFC3986,
|
|
14
|
+
formatters: {
|
|
15
|
+
RFC1738: function (value) {
|
|
16
|
+
return replace.call(value, percentTwenties, '+');
|
|
17
|
+
},
|
|
18
|
+
RFC3986: function (value) {
|
|
19
|
+
return String(value);
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
RFC1738: Format.RFC1738,
|
|
23
|
+
RFC3986: Format.RFC3986
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
},{}],2:[function(require,module,exports){
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
var stringify = require('./stringify');
|
|
30
|
+
var parse = require('./parse');
|
|
31
|
+
var formats = require('./formats');
|
|
32
|
+
|
|
33
|
+
module.exports = {
|
|
34
|
+
formats: formats,
|
|
35
|
+
parse: parse,
|
|
36
|
+
stringify: stringify
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
},{"./formats":1,"./parse":3,"./stringify":4}],3:[function(require,module,exports){
|
|
40
|
+
'use strict';
|
|
41
|
+
|
|
42
|
+
var utils = require('./utils');
|
|
43
|
+
|
|
44
|
+
var has = Object.prototype.hasOwnProperty;
|
|
45
|
+
var isArray = Array.isArray;
|
|
46
|
+
|
|
47
|
+
var defaults = {
|
|
48
|
+
allowDots: false,
|
|
49
|
+
allowPrototypes: false,
|
|
50
|
+
arrayLimit: 20,
|
|
51
|
+
charset: 'utf-8',
|
|
52
|
+
charsetSentinel: false,
|
|
53
|
+
comma: false,
|
|
54
|
+
decoder: utils.decode,
|
|
55
|
+
delimiter: '&',
|
|
56
|
+
depth: 5,
|
|
57
|
+
ignoreQueryPrefix: false,
|
|
58
|
+
interpretNumericEntities: false,
|
|
59
|
+
parameterLimit: 1000,
|
|
60
|
+
parseArrays: true,
|
|
61
|
+
plainObjects: false,
|
|
62
|
+
strictNullHandling: false
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
var interpretNumericEntities = function (str) {
|
|
66
|
+
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
|
67
|
+
return String.fromCharCode(parseInt(numberStr, 10));
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var parseArrayValue = function (val, options) {
|
|
72
|
+
if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) {
|
|
73
|
+
return val.split(',');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return val;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// This is what browsers will submit when the ✓ character occurs in an
|
|
80
|
+
// application/x-www-form-urlencoded body and the encoding of the page containing
|
|
81
|
+
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
|
82
|
+
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
|
83
|
+
// the ✓ character, such as us-ascii.
|
|
84
|
+
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
|
85
|
+
|
|
86
|
+
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
|
87
|
+
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
|
88
|
+
|
|
89
|
+
var parseValues = function parseQueryStringValues(str, options) {
|
|
90
|
+
var obj = {};
|
|
91
|
+
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
|
92
|
+
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
|
93
|
+
var parts = cleanStr.split(options.delimiter, limit);
|
|
94
|
+
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
|
95
|
+
var i;
|
|
96
|
+
|
|
97
|
+
var charset = options.charset;
|
|
98
|
+
if (options.charsetSentinel) {
|
|
99
|
+
for (i = 0; i < parts.length; ++i) {
|
|
100
|
+
if (parts[i].indexOf('utf8=') === 0) {
|
|
101
|
+
if (parts[i] === charsetSentinel) {
|
|
102
|
+
charset = 'utf-8';
|
|
103
|
+
} else if (parts[i] === isoSentinel) {
|
|
104
|
+
charset = 'iso-8859-1';
|
|
105
|
+
}
|
|
106
|
+
skipIndex = i;
|
|
107
|
+
i = parts.length; // The eslint settings do not allow break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
for (i = 0; i < parts.length; ++i) {
|
|
113
|
+
if (i === skipIndex) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
var part = parts[i];
|
|
117
|
+
|
|
118
|
+
var bracketEqualsPos = part.indexOf(']=');
|
|
119
|
+
var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
|
|
120
|
+
|
|
121
|
+
var key, val;
|
|
122
|
+
if (pos === -1) {
|
|
123
|
+
key = options.decoder(part, defaults.decoder, charset, 'key');
|
|
124
|
+
val = options.strictNullHandling ? null : '';
|
|
125
|
+
} else {
|
|
126
|
+
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');
|
|
127
|
+
val = utils.maybeMap(
|
|
128
|
+
parseArrayValue(part.slice(pos + 1), options),
|
|
129
|
+
function (encodedVal) {
|
|
130
|
+
return options.decoder(encodedVal, defaults.decoder, charset, 'value');
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
|
136
|
+
val = interpretNumericEntities(val);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (part.indexOf('[]=') > -1) {
|
|
140
|
+
val = isArray(val) ? [val] : val;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (has.call(obj, key)) {
|
|
144
|
+
obj[key] = utils.combine(obj[key], val);
|
|
145
|
+
} else {
|
|
146
|
+
obj[key] = val;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return obj;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
var parseObject = function (chain, val, options, valuesParsed) {
|
|
154
|
+
var leaf = valuesParsed ? val : parseArrayValue(val, options);
|
|
155
|
+
|
|
156
|
+
for (var i = chain.length - 1; i >= 0; --i) {
|
|
157
|
+
var obj;
|
|
158
|
+
var root = chain[i];
|
|
159
|
+
|
|
160
|
+
if (root === '[]' && options.parseArrays) {
|
|
161
|
+
obj = [].concat(leaf);
|
|
162
|
+
} else {
|
|
163
|
+
obj = options.plainObjects ? Object.create(null) : {};
|
|
164
|
+
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
165
|
+
var index = parseInt(cleanRoot, 10);
|
|
166
|
+
if (!options.parseArrays && cleanRoot === '') {
|
|
167
|
+
obj = { 0: leaf };
|
|
168
|
+
} else if (
|
|
169
|
+
!isNaN(index)
|
|
170
|
+
&& root !== cleanRoot
|
|
171
|
+
&& String(index) === cleanRoot
|
|
172
|
+
&& index >= 0
|
|
173
|
+
&& (options.parseArrays && index <= options.arrayLimit)
|
|
174
|
+
) {
|
|
175
|
+
obj = [];
|
|
176
|
+
obj[index] = leaf;
|
|
177
|
+
} else {
|
|
178
|
+
obj[cleanRoot] = leaf;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
leaf = obj;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return leaf;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) {
|
|
189
|
+
if (!givenKey) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Transform dot notation to bracket notation
|
|
194
|
+
var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey;
|
|
195
|
+
|
|
196
|
+
// The regex chunks
|
|
197
|
+
|
|
198
|
+
var brackets = /(\[[^[\]]*])/;
|
|
199
|
+
var child = /(\[[^[\]]*])/g;
|
|
200
|
+
|
|
201
|
+
// Get the parent
|
|
202
|
+
|
|
203
|
+
var segment = options.depth > 0 && brackets.exec(key);
|
|
204
|
+
var parent = segment ? key.slice(0, segment.index) : key;
|
|
205
|
+
|
|
206
|
+
// Stash the parent if it exists
|
|
207
|
+
|
|
208
|
+
var keys = [];
|
|
209
|
+
if (parent) {
|
|
210
|
+
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
|
211
|
+
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
212
|
+
if (!options.allowPrototypes) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
keys.push(parent);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Loop through children appending to the array until we hit depth
|
|
221
|
+
|
|
222
|
+
var i = 0;
|
|
223
|
+
while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) {
|
|
224
|
+
i += 1;
|
|
225
|
+
if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) {
|
|
226
|
+
if (!options.allowPrototypes) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
keys.push(segment[1]);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// If there's a remainder, just add whatever is left
|
|
234
|
+
|
|
235
|
+
if (segment) {
|
|
236
|
+
keys.push('[' + key.slice(segment.index) + ']');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return parseObject(keys, val, options, valuesParsed);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
var normalizeParseOptions = function normalizeParseOptions(opts) {
|
|
243
|
+
if (!opts) {
|
|
244
|
+
return defaults;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
|
|
248
|
+
throw new TypeError('Decoder has to be a function.');
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
252
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
253
|
+
}
|
|
254
|
+
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
|
258
|
+
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
|
259
|
+
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
|
260
|
+
charset: charset,
|
|
261
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
262
|
+
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
|
263
|
+
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
|
264
|
+
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
|
265
|
+
// eslint-disable-next-line no-implicit-coercion, no-extra-parens
|
|
266
|
+
depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth,
|
|
267
|
+
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
|
268
|
+
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
|
269
|
+
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
|
270
|
+
parseArrays: opts.parseArrays !== false,
|
|
271
|
+
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
|
272
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
module.exports = function (str, opts) {
|
|
277
|
+
var options = normalizeParseOptions(opts);
|
|
278
|
+
|
|
279
|
+
if (str === '' || str === null || typeof str === 'undefined') {
|
|
280
|
+
return options.plainObjects ? Object.create(null) : {};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
var tempObj = typeof str === 'string' ? parseValues(str, options) : str;
|
|
284
|
+
var obj = options.plainObjects ? Object.create(null) : {};
|
|
285
|
+
|
|
286
|
+
// Iterate over the keys and setup the new object
|
|
287
|
+
|
|
288
|
+
var keys = Object.keys(tempObj);
|
|
289
|
+
for (var i = 0; i < keys.length; ++i) {
|
|
290
|
+
var key = keys[i];
|
|
291
|
+
var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string');
|
|
292
|
+
obj = utils.merge(obj, newObj, options);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return utils.compact(obj);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
},{"./utils":5}],4:[function(require,module,exports){
|
|
299
|
+
'use strict';
|
|
300
|
+
|
|
301
|
+
var utils = require('./utils');
|
|
302
|
+
var formats = require('./formats');
|
|
303
|
+
var has = Object.prototype.hasOwnProperty;
|
|
304
|
+
|
|
305
|
+
var arrayPrefixGenerators = {
|
|
306
|
+
brackets: function brackets(prefix) {
|
|
307
|
+
return prefix + '[]';
|
|
308
|
+
},
|
|
309
|
+
comma: 'comma',
|
|
310
|
+
indices: function indices(prefix, key) {
|
|
311
|
+
return prefix + '[' + key + ']';
|
|
312
|
+
},
|
|
313
|
+
repeat: function repeat(prefix) {
|
|
314
|
+
return prefix;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
var isArray = Array.isArray;
|
|
319
|
+
var push = Array.prototype.push;
|
|
320
|
+
var pushToArray = function (arr, valueOrArray) {
|
|
321
|
+
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
var toISO = Date.prototype.toISOString;
|
|
325
|
+
|
|
326
|
+
var defaultFormat = formats['default'];
|
|
327
|
+
var defaults = {
|
|
328
|
+
addQueryPrefix: false,
|
|
329
|
+
allowDots: false,
|
|
330
|
+
charset: 'utf-8',
|
|
331
|
+
charsetSentinel: false,
|
|
332
|
+
delimiter: '&',
|
|
333
|
+
encode: true,
|
|
334
|
+
encoder: utils.encode,
|
|
335
|
+
encodeValuesOnly: false,
|
|
336
|
+
format: defaultFormat,
|
|
337
|
+
formatter: formats.formatters[defaultFormat],
|
|
338
|
+
// deprecated
|
|
339
|
+
indices: false,
|
|
340
|
+
serializeDate: function serializeDate(date) {
|
|
341
|
+
return toISO.call(date);
|
|
342
|
+
},
|
|
343
|
+
skipNulls: false,
|
|
344
|
+
strictNullHandling: false
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
var isNonNullishPrimitive = function isNonNullishPrimitive(v) {
|
|
348
|
+
return typeof v === 'string'
|
|
349
|
+
|| typeof v === 'number'
|
|
350
|
+
|| typeof v === 'boolean'
|
|
351
|
+
|| typeof v === 'symbol'
|
|
352
|
+
|| typeof v === 'bigint';
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
var stringify = function stringify(
|
|
356
|
+
object,
|
|
357
|
+
prefix,
|
|
358
|
+
generateArrayPrefix,
|
|
359
|
+
strictNullHandling,
|
|
360
|
+
skipNulls,
|
|
361
|
+
encoder,
|
|
362
|
+
filter,
|
|
363
|
+
sort,
|
|
364
|
+
allowDots,
|
|
365
|
+
serializeDate,
|
|
366
|
+
format,
|
|
367
|
+
formatter,
|
|
368
|
+
encodeValuesOnly,
|
|
369
|
+
charset
|
|
370
|
+
) {
|
|
371
|
+
var obj = object;
|
|
372
|
+
if (typeof filter === 'function') {
|
|
373
|
+
obj = filter(prefix, obj);
|
|
374
|
+
} else if (obj instanceof Date) {
|
|
375
|
+
obj = serializeDate(obj);
|
|
376
|
+
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
377
|
+
obj = utils.maybeMap(obj, function (value) {
|
|
378
|
+
if (value instanceof Date) {
|
|
379
|
+
return serializeDate(value);
|
|
380
|
+
}
|
|
381
|
+
return value;
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (obj === null) {
|
|
386
|
+
if (strictNullHandling) {
|
|
387
|
+
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
obj = '';
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (isNonNullishPrimitive(obj) || utils.isBuffer(obj)) {
|
|
394
|
+
if (encoder) {
|
|
395
|
+
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset, 'key', format);
|
|
396
|
+
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset, 'value', format))];
|
|
397
|
+
}
|
|
398
|
+
return [formatter(prefix) + '=' + formatter(String(obj))];
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var values = [];
|
|
402
|
+
|
|
403
|
+
if (typeof obj === 'undefined') {
|
|
404
|
+
return values;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
var objKeys;
|
|
408
|
+
if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
|
409
|
+
// we need to join elements in
|
|
410
|
+
objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : undefined }];
|
|
411
|
+
} else if (isArray(filter)) {
|
|
412
|
+
objKeys = filter;
|
|
413
|
+
} else {
|
|
414
|
+
var keys = Object.keys(obj);
|
|
415
|
+
objKeys = sort ? keys.sort(sort) : keys;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
for (var i = 0; i < objKeys.length; ++i) {
|
|
419
|
+
var key = objKeys[i];
|
|
420
|
+
var value = typeof key === 'object' && key.value !== undefined ? key.value : obj[key];
|
|
421
|
+
|
|
422
|
+
if (skipNulls && value === null) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
var keyPrefix = isArray(obj)
|
|
427
|
+
? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix
|
|
428
|
+
: prefix + (allowDots ? '.' + key : '[' + key + ']');
|
|
429
|
+
|
|
430
|
+
pushToArray(values, stringify(
|
|
431
|
+
value,
|
|
432
|
+
keyPrefix,
|
|
433
|
+
generateArrayPrefix,
|
|
434
|
+
strictNullHandling,
|
|
435
|
+
skipNulls,
|
|
436
|
+
encoder,
|
|
437
|
+
filter,
|
|
438
|
+
sort,
|
|
439
|
+
allowDots,
|
|
440
|
+
serializeDate,
|
|
441
|
+
format,
|
|
442
|
+
formatter,
|
|
443
|
+
encodeValuesOnly,
|
|
444
|
+
charset
|
|
445
|
+
));
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return values;
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
|
452
|
+
if (!opts) {
|
|
453
|
+
return defaults;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
|
|
457
|
+
throw new TypeError('Encoder has to be a function.');
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
var charset = opts.charset || defaults.charset;
|
|
461
|
+
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
|
462
|
+
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
var format = formats['default'];
|
|
466
|
+
if (typeof opts.format !== 'undefined') {
|
|
467
|
+
if (!has.call(formats.formatters, opts.format)) {
|
|
468
|
+
throw new TypeError('Unknown format option provided.');
|
|
469
|
+
}
|
|
470
|
+
format = opts.format;
|
|
471
|
+
}
|
|
472
|
+
var formatter = formats.formatters[format];
|
|
473
|
+
|
|
474
|
+
var filter = defaults.filter;
|
|
475
|
+
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
|
476
|
+
filter = opts.filter;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
return {
|
|
480
|
+
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
|
481
|
+
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
|
482
|
+
charset: charset,
|
|
483
|
+
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
|
484
|
+
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
|
485
|
+
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
|
486
|
+
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
|
487
|
+
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
|
488
|
+
filter: filter,
|
|
489
|
+
format: format,
|
|
490
|
+
formatter: formatter,
|
|
491
|
+
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
|
492
|
+
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
|
493
|
+
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
|
494
|
+
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
|
495
|
+
};
|
|
496
|
+
};
|
|
497
|
+
|
|
498
|
+
module.exports = function (object, opts) {
|
|
499
|
+
var obj = object;
|
|
500
|
+
var options = normalizeStringifyOptions(opts);
|
|
501
|
+
|
|
502
|
+
var objKeys;
|
|
503
|
+
var filter;
|
|
504
|
+
|
|
505
|
+
if (typeof options.filter === 'function') {
|
|
506
|
+
filter = options.filter;
|
|
507
|
+
obj = filter('', obj);
|
|
508
|
+
} else if (isArray(options.filter)) {
|
|
509
|
+
filter = options.filter;
|
|
510
|
+
objKeys = filter;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
var keys = [];
|
|
514
|
+
|
|
515
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
516
|
+
return '';
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
var arrayFormat;
|
|
520
|
+
if (opts && opts.arrayFormat in arrayPrefixGenerators) {
|
|
521
|
+
arrayFormat = opts.arrayFormat;
|
|
522
|
+
} else if (opts && 'indices' in opts) {
|
|
523
|
+
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
|
524
|
+
} else {
|
|
525
|
+
arrayFormat = 'indices';
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
var generateArrayPrefix = arrayPrefixGenerators[arrayFormat];
|
|
529
|
+
|
|
530
|
+
if (!objKeys) {
|
|
531
|
+
objKeys = Object.keys(obj);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (options.sort) {
|
|
535
|
+
objKeys.sort(options.sort);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
for (var i = 0; i < objKeys.length; ++i) {
|
|
539
|
+
var key = objKeys[i];
|
|
540
|
+
|
|
541
|
+
if (options.skipNulls && obj[key] === null) {
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
pushToArray(keys, stringify(
|
|
545
|
+
obj[key],
|
|
546
|
+
key,
|
|
547
|
+
generateArrayPrefix,
|
|
548
|
+
options.strictNullHandling,
|
|
549
|
+
options.skipNulls,
|
|
550
|
+
options.encode ? options.encoder : null,
|
|
551
|
+
options.filter,
|
|
552
|
+
options.sort,
|
|
553
|
+
options.allowDots,
|
|
554
|
+
options.serializeDate,
|
|
555
|
+
options.format,
|
|
556
|
+
options.formatter,
|
|
557
|
+
options.encodeValuesOnly,
|
|
558
|
+
options.charset
|
|
559
|
+
));
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
var joined = keys.join(options.delimiter);
|
|
563
|
+
var prefix = options.addQueryPrefix === true ? '?' : '';
|
|
564
|
+
|
|
565
|
+
if (options.charsetSentinel) {
|
|
566
|
+
if (options.charset === 'iso-8859-1') {
|
|
567
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
568
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
569
|
+
} else {
|
|
570
|
+
// encodeURIComponent('✓')
|
|
571
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return joined.length > 0 ? prefix + joined : '';
|
|
576
|
+
};
|
|
577
|
+
|
|
578
|
+
},{"./formats":1,"./utils":5}],5:[function(require,module,exports){
|
|
579
|
+
'use strict';
|
|
580
|
+
|
|
581
|
+
var formats = require('./formats');
|
|
582
|
+
|
|
583
|
+
var has = Object.prototype.hasOwnProperty;
|
|
584
|
+
var isArray = Array.isArray;
|
|
585
|
+
|
|
586
|
+
var hexTable = (function () {
|
|
587
|
+
var array = [];
|
|
588
|
+
for (var i = 0; i < 256; ++i) {
|
|
589
|
+
array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
return array;
|
|
593
|
+
}());
|
|
594
|
+
|
|
595
|
+
var compactQueue = function compactQueue(queue) {
|
|
596
|
+
while (queue.length > 1) {
|
|
597
|
+
var item = queue.pop();
|
|
598
|
+
var obj = item.obj[item.prop];
|
|
599
|
+
|
|
600
|
+
if (isArray(obj)) {
|
|
601
|
+
var compacted = [];
|
|
602
|
+
|
|
603
|
+
for (var j = 0; j < obj.length; ++j) {
|
|
604
|
+
if (typeof obj[j] !== 'undefined') {
|
|
605
|
+
compacted.push(obj[j]);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
item.obj[item.prop] = compacted;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
var arrayToObject = function arrayToObject(source, options) {
|
|
615
|
+
var obj = options && options.plainObjects ? Object.create(null) : {};
|
|
616
|
+
for (var i = 0; i < source.length; ++i) {
|
|
617
|
+
if (typeof source[i] !== 'undefined') {
|
|
618
|
+
obj[i] = source[i];
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
return obj;
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
var merge = function merge(target, source, options) {
|
|
626
|
+
/* eslint no-param-reassign: 0 */
|
|
627
|
+
if (!source) {
|
|
628
|
+
return target;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
if (typeof source !== 'object') {
|
|
632
|
+
if (isArray(target)) {
|
|
633
|
+
target.push(source);
|
|
634
|
+
} else if (target && typeof target === 'object') {
|
|
635
|
+
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
|
|
636
|
+
target[source] = true;
|
|
637
|
+
}
|
|
638
|
+
} else {
|
|
639
|
+
return [target, source];
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return target;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
if (!target || typeof target !== 'object') {
|
|
646
|
+
return [target].concat(source);
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
var mergeTarget = target;
|
|
650
|
+
if (isArray(target) && !isArray(source)) {
|
|
651
|
+
mergeTarget = arrayToObject(target, options);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (isArray(target) && isArray(source)) {
|
|
655
|
+
source.forEach(function (item, i) {
|
|
656
|
+
if (has.call(target, i)) {
|
|
657
|
+
var targetItem = target[i];
|
|
658
|
+
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
|
|
659
|
+
target[i] = merge(targetItem, item, options);
|
|
660
|
+
} else {
|
|
661
|
+
target.push(item);
|
|
662
|
+
}
|
|
663
|
+
} else {
|
|
664
|
+
target[i] = item;
|
|
665
|
+
}
|
|
666
|
+
});
|
|
667
|
+
return target;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
return Object.keys(source).reduce(function (acc, key) {
|
|
671
|
+
var value = source[key];
|
|
672
|
+
|
|
673
|
+
if (has.call(acc, key)) {
|
|
674
|
+
acc[key] = merge(acc[key], value, options);
|
|
675
|
+
} else {
|
|
676
|
+
acc[key] = value;
|
|
677
|
+
}
|
|
678
|
+
return acc;
|
|
679
|
+
}, mergeTarget);
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
var assign = function assignSingleSource(target, source) {
|
|
683
|
+
return Object.keys(source).reduce(function (acc, key) {
|
|
684
|
+
acc[key] = source[key];
|
|
685
|
+
return acc;
|
|
686
|
+
}, target);
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
var decode = function (str, decoder, charset) {
|
|
690
|
+
var strWithoutPlus = str.replace(/\+/g, ' ');
|
|
691
|
+
if (charset === 'iso-8859-1') {
|
|
692
|
+
// unescape never throws, no try...catch needed:
|
|
693
|
+
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
|
694
|
+
}
|
|
695
|
+
// utf-8
|
|
696
|
+
try {
|
|
697
|
+
return decodeURIComponent(strWithoutPlus);
|
|
698
|
+
} catch (e) {
|
|
699
|
+
return strWithoutPlus;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
var encode = function encode(str, defaultEncoder, charset, kind, format) {
|
|
704
|
+
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
|
|
705
|
+
// It has been adapted here for stricter adherence to RFC 3986
|
|
706
|
+
if (str.length === 0) {
|
|
707
|
+
return str;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
var string = str;
|
|
711
|
+
if (typeof str === 'symbol') {
|
|
712
|
+
string = Symbol.prototype.toString.call(str);
|
|
713
|
+
} else if (typeof str !== 'string') {
|
|
714
|
+
string = String(str);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
if (charset === 'iso-8859-1') {
|
|
718
|
+
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
|
719
|
+
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
var out = '';
|
|
724
|
+
for (var i = 0; i < string.length; ++i) {
|
|
725
|
+
var c = string.charCodeAt(i);
|
|
726
|
+
|
|
727
|
+
if (
|
|
728
|
+
c === 0x2D // -
|
|
729
|
+
|| c === 0x2E // .
|
|
730
|
+
|| c === 0x5F // _
|
|
731
|
+
|| c === 0x7E // ~
|
|
732
|
+
|| (c >= 0x30 && c <= 0x39) // 0-9
|
|
733
|
+
|| (c >= 0x41 && c <= 0x5A) // a-z
|
|
734
|
+
|| (c >= 0x61 && c <= 0x7A) // A-Z
|
|
735
|
+
|| (format === formats.RFC1738 && (c === 0x28 || c === 0x29)) // ( )
|
|
736
|
+
) {
|
|
737
|
+
out += string.charAt(i);
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (c < 0x80) {
|
|
742
|
+
out = out + hexTable[c];
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
if (c < 0x800) {
|
|
747
|
+
out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]);
|
|
748
|
+
continue;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (c < 0xD800 || c >= 0xE000) {
|
|
752
|
+
out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]);
|
|
753
|
+
continue;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
i += 1;
|
|
757
|
+
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
|
|
758
|
+
out += hexTable[0xF0 | (c >> 18)]
|
|
759
|
+
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
|
|
760
|
+
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
|
|
761
|
+
+ hexTable[0x80 | (c & 0x3F)];
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
return out;
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
var compact = function compact(value) {
|
|
768
|
+
var queue = [{ obj: { o: value }, prop: 'o' }];
|
|
769
|
+
var refs = [];
|
|
770
|
+
|
|
771
|
+
for (var i = 0; i < queue.length; ++i) {
|
|
772
|
+
var item = queue[i];
|
|
773
|
+
var obj = item.obj[item.prop];
|
|
774
|
+
|
|
775
|
+
var keys = Object.keys(obj);
|
|
776
|
+
for (var j = 0; j < keys.length; ++j) {
|
|
777
|
+
var key = keys[j];
|
|
778
|
+
var val = obj[key];
|
|
779
|
+
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
|
|
780
|
+
queue.push({ obj: obj, prop: key });
|
|
781
|
+
refs.push(val);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
compactQueue(queue);
|
|
787
|
+
|
|
788
|
+
return value;
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
var isRegExp = function isRegExp(obj) {
|
|
792
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
793
|
+
};
|
|
794
|
+
|
|
795
|
+
var isBuffer = function isBuffer(obj) {
|
|
796
|
+
if (!obj || typeof obj !== 'object') {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
|
801
|
+
};
|
|
802
|
+
|
|
803
|
+
var combine = function combine(a, b) {
|
|
804
|
+
return [].concat(a, b);
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
var maybeMap = function maybeMap(val, fn) {
|
|
808
|
+
if (isArray(val)) {
|
|
809
|
+
var mapped = [];
|
|
810
|
+
for (var i = 0; i < val.length; i += 1) {
|
|
811
|
+
mapped.push(fn(val[i]));
|
|
812
|
+
}
|
|
813
|
+
return mapped;
|
|
814
|
+
}
|
|
815
|
+
return fn(val);
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
module.exports = {
|
|
819
|
+
arrayToObject: arrayToObject,
|
|
820
|
+
assign: assign,
|
|
821
|
+
combine: combine,
|
|
822
|
+
compact: compact,
|
|
823
|
+
decode: decode,
|
|
824
|
+
encode: encode,
|
|
825
|
+
isBuffer: isBuffer,
|
|
826
|
+
isRegExp: isRegExp,
|
|
827
|
+
maybeMap: maybeMap,
|
|
828
|
+
merge: merge
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
},{"./formats":1}]},{},[2])(2)
|
|
832
|
+
});
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "qs",
|
|
3
3
|
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
|
4
4
|
"homepage": "https://github.com/ljharb/qs",
|
|
5
|
-
"version": "6.9.
|
|
5
|
+
"version": "6.9.6",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/ljharb/qs.git"
|