Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const targetValue = target[key];
if (targetValue instanceof URLSearchParams && sourceValue instanceof URLSearchParams) {
const params = new URLSearchParams();
const append = (value: string, key: string): void => params.append(key, value);
targetValue.forEach(append);
sourceValue.forEach(append);
// @ts-ignore https://github.com/microsoft/TypeScript/issues/31661
target[key] = params;
} else if (is.urlInstance(targetValue) && (is.urlInstance(sourceValue) || is.string(sourceValue))) {
// @ts-ignore
target[key] = new URL(sourceValue as string, targetValue);
} else if (is.plainObject(sourceValue)) {
if (is.plainObject(targetValue)) {
// @ts-ignore
target[key] = merge({}, targetValue, sourceValue);
} else {
// @ts-ignore
target[key] = merge({}, sourceValue);
}
} else if (is.array(sourceValue)) {
// @ts-ignore
target[key] = sourceValue.slice();
} else {
// @ts-ignore
target[key] = sourceValue;
}
}
}
export default function merge(target: Target, ...sources: Source[]): Merge {
for (const source of sources) {
for (const [key, sourceValue] of Object.entries(source)) {
const targetValue = target[key];
if (is.urlInstance(targetValue) && is.string(sourceValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = new URL(sourceValue, targetValue);
} else if (is.plainObject(sourceValue)) {
if (is.plainObject(targetValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = merge({}, targetValue, sourceValue);
} else {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = merge({}, sourceValue);
}
} else if (is.array(sourceValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = sourceValue.slice();
} else {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = sourceValue;
}
}
}
const targetValue = target[key];
if (targetValue instanceof URLSearchParams && sourceValue instanceof URLSearchParams) {
const params = new URLSearchParams();
const append = (value: string, key: string): void => params.append(key, value);
targetValue.forEach(append);
sourceValue.forEach(append);
// @ts-ignore https://github.com/microsoft/TypeScript/issues/31661
target[key] = params;
} else if (is.urlInstance(targetValue) && (is.urlInstance(sourceValue) || is.string(sourceValue))) {
// @ts-ignore
target[key] = new URL(sourceValue as string, targetValue);
} else if (is.plainObject(sourceValue)) {
if (is.plainObject(targetValue)) {
// @ts-ignore
target[key] = merge({}, targetValue, sourceValue);
} else {
// @ts-ignore
target[key] = merge({}, sourceValue);
}
} else if (is.array(sourceValue)) {
// @ts-ignore
target[key] = sourceValue.slice();
} else {
// @ts-ignore
target[key] = sourceValue;
}
}
}
export default function merge(target: Target, ...sources: Source[]): Merge {
for (const source of sources) {
for (const [key, sourceValue] of Object.entries(source)) {
const targetValue = target[key];
if (is.urlInstance(targetValue) && is.string(sourceValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = new URL(sourceValue, targetValue);
} else if (is.plainObject(sourceValue)) {
if (is.plainObject(targetValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = merge({}, targetValue, sourceValue);
} else {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = merge({}, sourceValue);
}
} else if (is.array(sourceValue)) {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = sourceValue.slice();
} else {
// @ts-ignore TS doesn't recognise Target accepts string keys
target[key] = sourceValue;
}
}
}
test('properties', wrapper, async (t, server) => {
const request = makeRequest(server.url);
request.end();
const response = await pEvent(request, 'response');
response.resume();
t.true(is.plainObject(response.headers));
t.true(is.array(response.rawHeaders));
t.true(is.plainObject(response.trailers));
t.true(is.array(response.rawTrailers));
t.is(request.socket, request.connection);
t.is(response.socket, request.socket);
t.is(response.connection, request.socket);
t.truthy(response.req);
t.is(response.httpVersion, '2.0');
t.is(response.httpVersionMajor, 2);
t.is(response.httpVersionMinor, 0);
t.true(is.number(response.statusCode));
t.is(response.statusMessage, '');
});
test('properties', wrapper, async (t, server) => {
const request = makeRequest(server.url);
request.end();
const response = await pEvent(request, 'response');
response.resume();
t.true(is.plainObject(response.headers));
t.true(is.array(response.rawHeaders));
t.true(is.plainObject(response.trailers));
t.true(is.array(response.rawTrailers));
t.is(request.socket, request.connection);
t.is(response.socket, request.socket);
t.is(response.connection, request.socket);
t.truthy(response.req);
t.is(response.httpVersion, '2.0');
t.is(response.httpVersionMajor, 2);
t.is(response.httpVersionMinor, 0);
t.true(is.number(response.statusCode));
t.is(response.statusMessage, '');
});
const { errors, arrayOfObjects, everythingElse } = groupBy(args, (arg: unknown) =>
is.error(arg) ? 'errors' : is.plainObject(arg) ? 'arrayOfObjects' : 'everythingElse'
);
validator: object => is.plainObject(object)
});
const normalize = (url, options, defaults) => {
if (is.plainObject(url)) {
options = {...url, ...options};
url = options.url || {};
delete options.url;
}
if (defaults) {
options = merge({}, defaults.options, options ? preNormalize(options, defaults.options) : {});
} else {
options = merge({}, preNormalize(options));
}
if (!is.string(url) && !is.object(url)) {
throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
}
if (is.string(url)) {