qs 6.3.1 → 6.4.1

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 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){
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;
@@ -11,7 +11,7 @@ module.exports = {
11
11
  return replace.call(value, percentTwenties, '+');
12
12
  },
13
13
  RFC3986: function (value) {
14
- return value;
14
+ return String(value);
15
15
  }
16
16
  },
17
17
  RFC1738: 'RFC1738',
@@ -84,23 +84,25 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
84
84
  var root = chain.shift();
85
85
 
86
86
  var obj;
87
- if (root === '[]') {
87
+ if (root === '[]' && options.parseArrays) {
88
88
  obj = [];
89
89
  obj = obj.concat(parseObject(chain, val, options));
90
90
  } else {
91
91
  obj = options.plainObjects ? Object.create(null) : {};
92
92
  var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
93
93
  var index = parseInt(cleanRoot, 10);
94
- if (
95
- !isNaN(index) &&
96
- root !== cleanRoot &&
97
- String(index) === cleanRoot &&
98
- index >= 0 &&
99
- (options.parseArrays && index <= options.arrayLimit)
94
+ if (!options.parseArrays && cleanRoot === '') {
95
+ obj = { 0: val };
96
+ } else if (
97
+ !isNaN(index)
98
+ && root !== cleanRoot
99
+ && String(index) === cleanRoot
100
+ && index >= 0
101
+ && (options.parseArrays && index <= options.arrayLimit)
100
102
  ) {
101
103
  obj = [];
102
104
  obj[index] = parseObject(chain, val, options);
103
- } else {
105
+ } else if (cleanRoot !== '__proto__') {
104
106
  obj[cleanRoot] = parseObject(chain, val, options);
105
107
  }
106
108
  }
@@ -118,26 +120,26 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
118
120
 
119
121
  // The regex chunks
120
122
 
121
- var parent = /^([^[]*)/;
123
+ var brackets = /(\[[^[\]]*])/;
122
124
  var child = /(\[[^[\]]*])/g;
123
125
 
124
126
  // Get the parent
125
127
 
126
- var segment = parent.exec(key);
128
+ var segment = brackets.exec(key);
129
+ var parent = segment ? key.slice(0, segment.index) : key;
127
130
 
128
131
  // Stash the parent if it exists
129
132
 
130
133
  var keys = [];
131
- if (segment[1]) {
132
- // If we aren't using plain objects, optionally prefix keys
133
- // that would overwrite object prototype properties
134
- if (!options.plainObjects && has.call(Object.prototype, segment[1])) {
134
+ if (parent) {
135
+ // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
136
+ if (!options.plainObjects && has.call(Object.prototype, parent)) {
135
137
  if (!options.allowPrototypes) {
136
138
  return;
137
139
  }
138
140
  }
139
141
 
140
- keys.push(segment[1]);
142
+ keys.push(parent);
141
143
  }
142
144
 
143
145
  // Loop through children appending to the array until we hit depth
@@ -206,31 +208,38 @@ var utils = require('./utils');
206
208
  var formats = require('./formats');
207
209
 
208
210
  var arrayPrefixGenerators = {
209
- brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
211
+ brackets: function brackets(prefix) {
210
212
  return prefix + '[]';
211
213
  },
212
- indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
214
+ indices: function indices(prefix, key) {
213
215
  return prefix + '[' + key + ']';
214
216
  },
215
- repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
217
+ repeat: function repeat(prefix) {
216
218
  return prefix;
217
219
  }
218
220
  };
219
221
 
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
+
220
228
  var toISO = Date.prototype.toISOString;
221
229
 
222
230
  var defaults = {
223
231
  delimiter: '&',
224
232
  encode: true,
225
233
  encoder: utils.encode,
226
- serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
234
+ encodeValuesOnly: false,
235
+ serializeDate: function serializeDate(date) {
227
236
  return toISO.call(date);
228
237
  },
229
238
  skipNulls: false,
230
239
  strictNullHandling: false
231
240
  };
232
241
 
233
- var stringify = function stringify( // eslint-disable-line func-name-matching
242
+ var stringify = function stringify(
234
243
  object,
235
244
  prefix,
236
245
  generateArrayPrefix,
@@ -241,16 +250,19 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
241
250
  sort,
242
251
  allowDots,
243
252
  serializeDate,
244
- formatter
253
+ formatter,
254
+ encodeValuesOnly
245
255
  ) {
246
256
  var obj = object;
247
257
  if (typeof filter === 'function') {
248
258
  obj = filter(prefix, obj);
249
259
  } else if (obj instanceof Date) {
250
260
  obj = serializeDate(obj);
251
- } else if (obj === null) {
261
+ }
262
+
263
+ if (obj === null) {
252
264
  if (strictNullHandling) {
253
- return encoder ? encoder(prefix) : prefix;
265
+ return encoder && !encodeValuesOnly ? encoder(prefix) : prefix;
254
266
  }
255
267
 
256
268
  obj = '';
@@ -258,7 +270,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
258
270
 
259
271
  if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
260
272
  if (encoder) {
261
- return [formatter(encoder(prefix)) + '=' + formatter(encoder(obj))];
273
+ var keyValue = encodeValuesOnly ? prefix : encoder(prefix);
274
+ return [formatter(keyValue) + '=' + formatter(encoder(obj))];
262
275
  }
263
276
  return [formatter(prefix) + '=' + formatter(String(obj))];
264
277
  }
@@ -270,7 +283,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
270
283
  }
271
284
 
272
285
  var objKeys;
273
- if (Array.isArray(filter)) {
286
+ if (isArray(filter)) {
274
287
  objKeys = filter;
275
288
  } else {
276
289
  var keys = Object.keys(obj);
@@ -284,8 +297,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
284
297
  continue;
285
298
  }
286
299
 
287
- if (Array.isArray(obj)) {
288
- values = values.concat(stringify(
300
+ if (isArray(obj)) {
301
+ pushToArray(values, stringify(
289
302
  obj[key],
290
303
  generateArrayPrefix(prefix, key),
291
304
  generateArrayPrefix,
@@ -296,10 +309,11 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
296
309
  sort,
297
310
  allowDots,
298
311
  serializeDate,
299
- formatter
312
+ formatter,
313
+ encodeValuesOnly
300
314
  ));
301
315
  } else {
302
- values = values.concat(stringify(
316
+ pushToArray(values, stringify(
303
317
  obj[key],
304
318
  prefix + (allowDots ? '.' + key : '[' + key + ']'),
305
319
  generateArrayPrefix,
@@ -310,7 +324,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
310
324
  sort,
311
325
  allowDots,
312
326
  serializeDate,
313
- formatter
327
+ formatter,
328
+ encodeValuesOnly
314
329
  ));
315
330
  }
316
331
  }
@@ -322,7 +337,7 @@ module.exports = function (object, opts) {
322
337
  var obj = object;
323
338
  var options = opts || {};
324
339
 
325
- if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
340
+ if (options.encoder !== null && typeof options.encoder !== 'undefined' && typeof options.encoder !== 'function') {
326
341
  throw new TypeError('Encoder has to be a function.');
327
342
  }
328
343
 
@@ -330,12 +345,13 @@ module.exports = function (object, opts) {
330
345
  var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
331
346
  var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
332
347
  var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
333
- var encoder = encode ? (typeof options.encoder === 'function' ? options.encoder : defaults.encoder) : null;
348
+ var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder;
334
349
  var sort = typeof options.sort === 'function' ? options.sort : null;
335
350
  var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots;
336
351
  var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
352
+ var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
337
353
  if (typeof options.format === 'undefined') {
338
- options.format = formats.default;
354
+ options.format = formats['default'];
339
355
  } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
340
356
  throw new TypeError('Unknown format option provided.');
341
357
  }
@@ -346,7 +362,7 @@ module.exports = function (object, opts) {
346
362
  if (typeof options.filter === 'function') {
347
363
  filter = options.filter;
348
364
  obj = filter('', obj);
349
- } else if (Array.isArray(options.filter)) {
365
+ } else if (isArray(options.filter)) {
350
366
  filter = options.filter;
351
367
  objKeys = filter;
352
368
  }
@@ -382,19 +398,19 @@ module.exports = function (object, opts) {
382
398
  if (skipNulls && obj[key] === null) {
383
399
  continue;
384
400
  }
385
-
386
- keys = keys.concat(stringify(
401
+ pushToArray(keys, stringify(
387
402
  obj[key],
388
403
  key,
389
404
  generateArrayPrefix,
390
405
  strictNullHandling,
391
406
  skipNulls,
392
- encoder,
407
+ encode ? encoder : null,
393
408
  filter,
394
409
  sort,
395
410
  allowDots,
396
411
  serializeDate,
397
- formatter
412
+ formatter,
413
+ encodeValuesOnly
398
414
  ));
399
415
  }
400
416
 
@@ -434,8 +450,10 @@ exports.merge = function (target, source, options) {
434
450
  if (typeof source !== 'object') {
435
451
  if (Array.isArray(target)) {
436
452
  target.push(source);
437
- } else if (typeof target === 'object') {
438
- target[source] = true;
453
+ } else if (target && typeof target === 'object') {
454
+ if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
455
+ target[source] = true;
456
+ }
439
457
  } else {
440
458
  return [target, source];
441
459
  }
@@ -443,7 +461,7 @@ exports.merge = function (target, source, options) {
443
461
  return target;
444
462
  }
445
463
 
446
- if (typeof target !== 'object') {
464
+ if (!target || typeof target !== 'object') {
447
465
  return [target].concat(source);
448
466
  }
449
467
 
@@ -501,13 +519,13 @@ exports.encode = function (str) {
501
519
  var c = string.charCodeAt(i);
502
520
 
503
521
  if (
504
- c === 0x2D || // -
505
- c === 0x2E || // .
506
- c === 0x5F || // _
507
- c === 0x7E || // ~
508
- (c >= 0x30 && c <= 0x39) || // 0-9
509
- (c >= 0x41 && c <= 0x5A) || // a-z
510
- (c >= 0x61 && c <= 0x7A) // A-Z
522
+ c === 0x2D // -
523
+ || c === 0x2E // .
524
+ || c === 0x5F // _
525
+ || c === 0x7E // ~
526
+ || (c >= 0x30 && c <= 0x39) // 0-9
527
+ || (c >= 0x41 && c <= 0x5A) // a-z
528
+ || (c >= 0x61 && c <= 0x7A) // A-Z
511
529
  ) {
512
530
  out += string.charAt(i);
513
531
  continue;
@@ -530,7 +548,11 @@ exports.encode = function (str) {
530
548
 
531
549
  i += 1;
532
550
  c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
533
- out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
551
+ /* eslint operator-linebreak: [2, "before"] */
552
+ out += hexTable[0xF0 | (c >> 18)]
553
+ + hexTable[0x80 | ((c >> 12) & 0x3F)]
554
+ + hexTable[0x80 | ((c >> 6) & 0x3F)]
555
+ + hexTable[0x80 | (c & 0x3F)];
534
556
  }
535
557
 
536
558
  return out;
@@ -584,4 +606,4 @@ exports.isBuffer = function (obj) {
584
606
  };
585
607
 
586
608
  },{}]},{},[2])(2)
587
- });
609
+ });
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 value;
13
+ return String(value);
14
14
  }
15
15
  },
16
16
  RFC1738: 'RFC1738',
package/lib/index.js CHANGED
File without changes
package/lib/parse.js CHANGED
@@ -50,23 +50,25 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
50
50
  var root = chain.shift();
51
51
 
52
52
  var obj;
53
- if (root === '[]') {
53
+ if (root === '[]' && options.parseArrays) {
54
54
  obj = [];
55
55
  obj = obj.concat(parseObject(chain, val, options));
56
56
  } else {
57
57
  obj = options.plainObjects ? Object.create(null) : {};
58
58
  var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
59
59
  var index = parseInt(cleanRoot, 10);
60
- if (
61
- !isNaN(index) &&
62
- root !== cleanRoot &&
63
- String(index) === cleanRoot &&
64
- index >= 0 &&
65
- (options.parseArrays && index <= options.arrayLimit)
60
+ if (!options.parseArrays && cleanRoot === '') {
61
+ obj = { 0: val };
62
+ } else if (
63
+ !isNaN(index)
64
+ && root !== cleanRoot
65
+ && String(index) === cleanRoot
66
+ && index >= 0
67
+ && (options.parseArrays && index <= options.arrayLimit)
66
68
  ) {
67
69
  obj = [];
68
70
  obj[index] = parseObject(chain, val, options);
69
- } else {
71
+ } else if (cleanRoot !== '__proto__') {
70
72
  obj[cleanRoot] = parseObject(chain, val, options);
71
73
  }
72
74
  }
@@ -84,26 +86,26 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
84
86
 
85
87
  // The regex chunks
86
88
 
87
- var parent = /^([^[]*)/;
89
+ var brackets = /(\[[^[\]]*])/;
88
90
  var child = /(\[[^[\]]*])/g;
89
91
 
90
92
  // Get the parent
91
93
 
92
- var segment = parent.exec(key);
94
+ var segment = brackets.exec(key);
95
+ var parent = segment ? key.slice(0, segment.index) : key;
93
96
 
94
97
  // Stash the parent if it exists
95
98
 
96
99
  var keys = [];
97
- if (segment[1]) {
98
- // If we aren't using plain objects, optionally prefix keys
99
- // that would overwrite object prototype properties
100
- if (!options.plainObjects && has.call(Object.prototype, segment[1])) {
100
+ if (parent) {
101
+ // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
102
+ if (!options.plainObjects && has.call(Object.prototype, parent)) {
101
103
  if (!options.allowPrototypes) {
102
104
  return;
103
105
  }
104
106
  }
105
107
 
106
- keys.push(segment[1]);
108
+ keys.push(parent);
107
109
  }
108
110
 
109
111
  // Loop through children appending to the array until we hit depth
package/lib/stringify.js CHANGED
@@ -4,31 +4,38 @@ var utils = require('./utils');
4
4
  var formats = require('./formats');
5
5
 
6
6
  var arrayPrefixGenerators = {
7
- brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
7
+ brackets: function brackets(prefix) {
8
8
  return prefix + '[]';
9
9
  },
10
- indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
10
+ indices: function indices(prefix, key) {
11
11
  return prefix + '[' + key + ']';
12
12
  },
13
- repeat: function repeat(prefix) { // eslint-disable-line func-name-matching
13
+ repeat: function repeat(prefix) {
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
+
18
24
  var toISO = Date.prototype.toISOString;
19
25
 
20
26
  var defaults = {
21
27
  delimiter: '&',
22
28
  encode: true,
23
29
  encoder: utils.encode,
24
- serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
30
+ encodeValuesOnly: false,
31
+ serializeDate: function serializeDate(date) {
25
32
  return toISO.call(date);
26
33
  },
27
34
  skipNulls: false,
28
35
  strictNullHandling: false
29
36
  };
30
37
 
31
- var stringify = function stringify( // eslint-disable-line func-name-matching
38
+ var stringify = function stringify(
32
39
  object,
33
40
  prefix,
34
41
  generateArrayPrefix,
@@ -39,16 +46,19 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
39
46
  sort,
40
47
  allowDots,
41
48
  serializeDate,
42
- formatter
49
+ formatter,
50
+ encodeValuesOnly
43
51
  ) {
44
52
  var obj = object;
45
53
  if (typeof filter === 'function') {
46
54
  obj = filter(prefix, obj);
47
55
  } else if (obj instanceof Date) {
48
56
  obj = serializeDate(obj);
49
- } else if (obj === null) {
57
+ }
58
+
59
+ if (obj === null) {
50
60
  if (strictNullHandling) {
51
- return encoder ? encoder(prefix) : prefix;
61
+ return encoder && !encodeValuesOnly ? encoder(prefix) : prefix;
52
62
  }
53
63
 
54
64
  obj = '';
@@ -56,7 +66,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
56
66
 
57
67
  if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
58
68
  if (encoder) {
59
- return [formatter(encoder(prefix)) + '=' + formatter(encoder(obj))];
69
+ var keyValue = encodeValuesOnly ? prefix : encoder(prefix);
70
+ return [formatter(keyValue) + '=' + formatter(encoder(obj))];
60
71
  }
61
72
  return [formatter(prefix) + '=' + formatter(String(obj))];
62
73
  }
@@ -68,7 +79,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
68
79
  }
69
80
 
70
81
  var objKeys;
71
- if (Array.isArray(filter)) {
82
+ if (isArray(filter)) {
72
83
  objKeys = filter;
73
84
  } else {
74
85
  var keys = Object.keys(obj);
@@ -82,8 +93,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
82
93
  continue;
83
94
  }
84
95
 
85
- if (Array.isArray(obj)) {
86
- values = values.concat(stringify(
96
+ if (isArray(obj)) {
97
+ pushToArray(values, stringify(
87
98
  obj[key],
88
99
  generateArrayPrefix(prefix, key),
89
100
  generateArrayPrefix,
@@ -94,10 +105,11 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
94
105
  sort,
95
106
  allowDots,
96
107
  serializeDate,
97
- formatter
108
+ formatter,
109
+ encodeValuesOnly
98
110
  ));
99
111
  } else {
100
- values = values.concat(stringify(
112
+ pushToArray(values, stringify(
101
113
  obj[key],
102
114
  prefix + (allowDots ? '.' + key : '[' + key + ']'),
103
115
  generateArrayPrefix,
@@ -108,7 +120,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
108
120
  sort,
109
121
  allowDots,
110
122
  serializeDate,
111
- formatter
123
+ formatter,
124
+ encodeValuesOnly
112
125
  ));
113
126
  }
114
127
  }
@@ -120,7 +133,7 @@ module.exports = function (object, opts) {
120
133
  var obj = object;
121
134
  var options = opts || {};
122
135
 
123
- if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
136
+ if (options.encoder !== null && typeof options.encoder !== 'undefined' && typeof options.encoder !== 'function') {
124
137
  throw new TypeError('Encoder has to be a function.');
125
138
  }
126
139
 
@@ -128,12 +141,13 @@ module.exports = function (object, opts) {
128
141
  var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
129
142
  var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
130
143
  var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
131
- var encoder = encode ? (typeof options.encoder === 'function' ? options.encoder : defaults.encoder) : null;
144
+ var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder;
132
145
  var sort = typeof options.sort === 'function' ? options.sort : null;
133
146
  var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots;
134
147
  var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
148
+ var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
135
149
  if (typeof options.format === 'undefined') {
136
- options.format = formats.default;
150
+ options.format = formats['default'];
137
151
  } else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
138
152
  throw new TypeError('Unknown format option provided.');
139
153
  }
@@ -144,7 +158,7 @@ module.exports = function (object, opts) {
144
158
  if (typeof options.filter === 'function') {
145
159
  filter = options.filter;
146
160
  obj = filter('', obj);
147
- } else if (Array.isArray(options.filter)) {
161
+ } else if (isArray(options.filter)) {
148
162
  filter = options.filter;
149
163
  objKeys = filter;
150
164
  }
@@ -180,19 +194,19 @@ module.exports = function (object, opts) {
180
194
  if (skipNulls && obj[key] === null) {
181
195
  continue;
182
196
  }
183
-
184
- keys = keys.concat(stringify(
197
+ pushToArray(keys, stringify(
185
198
  obj[key],
186
199
  key,
187
200
  generateArrayPrefix,
188
201
  strictNullHandling,
189
202
  skipNulls,
190
- encoder,
203
+ encode ? encoder : null,
191
204
  filter,
192
205
  sort,
193
206
  allowDots,
194
207
  serializeDate,
195
- formatter
208
+ formatter,
209
+ encodeValuesOnly
196
210
  ));
197
211
  }
198
212
 
package/lib/utils.js CHANGED
@@ -30,8 +30,10 @@ 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 (typeof target === 'object') {
34
- target[source] = true;
33
+ } else if (target && typeof target === 'object') {
34
+ if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
35
+ target[source] = true;
36
+ }
35
37
  } else {
36
38
  return [target, source];
37
39
  }
@@ -39,7 +41,7 @@ exports.merge = function (target, source, options) {
39
41
  return target;
40
42
  }
41
43
 
42
- if (typeof target !== 'object') {
44
+ if (!target || typeof target !== 'object') {
43
45
  return [target].concat(source);
44
46
  }
45
47
 
@@ -97,13 +99,13 @@ exports.encode = function (str) {
97
99
  var c = string.charCodeAt(i);
98
100
 
99
101
  if (
100
- c === 0x2D || // -
101
- c === 0x2E || // .
102
- c === 0x5F || // _
103
- c === 0x7E || // ~
104
- (c >= 0x30 && c <= 0x39) || // 0-9
105
- (c >= 0x41 && c <= 0x5A) || // a-z
106
- (c >= 0x61 && c <= 0x7A) // A-Z
102
+ c === 0x2D // -
103
+ || c === 0x2E // .
104
+ || c === 0x5F // _
105
+ || c === 0x7E // ~
106
+ || (c >= 0x30 && c <= 0x39) // 0-9
107
+ || (c >= 0x41 && c <= 0x5A) // a-z
108
+ || (c >= 0x61 && c <= 0x7A) // A-Z
107
109
  ) {
108
110
  out += string.charAt(i);
109
111
  continue;
@@ -126,7 +128,11 @@ exports.encode = function (str) {
126
128
 
127
129
  i += 1;
128
130
  c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
129
- out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
131
+ /* eslint operator-linebreak: [2, "before"] */
132
+ out += hexTable[0xF0 | (c >> 18)]
133
+ + hexTable[0x80 | ((c >> 12) & 0x3F)]
134
+ + hexTable[0x80 | ((c >> 6) & 0x3F)]
135
+ + hexTable[0x80 | (c & 0x3F)];
130
136
  }
131
137
 
132
138
  return out;