qs 6.5.0 → 6.6.0
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/.eslintrc +6 -3
- package/CHANGELOG.md +30 -0
- package/README.md +88 -2
- package/dist/qs.js +210 -88
- package/lib/parse.js +87 -33
- package/lib/stringify.js +46 -14
- package/lib/utils.js +78 -42
- package/package.json +9 -8
- package/test/.eslintrc +6 -0
- package/test/parse.js +118 -5
- package/test/stringify.js +59 -6
- package/test/utils.js +55 -0
package/dist/qs.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
|
|
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
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var replace = String.prototype.replace;
|
|
@@ -42,21 +42,62 @@ var defaults = {
|
|
|
42
42
|
allowDots: false,
|
|
43
43
|
allowPrototypes: false,
|
|
44
44
|
arrayLimit: 20,
|
|
45
|
+
charset: 'utf-8',
|
|
46
|
+
charsetSentinel: false,
|
|
45
47
|
decoder: utils.decode,
|
|
46
48
|
delimiter: '&',
|
|
47
49
|
depth: 5,
|
|
50
|
+
ignoreQueryPrefix: false,
|
|
51
|
+
interpretNumericEntities: false,
|
|
48
52
|
parameterLimit: 1000,
|
|
53
|
+
parseArrays: true,
|
|
49
54
|
plainObjects: false,
|
|
50
55
|
strictNullHandling: false
|
|
51
56
|
};
|
|
52
57
|
|
|
58
|
+
var interpretNumericEntities = function (str) {
|
|
59
|
+
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
|
60
|
+
return String.fromCharCode(parseInt(numberStr, 10));
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// This is what browsers will submit when the ✓ character occurs in an
|
|
65
|
+
// application/x-www-form-urlencoded body and the encoding of the page containing
|
|
66
|
+
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
|
67
|
+
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
|
68
|
+
// the ✓ character, such as us-ascii.
|
|
69
|
+
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
|
70
|
+
|
|
71
|
+
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
|
72
|
+
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
|
73
|
+
|
|
53
74
|
var parseValues = function parseQueryStringValues(str, options) {
|
|
54
75
|
var obj = {};
|
|
55
76
|
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
|
56
77
|
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
|
57
78
|
var parts = cleanStr.split(options.delimiter, limit);
|
|
79
|
+
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
|
80
|
+
var i;
|
|
81
|
+
|
|
82
|
+
var charset = options.charset;
|
|
83
|
+
if (options.charsetSentinel) {
|
|
84
|
+
for (i = 0; i < parts.length; ++i) {
|
|
85
|
+
if (parts[i].indexOf('utf8=') === 0) {
|
|
86
|
+
if (parts[i] === charsetSentinel) {
|
|
87
|
+
charset = 'utf-8';
|
|
88
|
+
} else if (parts[i] === isoSentinel) {
|
|
89
|
+
charset = 'iso-8859-1';
|
|
90
|
+
}
|
|
91
|
+
skipIndex = i;
|
|
92
|
+
i = parts.length; // The eslint settings do not allow break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
58
96
|
|
|
59
|
-
for (
|
|
97
|
+
for (i = 0; i < parts.length; ++i) {
|
|
98
|
+
if (i === skipIndex) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
60
101
|
var part = parts[i];
|
|
61
102
|
|
|
62
103
|
var bracketEqualsPos = part.indexOf(']=');
|
|
@@ -64,14 +105,18 @@ var parseValues = function parseQueryStringValues(str, options) {
|
|
|
64
105
|
|
|
65
106
|
var key, val;
|
|
66
107
|
if (pos === -1) {
|
|
67
|
-
key = options.decoder(part, defaults.decoder);
|
|
108
|
+
key = options.decoder(part, defaults.decoder, charset);
|
|
68
109
|
val = options.strictNullHandling ? null : '';
|
|
69
110
|
} else {
|
|
70
|
-
key = options.decoder(part.slice(0, pos), defaults.decoder);
|
|
71
|
-
val = options.decoder(part.slice(pos + 1), defaults.decoder);
|
|
111
|
+
key = options.decoder(part.slice(0, pos), defaults.decoder, charset);
|
|
112
|
+
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
|
116
|
+
val = interpretNumericEntities(val);
|
|
72
117
|
}
|
|
73
118
|
if (has.call(obj, key)) {
|
|
74
|
-
obj[key] =
|
|
119
|
+
obj[key] = utils.combine(obj[key], val);
|
|
75
120
|
} else {
|
|
76
121
|
obj[key] = val;
|
|
77
122
|
}
|
|
@@ -80,36 +125,39 @@ var parseValues = function parseQueryStringValues(str, options) {
|
|
|
80
125
|
return obj;
|
|
81
126
|
};
|
|
82
127
|
|
|
83
|
-
var parseObject = function
|
|
84
|
-
|
|
85
|
-
return val;
|
|
86
|
-
}
|
|
128
|
+
var parseObject = function (chain, val, options) {
|
|
129
|
+
var leaf = val;
|
|
87
130
|
|
|
88
|
-
var
|
|
131
|
+
for (var i = chain.length - 1; i >= 0; --i) {
|
|
132
|
+
var obj;
|
|
133
|
+
var root = chain[i];
|
|
89
134
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
obj = [];
|
|
93
|
-
obj = obj.concat(parseObject(chain, val, options));
|
|
94
|
-
} else {
|
|
95
|
-
obj = options.plainObjects ? Object.create(null) : {};
|
|
96
|
-
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
97
|
-
var index = parseInt(cleanRoot, 10);
|
|
98
|
-
if (
|
|
99
|
-
!isNaN(index)
|
|
100
|
-
&& root !== cleanRoot
|
|
101
|
-
&& String(index) === cleanRoot
|
|
102
|
-
&& index >= 0
|
|
103
|
-
&& (options.parseArrays && index <= options.arrayLimit)
|
|
104
|
-
) {
|
|
105
|
-
obj = [];
|
|
106
|
-
obj[index] = parseObject(chain, val, options);
|
|
135
|
+
if (root === '[]' && options.parseArrays) {
|
|
136
|
+
obj = [].concat(leaf);
|
|
107
137
|
} else {
|
|
108
|
-
obj
|
|
138
|
+
obj = options.plainObjects ? Object.create(null) : {};
|
|
139
|
+
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
|
140
|
+
var index = parseInt(cleanRoot, 10);
|
|
141
|
+
if (!options.parseArrays && cleanRoot === '') {
|
|
142
|
+
obj = { 0: leaf };
|
|
143
|
+
} else if (
|
|
144
|
+
!isNaN(index)
|
|
145
|
+
&& root !== cleanRoot
|
|
146
|
+
&& String(index) === cleanRoot
|
|
147
|
+
&& index >= 0
|
|
148
|
+
&& (options.parseArrays && index <= options.arrayLimit)
|
|
149
|
+
) {
|
|
150
|
+
obj = [];
|
|
151
|
+
obj[index] = leaf;
|
|
152
|
+
} else {
|
|
153
|
+
obj[cleanRoot] = leaf;
|
|
154
|
+
}
|
|
109
155
|
}
|
|
156
|
+
|
|
157
|
+
leaf = obj;
|
|
110
158
|
}
|
|
111
159
|
|
|
112
|
-
return
|
|
160
|
+
return leaf;
|
|
113
161
|
};
|
|
114
162
|
|
|
115
163
|
var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
|
@@ -134,8 +182,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
|
|
134
182
|
|
|
135
183
|
var keys = [];
|
|
136
184
|
if (parent) {
|
|
137
|
-
// If we aren't using plain objects, optionally prefix keys
|
|
138
|
-
// that would overwrite object prototype properties
|
|
185
|
+
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
|
139
186
|
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
|
140
187
|
if (!options.allowPrototypes) {
|
|
141
188
|
return;
|
|
@@ -180,12 +227,19 @@ module.exports = function (str, opts) {
|
|
|
180
227
|
options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults.arrayLimit;
|
|
181
228
|
options.parseArrays = options.parseArrays !== false;
|
|
182
229
|
options.decoder = typeof options.decoder === 'function' ? options.decoder : defaults.decoder;
|
|
183
|
-
options.allowDots = typeof options.allowDots === '
|
|
230
|
+
options.allowDots = typeof options.allowDots === 'undefined' ? defaults.allowDots : !!options.allowDots;
|
|
184
231
|
options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : defaults.plainObjects;
|
|
185
232
|
options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : defaults.allowPrototypes;
|
|
186
233
|
options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : defaults.parameterLimit;
|
|
187
234
|
options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
|
|
188
235
|
|
|
236
|
+
if (typeof options.charset !== 'undefined' && options.charset !== 'utf-8' && options.charset !== 'iso-8859-1') {
|
|
237
|
+
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
238
|
+
}
|
|
239
|
+
if (typeof options.charset === 'undefined') {
|
|
240
|
+
options.charset = defaults.charset;
|
|
241
|
+
}
|
|
242
|
+
|
|
189
243
|
if (str === '' || str === null || typeof str === 'undefined') {
|
|
190
244
|
return options.plainObjects ? Object.create(null) : {};
|
|
191
245
|
}
|
|
@@ -223,13 +277,25 @@ var arrayPrefixGenerators = {
|
|
|
223
277
|
}
|
|
224
278
|
};
|
|
225
279
|
|
|
280
|
+
var isArray = Array.isArray;
|
|
281
|
+
var push = Array.prototype.push;
|
|
282
|
+
var pushToArray = function (arr, valueOrArray) {
|
|
283
|
+
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
|
284
|
+
};
|
|
285
|
+
|
|
226
286
|
var toISO = Date.prototype.toISOString;
|
|
227
287
|
|
|
228
288
|
var defaults = {
|
|
289
|
+
addQueryPrefix: false,
|
|
290
|
+
allowDots: false,
|
|
291
|
+
charset: 'utf-8',
|
|
292
|
+
charsetSentinel: false,
|
|
229
293
|
delimiter: '&',
|
|
230
294
|
encode: true,
|
|
231
295
|
encoder: utils.encode,
|
|
232
296
|
encodeValuesOnly: false,
|
|
297
|
+
// deprecated
|
|
298
|
+
indices: false,
|
|
233
299
|
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
|
|
234
300
|
return toISO.call(date);
|
|
235
301
|
},
|
|
@@ -249,16 +315,19 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
|
249
315
|
allowDots,
|
|
250
316
|
serializeDate,
|
|
251
317
|
formatter,
|
|
252
|
-
encodeValuesOnly
|
|
318
|
+
encodeValuesOnly,
|
|
319
|
+
charset
|
|
253
320
|
) {
|
|
254
321
|
var obj = object;
|
|
255
322
|
if (typeof filter === 'function') {
|
|
256
323
|
obj = filter(prefix, obj);
|
|
257
324
|
} else if (obj instanceof Date) {
|
|
258
325
|
obj = serializeDate(obj);
|
|
259
|
-
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (obj === null) {
|
|
260
329
|
if (strictNullHandling) {
|
|
261
|
-
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix;
|
|
330
|
+
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix;
|
|
262
331
|
}
|
|
263
332
|
|
|
264
333
|
obj = '';
|
|
@@ -266,8 +335,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
|
266
335
|
|
|
267
336
|
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
|
|
268
337
|
if (encoder) {
|
|
269
|
-
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder);
|
|
270
|
-
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))];
|
|
338
|
+
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset);
|
|
339
|
+
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))];
|
|
271
340
|
}
|
|
272
341
|
return [formatter(prefix) + '=' + formatter(String(obj))];
|
|
273
342
|
}
|
|
@@ -294,7 +363,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
|
294
363
|
}
|
|
295
364
|
|
|
296
365
|
if (Array.isArray(obj)) {
|
|
297
|
-
values
|
|
366
|
+
pushToArray(values, stringify(
|
|
298
367
|
obj[key],
|
|
299
368
|
generateArrayPrefix(prefix, key),
|
|
300
369
|
generateArrayPrefix,
|
|
@@ -306,10 +375,11 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
|
306
375
|
allowDots,
|
|
307
376
|
serializeDate,
|
|
308
377
|
formatter,
|
|
309
|
-
encodeValuesOnly
|
|
378
|
+
encodeValuesOnly,
|
|
379
|
+
charset
|
|
310
380
|
));
|
|
311
381
|
} else {
|
|
312
|
-
values
|
|
382
|
+
pushToArray(values, stringify(
|
|
313
383
|
obj[key],
|
|
314
384
|
prefix + (allowDots ? '.' + key : '[' + key + ']'),
|
|
315
385
|
generateArrayPrefix,
|
|
@@ -321,7 +391,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
|
|
321
391
|
allowDots,
|
|
322
392
|
serializeDate,
|
|
323
393
|
formatter,
|
|
324
|
-
encodeValuesOnly
|
|
394
|
+
encodeValuesOnly,
|
|
395
|
+
charset
|
|
325
396
|
));
|
|
326
397
|
}
|
|
327
398
|
}
|
|
@@ -343,11 +414,16 @@ module.exports = function (object, opts) {
|
|
|
343
414
|
var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
|
|
344
415
|
var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder;
|
|
345
416
|
var sort = typeof options.sort === 'function' ? options.sort : null;
|
|
346
|
-
var allowDots = typeof options.allowDots === 'undefined' ?
|
|
417
|
+
var allowDots = typeof options.allowDots === 'undefined' ? defaults.allowDots : !!options.allowDots;
|
|
347
418
|
var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
|
|
348
419
|
var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
|
|
420
|
+
var charset = options.charset || defaults.charset;
|
|
421
|
+
if (typeof options.charset !== 'undefined' && options.charset !== 'utf-8' && options.charset !== 'iso-8859-1') {
|
|
422
|
+
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
|
|
423
|
+
}
|
|
424
|
+
|
|
349
425
|
if (typeof options.format === 'undefined') {
|
|
350
|
-
options.format = formats
|
|
426
|
+
options.format = formats['default'];
|
|
351
427
|
} else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
|
|
352
428
|
throw new TypeError('Unknown format option provided.');
|
|
353
429
|
}
|
|
@@ -394,8 +470,7 @@ module.exports = function (object, opts) {
|
|
|
394
470
|
if (skipNulls && obj[key] === null) {
|
|
395
471
|
continue;
|
|
396
472
|
}
|
|
397
|
-
|
|
398
|
-
keys = keys.concat(stringify(
|
|
473
|
+
pushToArray(keys, stringify(
|
|
399
474
|
obj[key],
|
|
400
475
|
key,
|
|
401
476
|
generateArrayPrefix,
|
|
@@ -407,13 +482,24 @@ module.exports = function (object, opts) {
|
|
|
407
482
|
allowDots,
|
|
408
483
|
serializeDate,
|
|
409
484
|
formatter,
|
|
410
|
-
encodeValuesOnly
|
|
485
|
+
encodeValuesOnly,
|
|
486
|
+
charset
|
|
411
487
|
));
|
|
412
488
|
}
|
|
413
489
|
|
|
414
490
|
var joined = keys.join(delimiter);
|
|
415
491
|
var prefix = options.addQueryPrefix === true ? '?' : '';
|
|
416
492
|
|
|
493
|
+
if (options.charsetSentinel) {
|
|
494
|
+
if (charset === 'iso-8859-1') {
|
|
495
|
+
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
|
496
|
+
prefix += 'utf8=%26%2310003%3B&';
|
|
497
|
+
} else {
|
|
498
|
+
// encodeURIComponent('✓')
|
|
499
|
+
prefix += 'utf8=%E2%9C%93&';
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
417
503
|
return joined.length > 0 ? prefix + joined : '';
|
|
418
504
|
};
|
|
419
505
|
|
|
@@ -431,7 +517,26 @@ var hexTable = (function () {
|
|
|
431
517
|
return array;
|
|
432
518
|
}());
|
|
433
519
|
|
|
434
|
-
|
|
520
|
+
var compactQueue = function compactQueue(queue) {
|
|
521
|
+
while (queue.length > 1) {
|
|
522
|
+
var item = queue.pop();
|
|
523
|
+
var obj = item.obj[item.prop];
|
|
524
|
+
|
|
525
|
+
if (Array.isArray(obj)) {
|
|
526
|
+
var compacted = [];
|
|
527
|
+
|
|
528
|
+
for (var j = 0; j < obj.length; ++j) {
|
|
529
|
+
if (typeof obj[j] !== 'undefined') {
|
|
530
|
+
compacted.push(obj[j]);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
item.obj[item.prop] = compacted;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
var arrayToObject = function arrayToObject(source, options) {
|
|
435
540
|
var obj = options && options.plainObjects ? Object.create(null) : {};
|
|
436
541
|
for (var i = 0; i < source.length; ++i) {
|
|
437
542
|
if (typeof source[i] !== 'undefined') {
|
|
@@ -442,7 +547,7 @@ exports.arrayToObject = function (source, options) {
|
|
|
442
547
|
return obj;
|
|
443
548
|
};
|
|
444
549
|
|
|
445
|
-
|
|
550
|
+
var merge = function merge(target, source, options) {
|
|
446
551
|
if (!source) {
|
|
447
552
|
return target;
|
|
448
553
|
}
|
|
@@ -451,7 +556,7 @@ exports.merge = function (target, source, options) {
|
|
|
451
556
|
if (Array.isArray(target)) {
|
|
452
557
|
target.push(source);
|
|
453
558
|
} else if (typeof target === 'object') {
|
|
454
|
-
if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
|
|
559
|
+
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
|
|
455
560
|
target[source] = true;
|
|
456
561
|
}
|
|
457
562
|
} else {
|
|
@@ -467,14 +572,14 @@ exports.merge = function (target, source, options) {
|
|
|
467
572
|
|
|
468
573
|
var mergeTarget = target;
|
|
469
574
|
if (Array.isArray(target) && !Array.isArray(source)) {
|
|
470
|
-
mergeTarget =
|
|
575
|
+
mergeTarget = arrayToObject(target, options);
|
|
471
576
|
}
|
|
472
577
|
|
|
473
578
|
if (Array.isArray(target) && Array.isArray(source)) {
|
|
474
579
|
source.forEach(function (item, i) {
|
|
475
580
|
if (has.call(target, i)) {
|
|
476
581
|
if (target[i] && typeof target[i] === 'object') {
|
|
477
|
-
target[i] =
|
|
582
|
+
target[i] = merge(target[i], item, options);
|
|
478
583
|
} else {
|
|
479
584
|
target.push(item);
|
|
480
585
|
}
|
|
@@ -489,7 +594,7 @@ exports.merge = function (target, source, options) {
|
|
|
489
594
|
var value = source[key];
|
|
490
595
|
|
|
491
596
|
if (has.call(acc, key)) {
|
|
492
|
-
acc[key] =
|
|
597
|
+
acc[key] = merge(acc[key], value, options);
|
|
493
598
|
} else {
|
|
494
599
|
acc[key] = value;
|
|
495
600
|
}
|
|
@@ -497,22 +602,28 @@ exports.merge = function (target, source, options) {
|
|
|
497
602
|
}, mergeTarget);
|
|
498
603
|
};
|
|
499
604
|
|
|
500
|
-
|
|
605
|
+
var assign = function assignSingleSource(target, source) {
|
|
501
606
|
return Object.keys(source).reduce(function (acc, key) {
|
|
502
607
|
acc[key] = source[key];
|
|
503
608
|
return acc;
|
|
504
609
|
}, target);
|
|
505
610
|
};
|
|
506
611
|
|
|
507
|
-
|
|
612
|
+
var decode = function (str, decoder, charset) {
|
|
613
|
+
var strWithoutPlus = str.replace(/\+/g, ' ');
|
|
614
|
+
if (charset === 'iso-8859-1') {
|
|
615
|
+
// unescape never throws, no try...catch needed:
|
|
616
|
+
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
|
617
|
+
}
|
|
618
|
+
// utf-8
|
|
508
619
|
try {
|
|
509
|
-
return decodeURIComponent(
|
|
620
|
+
return decodeURIComponent(strWithoutPlus);
|
|
510
621
|
} catch (e) {
|
|
511
|
-
return
|
|
622
|
+
return strWithoutPlus;
|
|
512
623
|
}
|
|
513
624
|
};
|
|
514
625
|
|
|
515
|
-
|
|
626
|
+
var encode = function encode(str, defaultEncoder, charset) {
|
|
516
627
|
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
|
|
517
628
|
// It has been adapted here for stricter adherence to RFC 3986
|
|
518
629
|
if (str.length === 0) {
|
|
@@ -521,12 +632,18 @@ exports.encode = function (str) {
|
|
|
521
632
|
|
|
522
633
|
var string = typeof str === 'string' ? str : String(str);
|
|
523
634
|
|
|
635
|
+
if (charset === 'iso-8859-1') {
|
|
636
|
+
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
|
637
|
+
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
|
|
524
641
|
var out = '';
|
|
525
642
|
for (var i = 0; i < string.length; ++i) {
|
|
526
643
|
var c = string.charCodeAt(i);
|
|
527
644
|
|
|
528
645
|
if (
|
|
529
|
-
c === 0x2D
|
|
646
|
+
c === 0x2D // -
|
|
530
647
|
|| c === 0x2E // .
|
|
531
648
|
|| c === 0x5F // _
|
|
532
649
|
|| c === 0x7E // ~
|
|
@@ -564,46 +681,35 @@ exports.encode = function (str) {
|
|
|
564
681
|
return out;
|
|
565
682
|
};
|
|
566
683
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
var refs = references || [];
|
|
573
|
-
var lookup = refs.indexOf(obj);
|
|
574
|
-
if (lookup !== -1) {
|
|
575
|
-
return refs[lookup];
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
refs.push(obj);
|
|
684
|
+
var compact = function compact(value) {
|
|
685
|
+
var queue = [{ obj: { o: value }, prop: 'o' }];
|
|
686
|
+
var refs = [];
|
|
579
687
|
|
|
580
|
-
|
|
581
|
-
var
|
|
688
|
+
for (var i = 0; i < queue.length; ++i) {
|
|
689
|
+
var item = queue[i];
|
|
690
|
+
var obj = item.obj[item.prop];
|
|
582
691
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
692
|
+
var keys = Object.keys(obj);
|
|
693
|
+
for (var j = 0; j < keys.length; ++j) {
|
|
694
|
+
var key = keys[j];
|
|
695
|
+
var val = obj[key];
|
|
696
|
+
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) {
|
|
697
|
+
queue.push({ obj: obj, prop: key });
|
|
698
|
+
refs.push(val);
|
|
588
699
|
}
|
|
589
700
|
}
|
|
590
|
-
|
|
591
|
-
return compacted;
|
|
592
701
|
}
|
|
593
702
|
|
|
594
|
-
|
|
595
|
-
keys.forEach(function (key) {
|
|
596
|
-
obj[key] = exports.compact(obj[key], refs);
|
|
597
|
-
});
|
|
703
|
+
compactQueue(queue);
|
|
598
704
|
|
|
599
|
-
return
|
|
705
|
+
return value;
|
|
600
706
|
};
|
|
601
707
|
|
|
602
|
-
|
|
708
|
+
var isRegExp = function isRegExp(obj) {
|
|
603
709
|
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
604
710
|
};
|
|
605
711
|
|
|
606
|
-
|
|
712
|
+
var isBuffer = function isBuffer(obj) {
|
|
607
713
|
if (obj === null || typeof obj === 'undefined') {
|
|
608
714
|
return false;
|
|
609
715
|
}
|
|
@@ -611,5 +717,21 @@ exports.isBuffer = function (obj) {
|
|
|
611
717
|
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
|
612
718
|
};
|
|
613
719
|
|
|
720
|
+
var combine = function combine(a, b) {
|
|
721
|
+
return [].concat(a, b);
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
module.exports = {
|
|
725
|
+
arrayToObject: arrayToObject,
|
|
726
|
+
assign: assign,
|
|
727
|
+
combine: combine,
|
|
728
|
+
compact: compact,
|
|
729
|
+
decode: decode,
|
|
730
|
+
encode: encode,
|
|
731
|
+
isBuffer: isBuffer,
|
|
732
|
+
isRegExp: isRegExp,
|
|
733
|
+
merge: merge
|
|
734
|
+
};
|
|
735
|
+
|
|
614
736
|
},{}]},{},[2])(2)
|
|
615
|
-
});
|
|
737
|
+
});
|