Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/utils

Package Overview
Dependencies
Maintainers
4
Versions
1288
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/utils - npm Package Compare versions

Comparing version 10.6.1 to 10.6.2-alpha-20241204120043-4eb970a1e7fffafa2a0eca8ececaf956c6282876

84

cjs/mergeDeep.js

@@ -6,27 +6,39 @@ "use strict";

function mergeDeep(sources, respectPrototype = false, respectArrays = false, respectArrayLength = false) {
if (respectArrays && respectArrayLength) {
let expectedLength;
const areArraysInTheSameLength = sources.every(source => {
if (Array.isArray(source)) {
if (expectedLength === undefined) {
expectedLength = source.length;
return true;
}
else if (expectedLength === source.length) {
return true;
}
let expectedLength;
let allArrays = true;
const areArraysInTheSameLength = sources.every(source => {
if (Array.isArray(source)) {
if (expectedLength === undefined) {
expectedLength = source.length;
return true;
}
return false;
});
if (areArraysInTheSameLength) {
return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength));
else if (expectedLength === source.length) {
return true;
}
}
else {
allArrays = false;
}
return false;
});
if (respectArrayLength && areArraysInTheSameLength) {
return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength));
}
const output = {};
if (allArrays) {
return sources.flat(1);
}
let output;
let firstObjectSource;
if (respectPrototype) {
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(sources[0])));
firstObjectSource = sources.find(source => isObject(source));
if (output == null) {
output = {};
}
if (firstObjectSource) {
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(firstObjectSource)));
}
}
for (const source of sources) {
if (isObject(source)) {
if (respectPrototype) {
if (firstObjectSource) {
const outputPrototype = Object.getPrototypeOf(output);

@@ -44,28 +56,24 @@ const sourcePrototype = Object.getPrototypeOf(source);

for (const key in source) {
if (isObject(source[key])) {
if (!(key in output)) {
Object.assign(output, { [key]: source[key] });
}
else {
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength);
}
if (output == null) {
output = {};
}
else if (respectArrays && Array.isArray(output[key])) {
if (Array.isArray(source[key])) {
if (respectArrayLength && output[key].length === source[key].length) {
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength);
}
else {
output[key].push(...source[key]);
}
}
else {
output[key].push(source[key]);
}
if (key in output) {
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength);
}
else {
Object.assign(output, { [key]: source[key] });
output[key] = source[key];
}
}
}
else if (Array.isArray(source)) {
if (!Array.isArray(output)) {
output = source;
}
else {
output = mergeDeep([output, source], respectPrototype, respectArrays, respectArrayLength);
}
}
else {
output = source;
}
}

@@ -72,0 +80,0 @@ return output;

import { isSome } from './helpers.js';
export function mergeDeep(sources, respectPrototype = false, respectArrays = false, respectArrayLength = false) {
if (respectArrays && respectArrayLength) {
let expectedLength;
const areArraysInTheSameLength = sources.every(source => {
if (Array.isArray(source)) {
if (expectedLength === undefined) {
expectedLength = source.length;
return true;
}
else if (expectedLength === source.length) {
return true;
}
let expectedLength;
let allArrays = true;
const areArraysInTheSameLength = sources.every(source => {
if (Array.isArray(source)) {
if (expectedLength === undefined) {
expectedLength = source.length;
return true;
}
return false;
});
if (areArraysInTheSameLength) {
return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength));
else if (expectedLength === source.length) {
return true;
}
}
else {
allArrays = false;
}
return false;
});
if (respectArrayLength && areArraysInTheSameLength) {
return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength));
}
const output = {};
if (allArrays) {
return sources.flat(1);
}
let output;
let firstObjectSource;
if (respectPrototype) {
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(sources[0])));
firstObjectSource = sources.find(source => isObject(source));
if (output == null) {
output = {};
}
if (firstObjectSource) {
Object.setPrototypeOf(output, Object.create(Object.getPrototypeOf(firstObjectSource)));
}
}
for (const source of sources) {
if (isObject(source)) {
if (respectPrototype) {
if (firstObjectSource) {
const outputPrototype = Object.getPrototypeOf(output);

@@ -40,28 +52,24 @@ const sourcePrototype = Object.getPrototypeOf(source);

for (const key in source) {
if (isObject(source[key])) {
if (!(key in output)) {
Object.assign(output, { [key]: source[key] });
}
else {
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength);
}
if (output == null) {
output = {};
}
else if (respectArrays && Array.isArray(output[key])) {
if (Array.isArray(source[key])) {
if (respectArrayLength && output[key].length === source[key].length) {
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength);
}
else {
output[key].push(...source[key]);
}
}
else {
output[key].push(source[key]);
}
if (key in output) {
output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength);
}
else {
Object.assign(output, { [key]: source[key] });
output[key] = source[key];
}
}
}
else if (Array.isArray(source)) {
if (!Array.isArray(output)) {
output = source;
}
else {
output = mergeDeep([output, source], respectPrototype, respectArrays, respectArrayLength);
}
}
else {
output = source;
}
}

@@ -68,0 +76,0 @@ return output;

{
"name": "@graphql-tools/utils",
"version": "10.6.1",
"version": "10.6.2-alpha-20241204120043-4eb970a1e7fffafa2a0eca8ececaf956c6282876",
"description": "Common package containing utils and types for GraphQL tools",

@@ -5,0 +5,0 @@ "sideEffects": false,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc