summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/qs/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/qs/lib/utils.js')
-rwxr-xr-xdeps/npm/node_modules/request/node_modules/qs/lib/utils.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/deps/npm/node_modules/request/node_modules/qs/lib/utils.js b/deps/npm/node_modules/request/node_modules/qs/lib/utils.js
index 2c5c8ee503..33c01c000d 100755
--- a/deps/npm/node_modules/request/node_modules/qs/lib/utils.js
+++ b/deps/npm/node_modules/request/node_modules/qs/lib/utils.js
@@ -1,16 +1,18 @@
'use strict';
+var has = Object.prototype.hasOwnProperty;
+
var hexTable = (function () {
- var array = new Array(256);
+ var array = [];
for (var i = 0; i < 256; ++i) {
- array[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase();
+ array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase());
}
return array;
}());
exports.arrayToObject = function (source, options) {
- var obj = options.plainObjects ? Object.create(null) : {};
+ var obj = options && options.plainObjects ? Object.create(null) : {};
for (var i = 0; i < source.length; ++i) {
if (typeof source[i] !== 'undefined') {
obj[i] = source[i];
@@ -46,6 +48,21 @@ exports.merge = function (target, source, options) {
mergeTarget = exports.arrayToObject(target, options);
}
+ if (Array.isArray(target) && Array.isArray(source)) {
+ source.forEach(function (item, i) {
+ if (has.call(target, i)) {
+ if (target[i] && typeof target[i] === 'object') {
+ target[i] = exports.merge(target[i], item, options);
+ } else {
+ target.push(item);
+ }
+ } else {
+ target[i] = item;
+ }
+ });
+ return target;
+ }
+
return Object.keys(source).reduce(function (acc, key) {
var value = source[key];
@@ -143,10 +160,9 @@ exports.compact = function (obj, references) {
}
var keys = Object.keys(obj);
- for (var j = 0; j < keys.length; ++j) {
- var key = keys[j];
+ keys.forEach(function (key) {
obj[key] = exports.compact(obj[key], refs);
- }
+ });
return obj;
};