updated npm modules
This commit is contained in:
336
node_modules/qs/dist/qs.js
generated
vendored
336
node_modules/qs/dist/qs.js
generated
vendored
@@ -42,21 +42,63 @@ var defaults = {
|
||||
allowDots: false,
|
||||
allowPrototypes: false,
|
||||
arrayLimit: 20,
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: false,
|
||||
comma: false,
|
||||
decoder: utils.decode,
|
||||
delimiter: '&',
|
||||
depth: 5,
|
||||
ignoreQueryPrefix: false,
|
||||
interpretNumericEntities: false,
|
||||
parameterLimit: 1000,
|
||||
parseArrays: true,
|
||||
plainObjects: false,
|
||||
strictNullHandling: false
|
||||
};
|
||||
|
||||
var interpretNumericEntities = function (str) {
|
||||
return str.replace(/&#(\d+);/g, function ($0, numberStr) {
|
||||
return String.fromCharCode(parseInt(numberStr, 10));
|
||||
});
|
||||
};
|
||||
|
||||
// This is what browsers will submit when the ✓ character occurs in an
|
||||
// application/x-www-form-urlencoded body and the encoding of the page containing
|
||||
// the form is iso-8859-1, or when the submitted form has an accept-charset
|
||||
// attribute of iso-8859-1. Presumably also with other charsets that do not contain
|
||||
// the ✓ character, such as us-ascii.
|
||||
var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓')
|
||||
|
||||
// These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded.
|
||||
var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓')
|
||||
|
||||
var parseValues = function parseQueryStringValues(str, options) {
|
||||
var obj = {};
|
||||
var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
|
||||
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
|
||||
var parts = cleanStr.split(options.delimiter, limit);
|
||||
var skipIndex = -1; // Keep track of where the utf8 sentinel was found
|
||||
var i;
|
||||
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
var charset = options.charset;
|
||||
if (options.charsetSentinel) {
|
||||
for (i = 0; i < parts.length; ++i) {
|
||||
if (parts[i].indexOf('utf8=') === 0) {
|
||||
if (parts[i] === charsetSentinel) {
|
||||
charset = 'utf-8';
|
||||
} else if (parts[i] === isoSentinel) {
|
||||
charset = 'iso-8859-1';
|
||||
}
|
||||
skipIndex = i;
|
||||
i = parts.length; // The eslint settings do not allow break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < parts.length; ++i) {
|
||||
if (i === skipIndex) {
|
||||
continue;
|
||||
}
|
||||
var part = parts[i];
|
||||
|
||||
var bracketEqualsPos = part.indexOf(']=');
|
||||
@@ -64,14 +106,23 @@ var parseValues = function parseQueryStringValues(str, options) {
|
||||
|
||||
var key, val;
|
||||
if (pos === -1) {
|
||||
key = options.decoder(part, defaults.decoder);
|
||||
key = options.decoder(part, defaults.decoder, charset);
|
||||
val = options.strictNullHandling ? null : '';
|
||||
} else {
|
||||
key = options.decoder(part.slice(0, pos), defaults.decoder);
|
||||
val = options.decoder(part.slice(pos + 1), defaults.decoder);
|
||||
key = options.decoder(part.slice(0, pos), defaults.decoder, charset);
|
||||
val = options.decoder(part.slice(pos + 1), defaults.decoder, charset);
|
||||
}
|
||||
|
||||
if (val && options.interpretNumericEntities && charset === 'iso-8859-1') {
|
||||
val = interpretNumericEntities(val);
|
||||
}
|
||||
|
||||
if (val && options.comma && val.indexOf(',') > -1) {
|
||||
val = val.split(',');
|
||||
}
|
||||
|
||||
if (has.call(obj, key)) {
|
||||
obj[key] = [].concat(obj[key]).concat(val);
|
||||
obj[key] = utils.combine(obj[key], val);
|
||||
} else {
|
||||
obj[key] = val;
|
||||
}
|
||||
@@ -87,14 +138,15 @@ var parseObject = function (chain, val, options) {
|
||||
var obj;
|
||||
var root = chain[i];
|
||||
|
||||
if (root === '[]') {
|
||||
obj = [];
|
||||
obj = obj.concat(leaf);
|
||||
if (root === '[]' && options.parseArrays) {
|
||||
obj = [].concat(leaf);
|
||||
} else {
|
||||
obj = options.plainObjects ? Object.create(null) : {};
|
||||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
|
||||
var index = parseInt(cleanRoot, 10);
|
||||
if (
|
||||
if (!options.parseArrays && cleanRoot === '') {
|
||||
obj = { 0: leaf };
|
||||
} else if (
|
||||
!isNaN(index)
|
||||
&& root !== cleanRoot
|
||||
&& String(index) === cleanRoot
|
||||
@@ -136,8 +188,7 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
||||
|
||||
var keys = [];
|
||||
if (parent) {
|
||||
// If we aren't using plain objects, optionally prefix keys
|
||||
// that would overwrite object prototype properties
|
||||
// If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties
|
||||
if (!options.plainObjects && has.call(Object.prototype, parent)) {
|
||||
if (!options.allowPrototypes) {
|
||||
return;
|
||||
@@ -169,24 +220,41 @@ var parseKeys = function parseQueryStringKeys(givenKey, val, options) {
|
||||
return parseObject(keys, val, options);
|
||||
};
|
||||
|
||||
module.exports = function (str, opts) {
|
||||
var options = opts ? utils.assign({}, opts) : {};
|
||||
var normalizeParseOptions = function normalizeParseOptions(opts) {
|
||||
if (!opts) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
if (options.decoder !== null && options.decoder !== undefined && typeof options.decoder !== 'function') {
|
||||
if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') {
|
||||
throw new TypeError('Decoder has to be a function.');
|
||||
}
|
||||
|
||||
options.ignoreQueryPrefix = options.ignoreQueryPrefix === true;
|
||||
options.delimiter = typeof options.delimiter === 'string' || utils.isRegExp(options.delimiter) ? options.delimiter : defaults.delimiter;
|
||||
options.depth = typeof options.depth === 'number' ? options.depth : defaults.depth;
|
||||
options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : defaults.arrayLimit;
|
||||
options.parseArrays = options.parseArrays !== false;
|
||||
options.decoder = typeof options.decoder === 'function' ? options.decoder : defaults.decoder;
|
||||
options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : defaults.allowDots;
|
||||
options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : defaults.plainObjects;
|
||||
options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : defaults.allowPrototypes;
|
||||
options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : defaults.parameterLimit;
|
||||
options.strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
|
||||
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
||||
throw new Error('The charset option must be either utf-8, iso-8859-1, or undefined');
|
||||
}
|
||||
var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset;
|
||||
|
||||
return {
|
||||
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
||||
allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes,
|
||||
arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit,
|
||||
charset: charset,
|
||||
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
||||
comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma,
|
||||
decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder,
|
||||
delimiter: typeof opts.delimiter === 'string' || utils.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter,
|
||||
depth: typeof opts.depth === 'number' ? opts.depth : defaults.depth,
|
||||
ignoreQueryPrefix: opts.ignoreQueryPrefix === true,
|
||||
interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities,
|
||||
parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit,
|
||||
parseArrays: opts.parseArrays !== false,
|
||||
plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects,
|
||||
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = function (str, opts) {
|
||||
var options = normalizeParseOptions(opts);
|
||||
|
||||
if (str === '' || str === null || typeof str === 'undefined') {
|
||||
return options.plainObjects ? Object.create(null) : {};
|
||||
@@ -212,11 +280,13 @@ module.exports = function (str, opts) {
|
||||
|
||||
var utils = require('./utils');
|
||||
var formats = require('./formats');
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
|
||||
var arrayPrefixGenerators = {
|
||||
brackets: function brackets(prefix) { // eslint-disable-line func-name-matching
|
||||
return prefix + '[]';
|
||||
},
|
||||
comma: 'comma',
|
||||
indices: function indices(prefix, key) { // eslint-disable-line func-name-matching
|
||||
return prefix + '[' + key + ']';
|
||||
},
|
||||
@@ -225,13 +295,26 @@ var arrayPrefixGenerators = {
|
||||
}
|
||||
};
|
||||
|
||||
var isArray = Array.isArray;
|
||||
var push = Array.prototype.push;
|
||||
var pushToArray = function (arr, valueOrArray) {
|
||||
push.apply(arr, isArray(valueOrArray) ? valueOrArray : [valueOrArray]);
|
||||
};
|
||||
|
||||
var toISO = Date.prototype.toISOString;
|
||||
|
||||
var defaults = {
|
||||
addQueryPrefix: false,
|
||||
allowDots: false,
|
||||
charset: 'utf-8',
|
||||
charsetSentinel: false,
|
||||
delimiter: '&',
|
||||
encode: true,
|
||||
encoder: utils.encode,
|
||||
encodeValuesOnly: false,
|
||||
formatter: formats.formatters[formats['default']],
|
||||
// deprecated
|
||||
indices: false,
|
||||
serializeDate: function serializeDate(date) { // eslint-disable-line func-name-matching
|
||||
return toISO.call(date);
|
||||
},
|
||||
@@ -251,16 +334,21 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
allowDots,
|
||||
serializeDate,
|
||||
formatter,
|
||||
encodeValuesOnly
|
||||
encodeValuesOnly,
|
||||
charset
|
||||
) {
|
||||
var obj = object;
|
||||
if (typeof filter === 'function') {
|
||||
obj = filter(prefix, obj);
|
||||
} else if (obj instanceof Date) {
|
||||
obj = serializeDate(obj);
|
||||
} else if (obj === null) {
|
||||
} else if (generateArrayPrefix === 'comma' && isArray(obj)) {
|
||||
obj = obj.join(',');
|
||||
}
|
||||
|
||||
if (obj === null) {
|
||||
if (strictNullHandling) {
|
||||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder) : prefix;
|
||||
return encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset) : prefix;
|
||||
}
|
||||
|
||||
obj = '';
|
||||
@@ -268,8 +356,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
|
||||
if (typeof obj === 'string' || typeof obj === 'number' || typeof obj === 'boolean' || utils.isBuffer(obj)) {
|
||||
if (encoder) {
|
||||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder);
|
||||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder))];
|
||||
var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults.encoder, charset);
|
||||
return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults.encoder, charset))];
|
||||
}
|
||||
return [formatter(prefix) + '=' + formatter(String(obj))];
|
||||
}
|
||||
@@ -281,7 +369,7 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
}
|
||||
|
||||
var objKeys;
|
||||
if (Array.isArray(filter)) {
|
||||
if (isArray(filter)) {
|
||||
objKeys = filter;
|
||||
} else {
|
||||
var keys = Object.keys(obj);
|
||||
@@ -295,10 +383,10 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
values = values.concat(stringify(
|
||||
if (isArray(obj)) {
|
||||
pushToArray(values, stringify(
|
||||
obj[key],
|
||||
generateArrayPrefix(prefix, key),
|
||||
typeof generateArrayPrefix === 'function' ? generateArrayPrefix(prefix, key) : prefix,
|
||||
generateArrayPrefix,
|
||||
strictNullHandling,
|
||||
skipNulls,
|
||||
@@ -308,10 +396,11 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
allowDots,
|
||||
serializeDate,
|
||||
formatter,
|
||||
encodeValuesOnly
|
||||
encodeValuesOnly,
|
||||
charset
|
||||
));
|
||||
} else {
|
||||
values = values.concat(stringify(
|
||||
pushToArray(values, stringify(
|
||||
obj[key],
|
||||
prefix + (allowDots ? '.' + key : '[' + key + ']'),
|
||||
generateArrayPrefix,
|
||||
@@ -323,7 +412,8 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
allowDots,
|
||||
serializeDate,
|
||||
formatter,
|
||||
encodeValuesOnly
|
||||
encodeValuesOnly,
|
||||
charset
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -331,36 +421,63 @@ var stringify = function stringify( // eslint-disable-line func-name-matching
|
||||
return values;
|
||||
};
|
||||
|
||||
module.exports = function (object, opts) {
|
||||
var obj = object;
|
||||
var options = opts ? utils.assign({}, opts) : {};
|
||||
var normalizeStringifyOptions = function normalizeStringifyOptions(opts) {
|
||||
if (!opts) {
|
||||
return defaults;
|
||||
}
|
||||
|
||||
if (options.encoder !== null && options.encoder !== undefined && typeof options.encoder !== 'function') {
|
||||
if (opts.encoder !== null && opts.encoder !== undefined && typeof opts.encoder !== 'function') {
|
||||
throw new TypeError('Encoder has to be a function.');
|
||||
}
|
||||
|
||||
var delimiter = typeof options.delimiter === 'undefined' ? defaults.delimiter : options.delimiter;
|
||||
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : defaults.strictNullHandling;
|
||||
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : defaults.skipNulls;
|
||||
var encode = typeof options.encode === 'boolean' ? options.encode : defaults.encode;
|
||||
var encoder = typeof options.encoder === 'function' ? options.encoder : defaults.encoder;
|
||||
var sort = typeof options.sort === 'function' ? options.sort : null;
|
||||
var allowDots = typeof options.allowDots === 'undefined' ? false : options.allowDots;
|
||||
var serializeDate = typeof options.serializeDate === 'function' ? options.serializeDate : defaults.serializeDate;
|
||||
var encodeValuesOnly = typeof options.encodeValuesOnly === 'boolean' ? options.encodeValuesOnly : defaults.encodeValuesOnly;
|
||||
if (typeof options.format === 'undefined') {
|
||||
options.format = formats['default'];
|
||||
} else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) {
|
||||
throw new TypeError('Unknown format option provided.');
|
||||
var charset = opts.charset || defaults.charset;
|
||||
if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
|
||||
throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
|
||||
}
|
||||
var formatter = formats.formatters[options.format];
|
||||
|
||||
var format = formats['default'];
|
||||
if (typeof opts.format !== 'undefined') {
|
||||
if (!has.call(formats.formatters, opts.format)) {
|
||||
throw new TypeError('Unknown format option provided.');
|
||||
}
|
||||
format = opts.format;
|
||||
}
|
||||
var formatter = formats.formatters[format];
|
||||
|
||||
var filter = defaults.filter;
|
||||
if (typeof opts.filter === 'function' || isArray(opts.filter)) {
|
||||
filter = opts.filter;
|
||||
}
|
||||
|
||||
return {
|
||||
addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
|
||||
allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots,
|
||||
charset: charset,
|
||||
charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel,
|
||||
delimiter: typeof opts.delimiter === 'undefined' ? defaults.delimiter : opts.delimiter,
|
||||
encode: typeof opts.encode === 'boolean' ? opts.encode : defaults.encode,
|
||||
encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults.encoder,
|
||||
encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults.encodeValuesOnly,
|
||||
filter: filter,
|
||||
formatter: formatter,
|
||||
serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults.serializeDate,
|
||||
skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults.skipNulls,
|
||||
sort: typeof opts.sort === 'function' ? opts.sort : null,
|
||||
strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = function (object, opts) {
|
||||
var obj = object;
|
||||
var options = normalizeStringifyOptions(opts);
|
||||
|
||||
var objKeys;
|
||||
var filter;
|
||||
|
||||
if (typeof options.filter === 'function') {
|
||||
filter = options.filter;
|
||||
obj = filter('', obj);
|
||||
} else if (Array.isArray(options.filter)) {
|
||||
} else if (isArray(options.filter)) {
|
||||
filter = options.filter;
|
||||
objKeys = filter;
|
||||
}
|
||||
@@ -372,10 +489,10 @@ module.exports = function (object, opts) {
|
||||
}
|
||||
|
||||
var arrayFormat;
|
||||
if (options.arrayFormat in arrayPrefixGenerators) {
|
||||
arrayFormat = options.arrayFormat;
|
||||
} else if ('indices' in options) {
|
||||
arrayFormat = options.indices ? 'indices' : 'repeat';
|
||||
if (opts && opts.arrayFormat in arrayPrefixGenerators) {
|
||||
arrayFormat = opts.arrayFormat;
|
||||
} else if (opts && 'indices' in opts) {
|
||||
arrayFormat = opts.indices ? 'indices' : 'repeat';
|
||||
} else {
|
||||
arrayFormat = 'indices';
|
||||
}
|
||||
@@ -386,36 +503,46 @@ module.exports = function (object, opts) {
|
||||
objKeys = Object.keys(obj);
|
||||
}
|
||||
|
||||
if (sort) {
|
||||
objKeys.sort(sort);
|
||||
if (options.sort) {
|
||||
objKeys.sort(options.sort);
|
||||
}
|
||||
|
||||
for (var i = 0; i < objKeys.length; ++i) {
|
||||
var key = objKeys[i];
|
||||
|
||||
if (skipNulls && obj[key] === null) {
|
||||
if (options.skipNulls && obj[key] === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
keys = keys.concat(stringify(
|
||||
pushToArray(keys, stringify(
|
||||
obj[key],
|
||||
key,
|
||||
generateArrayPrefix,
|
||||
strictNullHandling,
|
||||
skipNulls,
|
||||
encode ? encoder : null,
|
||||
filter,
|
||||
sort,
|
||||
allowDots,
|
||||
serializeDate,
|
||||
formatter,
|
||||
encodeValuesOnly
|
||||
options.strictNullHandling,
|
||||
options.skipNulls,
|
||||
options.encode ? options.encoder : null,
|
||||
options.filter,
|
||||
options.sort,
|
||||
options.allowDots,
|
||||
options.serializeDate,
|
||||
options.formatter,
|
||||
options.encodeValuesOnly,
|
||||
options.charset
|
||||
));
|
||||
}
|
||||
|
||||
var joined = keys.join(delimiter);
|
||||
var joined = keys.join(options.delimiter);
|
||||
var prefix = options.addQueryPrefix === true ? '?' : '';
|
||||
|
||||
if (options.charsetSentinel) {
|
||||
if (options.charset === 'iso-8859-1') {
|
||||
// encodeURIComponent('✓'), the "numeric entity" representation of a checkmark
|
||||
prefix += 'utf8=%26%2310003%3B&';
|
||||
} else {
|
||||
// encodeURIComponent('✓')
|
||||
prefix += 'utf8=%E2%9C%93&';
|
||||
}
|
||||
}
|
||||
|
||||
return joined.length > 0 ? prefix + joined : '';
|
||||
};
|
||||
|
||||
@@ -423,6 +550,7 @@ module.exports = function (object, opts) {
|
||||
'use strict';
|
||||
|
||||
var has = Object.prototype.hasOwnProperty;
|
||||
var isArray = Array.isArray;
|
||||
|
||||
var hexTable = (function () {
|
||||
var array = [];
|
||||
@@ -434,13 +562,11 @@ var hexTable = (function () {
|
||||
}());
|
||||
|
||||
var compactQueue = function compactQueue(queue) {
|
||||
var obj;
|
||||
|
||||
while (queue.length) {
|
||||
while (queue.length > 1) {
|
||||
var item = queue.pop();
|
||||
obj = item.obj[item.prop];
|
||||
var obj = item.obj[item.prop];
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
if (isArray(obj)) {
|
||||
var compacted = [];
|
||||
|
||||
for (var j = 0; j < obj.length; ++j) {
|
||||
@@ -452,8 +578,6 @@ var compactQueue = function compactQueue(queue) {
|
||||
item.obj[item.prop] = compacted;
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
var arrayToObject = function arrayToObject(source, options) {
|
||||
@@ -473,10 +597,10 @@ var merge = function merge(target, source, options) {
|
||||
}
|
||||
|
||||
if (typeof source !== 'object') {
|
||||
if (Array.isArray(target)) {
|
||||
if (isArray(target)) {
|
||||
target.push(source);
|
||||
} else if (typeof target === 'object') {
|
||||
if (options.plainObjects || options.allowPrototypes || !has.call(Object.prototype, source)) {
|
||||
} else if (target && typeof target === 'object') {
|
||||
if ((options && (options.plainObjects || options.allowPrototypes)) || !has.call(Object.prototype, source)) {
|
||||
target[source] = true;
|
||||
}
|
||||
} else {
|
||||
@@ -486,20 +610,21 @@ var merge = function merge(target, source, options) {
|
||||
return target;
|
||||
}
|
||||
|
||||
if (typeof target !== 'object') {
|
||||
if (!target || typeof target !== 'object') {
|
||||
return [target].concat(source);
|
||||
}
|
||||
|
||||
var mergeTarget = target;
|
||||
if (Array.isArray(target) && !Array.isArray(source)) {
|
||||
if (isArray(target) && !isArray(source)) {
|
||||
mergeTarget = arrayToObject(target, options);
|
||||
}
|
||||
|
||||
if (Array.isArray(target) && Array.isArray(source)) {
|
||||
if (isArray(target) && isArray(source)) {
|
||||
source.forEach(function (item, i) {
|
||||
if (has.call(target, i)) {
|
||||
if (target[i] && typeof target[i] === 'object') {
|
||||
target[i] = merge(target[i], item, options);
|
||||
var targetItem = target[i];
|
||||
if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') {
|
||||
target[i] = merge(targetItem, item, options);
|
||||
} else {
|
||||
target.push(item);
|
||||
}
|
||||
@@ -529,15 +654,21 @@ var assign = function assignSingleSource(target, source) {
|
||||
}, target);
|
||||
};
|
||||
|
||||
var decode = function (str) {
|
||||
var decode = function (str, decoder, charset) {
|
||||
var strWithoutPlus = str.replace(/\+/g, ' ');
|
||||
if (charset === 'iso-8859-1') {
|
||||
// unescape never throws, no try...catch needed:
|
||||
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
|
||||
}
|
||||
// utf-8
|
||||
try {
|
||||
return decodeURIComponent(str.replace(/\+/g, ' '));
|
||||
return decodeURIComponent(strWithoutPlus);
|
||||
} catch (e) {
|
||||
return str;
|
||||
return strWithoutPlus;
|
||||
}
|
||||
};
|
||||
|
||||
var encode = function encode(str) {
|
||||
var encode = function encode(str, defaultEncoder, charset) {
|
||||
// This code was originally written by Brian White (mscdex) for the io.js core querystring library.
|
||||
// It has been adapted here for stricter adherence to RFC 3986
|
||||
if (str.length === 0) {
|
||||
@@ -546,6 +677,12 @@ var encode = function encode(str) {
|
||||
|
||||
var string = typeof str === 'string' ? str : String(str);
|
||||
|
||||
if (charset === 'iso-8859-1') {
|
||||
return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) {
|
||||
return '%26%23' + parseInt($0.slice(2), 16) + '%3B';
|
||||
});
|
||||
}
|
||||
|
||||
var out = '';
|
||||
for (var i = 0; i < string.length; ++i) {
|
||||
var c = string.charCodeAt(i);
|
||||
@@ -608,7 +745,9 @@ var compact = function compact(value) {
|
||||
}
|
||||
}
|
||||
|
||||
return compactQueue(queue);
|
||||
compactQueue(queue);
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
var isRegExp = function isRegExp(obj) {
|
||||
@@ -616,16 +755,21 @@ var isRegExp = function isRegExp(obj) {
|
||||
};
|
||||
|
||||
var isBuffer = function isBuffer(obj) {
|
||||
if (obj === null || typeof obj === 'undefined') {
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj));
|
||||
};
|
||||
|
||||
var combine = function combine(a, b) {
|
||||
return [].concat(a, b);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
arrayToObject: arrayToObject,
|
||||
assign: assign,
|
||||
combine: combine,
|
||||
compact: compact,
|
||||
decode: decode,
|
||||
encode: encode,
|
||||
|
||||
Reference in New Issue
Block a user