Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@corex/deepmerge
Advanced tools
A zero dependency object merger with typescript support and built in common merge utilities.
A zero dependency object merger with typescript support and built in common merge utilities. Support merging of n number of objects
yarn add @corex/deepmerge
import { merge } from '@corex/deepmerge'
merge([obj1, obj2, obj3], { options })
property | default | description |
---|---|---|
arrayMergeType | combine | Merge two array by concatenation and remove duplicates. Available options are combine , overwrite |
arrayMerge | - | Custom merge function to handle array merging. |
const obj1 = {
a: 1,
b: {
c: 2,
},
}
const obj2 = {
a: 2,
b: {
c: 4,
d: 5,
},
}
const result = merge([obj1, obj2])
console.log(result)
// {
// a: 2,
// b: {
// c: 4,
// d: 5,
// },
// }
const arr1 = {
a: [1, 2, 3],
}
const arr2 = {
a: [3, 4, 5],
}
const result = merge([arr1, arr2])
console.log(result)
// result = {
// a: [1, 2, 3, 4, 5],
// }
const obj1 = {
a: 2,
b: (x: number, y: number) => x + y,
c: [1, 2, 4],
d: {
e: [4, 5, 7],
},
}
console.log(obj1.b(7, 5)) // ==> 12
const obj2 = {
a: 10,
b: (x: number, y: number) => x / y,
c: [20, 30],
d: {
e: [4, 7, 5],
f: {
g: 'another',
},
},
}
const obj3 = {
b: (x: number, y: number) => x * y,
c: [1, 2, 4],
d: {
e: [4, 7, 5],
},
}
const result = merge([obj1, obj2, obj3])
console.log(result.b(7, 5)) // ==> 35
By default @corex/deepmerge
uses combine merge. However user can implement their own methods to perform merge or use the built in overwrite
.
const obj1 = {
a: [1, 2, 3],
b: ['c', 'd'],
c: {
d: [1, 2],
},
}
const obj2 = {
a: [1, 7, 6],
b: ['e', 'f'],
c: {
d: [9, 10],
},
}
const obj3 = {
a: [20, 40],
}
const result = merge([obj1, obj2, obj3], {
arrayMergeType: 'overwrite',
})
console.log(result)
// result = {
// a: [20, 40],
// b: ['e', 'f'],
// c: {
// d: [9, 10],
// },
// }
const obj1 = {
a: ['1', '2'],
c: {
d: [1000, 500],
},
}
const obj2 = {
a: ['4', '5'],
c: {
d: [60, 80],
},
}
const customMergeFn = (_: any[], __: any[]) => 42
const result = merge([obj1, obj2], {
arrayMerge: customMergeFn,
})
console.log(result)
// {
// a: 42,
// c: {
// d: 42,
// },
// }
FAQs
A zero dependency object merger with typescript support and built in common merge utilities.
The npm package @corex/deepmerge receives a total of 0 weekly downloads. As such, @corex/deepmerge popularity was classified as not popular.
We found that @corex/deepmerge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.