Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (opts.json && is.undefined(opts.headers.accept)) {
opts.headers.accept = 'application/json';
}
const body = opts.body;
if (is.nullOrUndefined(body)) {
opts.method = (opts.method || 'GET').toUpperCase();
} else {
const headers = opts.headers;
if (!is.nodeStream(body) && !is.string(body) && !is.buffer(body) && !(opts.form || opts.json)) {
throw new TypeError('The `body` option must be a stream.Readable, string, Buffer or plain Object');
}
const canBodyBeStringified = is.plainObject(body) || is.array(body);
if ((opts.form || opts.json) && !canBodyBeStringified) {
throw new TypeError('The `body` option must be a plain Object or Array when the `form` or `json` option is used');
}
if (isFormData(body)) {
// Special case for https://github.com/form-data/form-data
headers['content-type'] = headers['content-type'] || `multipart/form-data; boundary=${body.getBoundary()}`;
} else if (opts.form && canBodyBeStringified) {
headers['content-type'] = headers['content-type'] || 'application/x-www-form-urlencoded';
opts.body = querystring.stringify(body);
} else if (opts.json && canBodyBeStringified) {
headers['content-type'] = headers['content-type'] || 'application/json';
opts.body = JSON.stringify(body);
}
if (is.undefined(headers['content-length']) && is.undefined(headers['transfer-encoding']) && !is.nodeStream(body)) {
}
if (opts.json && is.undefined(opts.headers.accept)) {
opts.headers.accept = 'application/json';
}
const body = opts.body;
if (is.nullOrUndefined(body)) {
opts.method = (opts.method || 'GET').toUpperCase();
} else {
const headers = opts.headers;
if (!is.nodeStream(body) && !is.string(body) && !is.buffer(body) && !(opts.form || opts.json)) {
throw new TypeError('The `body` option must be a stream.Readable, string, Buffer or plain Object');
}
const canBodyBeStringified = is.plainObject(body) || is.array(body);
if ((opts.form || opts.json) && !canBodyBeStringified) {
throw new TypeError('The `body` option must be a plain Object or Array when the `form` or `json` option is used');
}
if (isFormData(body)) {
// Special case for https://github.com/form-data/form-data
headers['content-type'] = headers['content-type'] || `multipart/form-data; boundary=${body.getBoundary()}`;
} else if (opts.form && canBodyBeStringified) {
headers['content-type'] = headers['content-type'] || 'application/x-www-form-urlencoded';
opts.body = querystring.stringify(body);
} else if (opts.json && canBodyBeStringified) {
headers['content-type'] = headers['content-type'] || 'application/json';
opts.body = JSON.stringify(body);
}
if (is.undefined(headers['content-length']) && is.undefined(headers['transfer-encoding']) && !is.nodeStream(body)) {
}
if (options.decompress && is.undefined(headers['accept-encoding'])) {
headers['accept-encoding'] = 'gzip, deflate';
}
const {body} = options;
if (is.nullOrUndefined(body)) {
options.method = options.method ? options.method.toUpperCase() : 'GET';
} else {
const isObject = is.object(body) && !is.buffer(body) && !is.nodeStream(body);
if (!is.nodeStream(body) && !is.string(body) && !is.buffer(body) && !(options.form || options.json)) {
throw new TypeError('The `body` option must be a stream.Readable, string or Buffer');
}
if (options.json && !(isObject || is.array(body))) {
throw new TypeError('The `body` option must be an Object or Array when the `json` option is used');
}
if (options.form && !isObject) {
throw new TypeError('The `body` option must be an Object when the `form` option is used');
}
if (isFormData(body)) {
// Special case for https://github.com/form-data/form-data
headers['content-type'] = headers['content-type'] || `multipart/form-data; boundary=${body.getBoundary()}`;
} else if (options.form) {
headers['content-type'] = headers['content-type'] || 'application/x-www-form-urlencoded';
options.body = (new URLSearchParams(body)).toString();
} else if (options.json) {
headers['content-type'] = headers['content-type'] || 'application/json';
options.body = JSON.stringify(body);
module.exports = function deepFreeze(object) {
for (const [key, value] of Object.entries(object)) {
if (is.plainObject(value) || is.array(value)) {
deepFreeze(object[key]);
}
}
return Object.freeze(object);
};
const pathToPipeline = (path) => is.array(path)
? pathPipelineSetAlts(path)
: [path]
export default function deepFreeze(object: T): Readonly {
for (const value of Object.values(object)) {
if (is.plainObject(value) || is.array(value)) {
deepFreeze(value);
}
}
return Object.freeze(object);
}
const normalizeFieldMapping = (transformers = {}, switchTransforms = false) => (def) => (is.string(def) || is.array(def))
? pathToPipeline(def)
: createFieldPipeline(def, transformers, switchTransforms)