qs 6.4.1 → 6.5.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/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(){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){
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){
2
2
  'use strict';
3
3
 
4
4
  var replace = String.prototype.replace;
@@ -11,7 +11,7 @@ module.exports = {
11
11
  return replace.call(value, percentTwenties, '+');
12
12
  },
13
13
  RFC3986: function (value) {
14
- return String(value);
14
+ return value;
15
15
  }
16
16
  },
17
17
  RFC1738: 'RFC1738',
@@ -52,19 +52,23 @@ var defaults = {
52
52
 
53
53
  var parseValues = function parseQueryStringValues(str, options) {
54
54
  var obj = {};
55
- var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
55
+ var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
56
+ var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
57
+ var parts = cleanStr.split(options.delimiter, limit);
56
58
 
57
59
  for (var i = 0; i < parts.length; ++i) {
58
60
  var part = parts[i];
59
- var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
61
+
62
+ var bracketEqualsPos = part.indexOf(']=');
63
+ var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
60
64
 
61
65
  var key, val;
62
66
  if (pos === -1) {
63
- key = options.decoder(part);
67
+ key = options.decoder(part, defaults.decoder);
64
68
  val = options.strictNullHandling ? null : '';
65
69
  } else {
66
- key = options.decoder(part.slice(0, pos));
67
- val = options.decoder(part.slice(pos + 1));
70
+ key = options.decoder(part.slice(0, pos), defaults.decoder);
71
+ val = options.decoder(part.slice(pos + 1), defaults.decoder);
68
72
  }
69
73
  if (has.call(obj, key)) {
70
74
  obj[key] = [].concat(obj[key]).concat(val);
@@ -84,16 +88,14 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
84
88
  var root = chain.shift();
85
89
 
86
90
  var obj;
87
- if (root === '[]' && options.parseArrays) {
91
+ if (root === '[]') {
88
92
  obj = [];
89
93
  obj = obj.concat(parseObject(chain, val, options));
90
94
  } else {
91
95
  obj = options.plainObjects ? Object.create(null) : {};
92
96
  var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
93
97
  var index = parseInt(cleanRoot, 10);
94
- if (!options.parseArrays && cleanRoot === '') {
95
- obj = { 0: val };
96
- } else if (
98
+ if (
97
99
  !isNaN(index)
98
100
  && root !== cleanRoot
99
101
  && String(index) === cleanRoot
@@ -102,7 +104,7 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
102
104
  ) {
103
105
  obj = [];
104
106
  obj[index] = parseObject(chain, val, options);
105
- } else if (cleanRoot !== '__proto__') {
107
+ } else {
106
108
  obj[cleanRoot] = parseObject(chain, val, options);
107
109
  }
108
110
  }
@@ -132,7 +134,8 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
132
134
 
133
135
  var keys = [];
134
136
  if (parent) {
135
- // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
137
+ // If we aren't using plain objects, optionally prefix keys
138
+ // that would overwrite object prototype properties
136
139
  if (!options.plainObjects && has.call(Object.prototype, parent)) {
137
140
  if (!options.allowPrototypes) {
138
141
  return;
@@ -165,12 +168,13 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
165
168
  };
166
169
 
167
170
  module.exports = function (str, opts) {
168
- var options = opts || {};
171
+ var options = opts ? utils.assign({}, opts) : {};
169
172
 
170
173
  if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') {
171
174
  throw new TypeError('Decoder has to be a function.');
172
175
  }
173
176
 
177
+ options.ignoreQueryPrefix = options.ignoreQueryPrefix === true;
174
178
  options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter;
175
179
  options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth;
176
180
  options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults.arrayLimit;
@@ -208,23 +212,17 @@ var utils = require('./utils');
208
212
  var formats = require('./formats');
209
213
 
210
214
  var arrayPrefixGenerators = {
211
- brackets: function brackets(prefix) {
215
+ brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
212
216
  return prefix + '[]';
213
217
  },
214
- indices: function indices(prefix, key) {
218
+ indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
215
219
  return prefix + '[' + key + ']';
216
220
  },
217
- repeat: function repeat(prefix) {
221
+ repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
218
222
  return prefix;
219
223
  }
220
224
  };
221
225
 
222
- var isArray = Array.isArray;
223
- var push = Array.prototype.push;
224
- var pushToArray = function (arr, valueOrArray) {
225
- push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
226
- };
227
-
228
226
  var toISO = Date.prototype.toISOString;
229
227
 
230
228
  var defaults = {
@@ -232,14 +230,14 @@ var defaults = {
232
230
  encode: true,
233
231
  encoder: utils.encode,
234
232
  encodeValuesOnly: false,
235
- serializeDate: function serializeDate(date) {
233
+ serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
236
234
  return toISO.call(date);
237
235
  },
238
236
  skipNulls: false,
239
237
  strictNullHandling: false
240
238
  };
241
239
 
242
- var stringify = function stringify(
240
+ var stringify = function stringify( // eslint-disable-line func-name-matching
243
241
  object,
244
242
  prefix,
245
243
  generateArrayPrefix,
@@ -258,11 +256,9 @@ var stringify = function stringify(
258
256
  obj = filter(prefix, obj);
259
257
  } else if (obj instanceof Date) {
260
258
  obj = serializeDate(obj);
261
- }
262
-
263
- if (obj === null) {
259
+ } else if (obj === null) {
264
260
  if (strictNullHandling) {
265
- return encoder && !encodeValuesOnly ? encoder(prefix) : prefix;
261
+ return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix;
266
262
  }
267
263
 
268
264
  obj = '';
@@ -270,8 +266,8 @@ var stringify = function stringify(
270
266
 
271
267
  if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
272
268
  if (encoder) {
273
- var keyValue = encodeValuesOnly ? prefix : encoder(prefix);
274
- return [formatter(keyValue) + '=' + formatter(encoder(obj))];
269
+ var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder);
270
+ return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))];
275
271
  }
276
272
  return [formatter(prefix) + '=' + formatter(String(obj))];
277
273
  }
@@ -283,7 +279,7 @@ var stringify = function stringify(
283
279
  }
284
280
 
285
281
  var objKeys;
286
- if (isArray(filter)) {
282
+ if (Array.isArray(filter)) {
287
283
  objKeys = filter;
288
284
  } else {
289
285
  var keys = Object.keys(obj);
@@ -297,8 +293,8 @@ var stringify = function stringify(
297
293
  continue;
298
294
  }
299
295
 
300
- if (isArray(obj)) {
301
- pushToArray(values, stringify(
296
+ if (Array.isArray(obj)) {
297
+ values = values.concat(stringify(
302
298
  obj[key],
303
299
  generateArrayPrefix(prefix, key),
304
300
  generateArrayPrefix,
@@ -313,7 +309,7 @@ var stringify = function stringify(
313
309
  encodeValuesOnly
314
310
  ));
315
311
  } else {
316
- pushToArray(values, stringify(
312
+ values = values.concat(stringify(
317
313
  obj[key],
318
314
  prefix + (allowDots ? '.' + key : '[' + key + ']'),
319
315
  generateArrayPrefix,
@@ -335,9 +331,9 @@ var stringify = function stringify(
335
331
 
336
332
  module.exports = function (object, opts) {
337
333
  var obj = object;
338
- var options = opts || {};
334
+ var options = opts ? utils.assign({}, opts) : {};
339
335
 
340
- if (options.encoder !== null && typeof options.encoder !== 'undefined' && typeof options.encoder !== 'function') {
336
+ if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
341
337
  throw new TypeError('Encoder has to be a function.');
342
338
  }
343
339
 
@@ -351,7 +347,7 @@ module.exports = function (object, opts) {
351
347
  var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
352
348
  var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
353
349
  if (typeof options.format === 'undefined') {
354
- options.format = formats['default'];
350
+ options.format = formats.default;
355
351
  } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
356
352
  throw new TypeError('Unknown format option provided.');
357
353
  }
@@ -362,7 +358,7 @@ module.exports = function (object, opts) {
362
358
  if (typeof options.filter === 'function') {
363
359
  filter = options.filter;
364
360
  obj = filter('', obj);
365
- } else if (isArray(options.filter)) {
361
+ } else if (Array.isArray(options.filter)) {
366
362
  filter = options.filter;
367
363
  objKeys = filter;
368
364
  }
@@ -398,7 +394,8 @@ module.exports = function (object, opts) {
398
394
  if (skipNulls && obj[key] === null) {
399
395
  continue;
400
396
  }
401
- pushToArray(keys, stringify(
397
+
398
+ keys = keys.concat(stringify(
402
399
  obj[key],
403
400
  key,
404
401
  generateArrayPrefix,
@@ -414,7 +411,10 @@ module.exports = function (object, opts) {
414
411
  ));
415
412
  }
416
413
 
417
- return keys.join(delimiter);
414
+ var joined = keys.join(delimiter);
415
+ var prefix = options.addQueryPrefix === true ? '?' : '';
416
+
417
+ return joined.length > 0 ? prefix + joined : '';
418
418
  };
419
419
 
420
420
  },{"./formats":1,"./utils":5}],5:[function(require,module,exports){
@@ -450,8 +450,8 @@ exports.merge = function (target, source, options) {
450
450
  if (typeof source !== 'object') {
451
451
  if (Array.isArray(target)) {
452
452
  target.push(source);
453
- } else if (target && typeof target === 'object') {
454
- if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
453
+ } else if (typeof target === 'object') {
454
+ if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
455
455
  target[source] = true;
456
456
  }
457
457
  } else {
@@ -461,7 +461,7 @@ exports.merge = function (target, source, options) {
461
461
  return target;
462
462
  }
463
463
 
464
- if (!target || typeof target !== 'object') {
464
+ if (typeof target !== 'object') {
465
465
  return [target].concat(source);
466
466
  }
467
467
 
@@ -488,7 +488,7 @@ exports.merge = function (target, source, options) {
488
488
  return Object.keys(source).reduce(function (acc, key) {
489
489
  var value = source[key];
490
490
 
491
- if (Object.prototype.hasOwnProperty.call(acc, key)) {
491
+ if (has.call(acc, key)) {
492
492
  acc[key] = exports.merge(acc[key], value, options);
493
493
  } else {
494
494
  acc[key] = value;
@@ -497,6 +497,13 @@ exports.merge = function (target, source, options) {
497
497
  }, mergeTarget);
498
498
  };
499
499
 
500
+ exports.assign = function assignSingleSource(target, source) {
501
+ return Object.keys(source).reduce(function (acc, key) {
502
+ acc[key] = source[key];
503
+ return acc;
504
+ }, target);
505
+ };
506
+
500
507
  exports.decode = function (str) {
501
508
  try {
502
509
  return decodeURIComponent(str.replace(/\+/g, ' '));
@@ -519,7 +526,7 @@ exports.encode = function (str) {
519
526
  var c = string.charCodeAt(i);
520
527
 
521
528
  if (
522
- c === 0x2D // -
529
+ c === 0x2D // -
523
530
  || c === 0x2E // .
524
531
  || c === 0x5F // _
525
532
  || c === 0x7E // ~
@@ -548,7 +555,6 @@ exports.encode = function (str) {
548
555
 
549
556
  i += 1;
550
557
  c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
551
- /* eslint operator-linebreak: [2, "before"] */
552
558
  out += hexTable[0xF0 | (c >> 18)]
553
559
  + hexTable[0x80 | ((c >> 12) & 0x3F)]
554
560
  + hexTable[0x80 | ((c >> 6) & 0x3F)]
@@ -606,4 +612,4 @@ exports.isBuffer = function (obj) {
606
612
  };
607
613
 
608
614
  },{}]},{},[2])(2)
609
- });
615
+ });
package/lib/formats.js CHANGED
@@ -10,7 +10,7 @@ module.exports = {
10
10
  return replace.call(value, percentTwenties, '+');
11
11
  },
12
12
  RFC3986: function (value) {
13
- return String(value);
13
+ return value;
14
14
  }
15
15
  },
16
16
  RFC1738: 'RFC1738',
package/lib/parse.js CHANGED
@@ -18,19 +18,23 @@ var defaults = {
18
18
 
19
19
  var parseValues = function parseQueryStringValues(str, options) {
20
20
  var obj = {};
21
- var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
21
+ var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
22
+ var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
23
+ var parts = cleanStr.split(options.delimiter, limit);
22
24
 
23
25
  for (var i = 0; i < parts.length; ++i) {
24
26
  var part = parts[i];
25
- var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
27
+
28
+ var bracketEqualsPos = part.indexOf(']=');
29
+ var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1;
26
30
 
27
31
  var key, val;
28
32
  if (pos === -1) {
29
- key = options.decoder(part);
33
+ key = options.decoder(part, defaults.decoder);
30
34
  val = options.strictNullHandling ? null : '';
31
35
  } else {
32
- key = options.decoder(part.slice(0, pos));
33
- val = options.decoder(part.slice(pos + 1));
36
+ key = options.decoder(part.slice(0, pos), defaults.decoder);
37
+ val = options.decoder(part.slice(pos + 1), defaults.decoder);
34
38
  }
35
39
  if (has.call(obj, key)) {
36
40
  obj[key] = [].concat(obj[key]).concat(val);
@@ -50,16 +54,14 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
50
54
  var root = chain.shift();
51
55
 
52
56
  var obj;
53
- if (root === '[]' && options.parseArrays) {
57
+ if (root === '[]') {
54
58
  obj = [];
55
59
  obj = obj.concat(parseObject(chain, val, options));
56
60
  } else {
57
61
  obj = options.plainObjects ? Object.create(null) : {};
58
62
  var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
59
63
  var index = parseInt(cleanRoot, 10);
60
- if (!options.parseArrays && cleanRoot === '') {
61
- obj = { 0: val };
62
- } else if (
64
+ if (
63
65
  !isNaN(index)
64
66
  && root !== cleanRoot
65
67
  && String(index) === cleanRoot
@@ -68,7 +70,7 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
68
70
  ) {
69
71
  obj = [];
70
72
  obj[index] = parseObject(chain, val, options);
71
- } else if (cleanRoot !== '__proto__') {
73
+ } else {
72
74
  obj[cleanRoot] = parseObject(chain, val, options);
73
75
  }
74
76
  }
@@ -98,7 +100,8 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
98
100
 
99
101
  var keys = [];
100
102
  if (parent) {
101
- // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
103
+ // If we aren't using plain objects, optionally prefix keys
104
+ // that would overwrite object prototype properties
102
105
  if (!options.plainObjects && has.call(Object.prototype, parent)) {
103
106
  if (!options.allowPrototypes) {
104
107
  return;
@@ -131,12 +134,13 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
131
134
  };
132
135
 
133
136
  module.exports = function (str, opts) {
134
- var options = opts || {};
137
+ var options = opts ? utils.assign({}, opts) : {};
135
138
 
136
139
  if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') {
137
140
  throw new TypeError('Decoder has to be a function.');
138
141
  }
139
142
 
143
+ options.ignoreQueryPrefix = options.ignoreQueryPrefix === true;
140
144
  options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter;
141
145
  options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth;
142
146
  options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults.arrayLimit;
package/lib/stringify.js CHANGED
@@ -4,23 +4,17 @@ var utils = require('./utils');
4
4
  var formats = require('./formats');
5
5
 
6
6
  var arrayPrefixGenerators = {
7
- brackets: function brackets(prefix) {
7
+ brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
8
8
  return prefix + '[]';
9
9
  },
10
- indices: function indices(prefix, key) {
10
+ indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
11
11
  return prefix + '[' + key + ']';
12
12
  },
13
- repeat: function repeat(prefix) {
13
+ repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
14
14
  return prefix;
15
15
  }
16
16
  };
17
17
 
18
- var isArray = Array.isArray;
19
- var push = Array.prototype.push;
20
- var pushToArray = function (arr, valueOrArray) {
21
- push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
22
- };
23
-
24
18
  var toISO = Date.prototype.toISOString;
25
19
 
26
20
  var defaults = {
@@ -28,14 +22,14 @@ var defaults = {
28
22
  encode: true,
29
23
  encoder: utils.encode,
30
24
  encodeValuesOnly: false,
31
- serializeDate: function serializeDate(date) {
25
+ serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
32
26
  return toISO.call(date);
33
27
  },
34
28
  skipNulls: false,
35
29
  strictNullHandling: false
36
30
  };
37
31
 
38
- var stringify = function stringify(
32
+ var stringify = function stringify( // eslint-disable-line func-name-matching
39
33
  object,
40
34
  prefix,
41
35
  generateArrayPrefix,
@@ -54,11 +48,9 @@ var stringify = function stringify(
54
48
  obj = filter(prefix, obj);
55
49
  } else if (obj instanceof Date) {
56
50
  obj = serializeDate(obj);
57
- }
58
-
59
- if (obj === null) {
51
+ } else if (obj === null) {
60
52
  if (strictNullHandling) {
61
- return encoder && !encodeValuesOnly ? encoder(prefix) : prefix;
53
+ return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix;
62
54
  }
63
55
 
64
56
  obj = '';
@@ -66,8 +58,8 @@ var stringify = function stringify(
66
58
 
67
59
  if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
68
60
  if (encoder) {
69
- var keyValue = encodeValuesOnly ? prefix : encoder(prefix);
70
- return [formatter(keyValue) + '=' + formatter(encoder(obj))];
61
+ var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder);
62
+ return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))];
71
63
  }
72
64
  return [formatter(prefix) + '=' + formatter(String(obj))];
73
65
  }
@@ -79,7 +71,7 @@ var stringify = function stringify(
79
71
  }
80
72
 
81
73
  var objKeys;
82
- if (isArray(filter)) {
74
+ if (Array.isArray(filter)) {
83
75
  objKeys = filter;
84
76
  } else {
85
77
  var keys = Object.keys(obj);
@@ -93,8 +85,8 @@ var stringify = function stringify(
93
85
  continue;
94
86
  }
95
87
 
96
- if (isArray(obj)) {
97
- pushToArray(values, stringify(
88
+ if (Array.isArray(obj)) {
89
+ values = values.concat(stringify(
98
90
  obj[key],
99
91
  generateArrayPrefix(prefix, key),
100
92
  generateArrayPrefix,
@@ -109,7 +101,7 @@ var stringify = function stringify(
109
101
  encodeValuesOnly
110
102
  ));
111
103
  } else {
112
- pushToArray(values, stringify(
104
+ values = values.concat(stringify(
113
105
  obj[key],
114
106
  prefix + (allowDots ? '.' + key : '[' + key + ']'),
115
107
  generateArrayPrefix,
@@ -131,9 +123,9 @@ var stringify = function stringify(
131
123
 
132
124
  module.exports = function (object, opts) {
133
125
  var obj = object;
134
- var options = opts || {};
126
+ var options = opts ? utils.assign({}, opts) : {};
135
127
 
136
- if (options.encoder !== null && typeof options.encoder !== 'undefined' && typeof options.encoder !== 'function') {
128
+ if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
137
129
  throw new TypeError('Encoder has to be a function.');
138
130
  }
139
131
 
@@ -147,7 +139,7 @@ module.exports = function (object, opts) {
147
139
  var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
148
140
  var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
149
141
  if (typeof options.format === 'undefined') {
150
- options.format = formats['default'];
142
+ options.format = formats.default;
151
143
  } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
152
144
  throw new TypeError('Unknown format option provided.');
153
145
  }
@@ -158,7 +150,7 @@ module.exports = function (object, opts) {
158
150
  if (typeof options.filter === 'function') {
159
151
  filter = options.filter;
160
152
  obj = filter('', obj);
161
- } else if (isArray(options.filter)) {
153
+ } else if (Array.isArray(options.filter)) {
162
154
  filter = options.filter;
163
155
  objKeys = filter;
164
156
  }
@@ -194,7 +186,8 @@ module.exports = function (object, opts) {
194
186
  if (skipNulls && obj[key] === null) {
195
187
  continue;
196
188
  }
197
- pushToArray(keys, stringify(
189
+
190
+ keys = keys.concat(stringify(
198
191
  obj[key],
199
192
  key,
200
193
  generateArrayPrefix,
@@ -210,5 +203,8 @@ module.exports = function (object, opts) {
210
203
  ));
211
204
  }
212
205
 
213
- return keys.join(delimiter);
206
+ var joined = keys.join(delimiter);
207
+ var prefix = options.addQueryPrefix === true ? '?' : '';
208
+
209
+ return joined.length > 0 ? prefix + joined : '';
214
210
  };
package/lib/utils.js CHANGED
@@ -30,8 +30,8 @@ exports.merge = function (target, source, options) {
30
30
  if (typeof source !== 'object') {
31
31
  if (Array.isArray(target)) {
32
32
  target.push(source);
33
- } else if (target && typeof target === 'object') {
34
- if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
33
+ } else if (typeof target === 'object') {
34
+ if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
35
35
  target[source] = true;
36
36
  }
37
37
  } else {
@@ -41,7 +41,7 @@ exports.merge = function (target, source, options) {
41
41
  return target;
42
42
  }
43
43
 
44
- if (!target || typeof target !== 'object') {
44
+ if (typeof target !== 'object') {
45
45
  return [target].concat(source);
46
46
  }
47
47
 
@@ -68,7 +68,7 @@ exports.merge = function (target, source, options) {
68
68
  return Object.keys(source).reduce(function (acc, key) {
69
69
  var value = source[key];
70
70
 
71
- if (Object.prototype.hasOwnProperty.call(acc, key)) {
71
+ if (has.call(acc, key)) {
72
72
  acc[key] = exports.merge(acc[key], value, options);
73
73
  } else {
74
74
  acc[key] = value;
@@ -77,6 +77,13 @@ exports.merge = function (target, source, options) {
77
77
  }, mergeTarget);
78
78
  };
79
79
 
80
+ exports.assign = function assignSingleSource(target, source) {
81
+ return Object.keys(source).reduce(function (acc, key) {
82
+ acc[key] = source[key];
83
+ return acc;
84
+ }, target);
85
+ };
86
+
80
87
  exports.decode = function (str) {
81
88
  try {
82
89
  return decodeURIComponent(str.replace(/\+/g, ' '));
@@ -99,7 +106,7 @@ exports.encode = function (str) {
99
106
  var c = string.charCodeAt(i);
100
107
 
101
108
  if (
102
- c === 0x2D // -
109
+ c === 0x2D // -
103
110
  || c === 0x2E // .
104
111
  || c === 0x5F // _
105
112
  || c === 0x7E // ~
@@ -128,7 +135,6 @@ exports.encode = function (str) {
128
135
 
129
136
  i += 1;
130
137
  c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
131
- /* eslint operator-linebreak: [2, "before"] */
132
138
  out += hexTable[0xF0 | (c >> 18)]
133
139
  + hexTable[0x80 | ((c >> 12) & 0x3F)]
134
140
  + hexTable[0x80 | ((c >> 6) & 0x3F)]
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.4.1",
5
+ "version": "6.5.0",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/ljharb/qs.git"
@@ -22,32 +22,29 @@
22
22
  "engines": {
23
23
  "node": ">=0.6"
24
24
  },
25
+ "dependencies": {},
25
26
  "devDependencies": {
26
- "@ljharb/eslint-config": "^20.1.0",
27
- "aud": "^1.1.5",
28
- "browserify": "^16.5.2",
29
- "eclint": "^2.8.1",
30
- "eslint": "^8.6.0",
27
+ "@ljharb/eslint-config": "^11.0.0",
28
+ "browserify": "^14.4.0",
29
+ "covert": "^1.1.0",
30
+ "editorconfig-tools": "^0.1.1",
31
+ "eslint": "^3.19.0",
31
32
  "evalmd": "^0.0.17",
32
- "iconv-lite": "^0.4.24",
33
- "in-publish": "^2.0.1",
33
+ "iconv-lite": "^0.4.18",
34
34
  "mkdirp": "^0.5.1",
35
- "nyc": "^10.3.2",
36
35
  "qs-iconv": "^1.0.4",
37
- "safe-publish-latest": "^2.0.0",
38
- "safer-buffer": "^2.1.2",
39
- "tape": "^5.4.0"
36
+ "safe-publish-latest": "^1.1.1",
37
+ "tape": "^4.7.0"
40
38
  },
41
39
  "scripts": {
42
- "prepublishOnly": "safe-publish-latest && npm run dist",
43
- "prepublish": "not-in-publish || npm run prepublishOnly",
40
+ "prepublish": "safe-publish-latest && npm run dist",
44
41
  "pretest": "npm run --silent readme && npm run --silent lint",
45
- "test": "npm run --silent tests-only",
46
- "tests-only": "nyc tape 'test/**/*.js'",
47
- "posttest": "aud --production",
42
+ "test": "npm run --silent coverage",
43
+ "tests-only": "node test",
48
44
  "readme": "evalmd README.md",
49
- "postlint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
50
- "lint": "eslint --ext=js,mjs .",
45
+ "prelint": "editorconfig-tools check * lib/* test/*",
46
+ "lint": "eslint lib/*.js test/*.js",
47
+ "coverage": "covert test",
51
48
  "dist": "mkdirp dist && browserify --standalone Qs lib/index.js > dist/qs.js"
52
49
  },
53
50
  "license": "BSD-3-Clause"
package/test/.eslintrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "rules": {
3
+ "consistent-return": 2,
4
+ "max-lines": 0,
5
+ "max-nested-callbacks": [2, 3],
6
+ "max-statements": 0,
7
+ "no-extend-native": 0,
8
+ "no-magic-numbers": 0,
9
+ "sort-keys": 0
10
+ }
11
+ }