import { daffMerge } from '@daffodil/core'
Merges dictionaries with a specific strategy for handling collisions.
function daffMerge<T extends Record<string, unknown> = Record<string, unknown>>(
dicts: T[]
strategy: DaffMergeStrategy<T> = {}
): T
| Parameter | dicts: T[] |
|---|---|
| Description |
| Parameter | strategy: DaffMergeStrategy<T> |
|---|---|
| Default | {} |
| Description |
const a = {
ary: [1, 2],
obj: {foo: 5, bar: 10}
}
const a = {
ary: [3, 4],
obj: {foo: 6},
fish: 'tacos'
}
const result = daffMerge(
[a, b],
{
ary: daffArrayConcatMerger,
obj: daffDictAssignMerger
}
)
the value of result would be:
{
ary: [1, 2, 3, 4],
obj: {foo: 6, bar: 10},
fish: 'tacos'
}
const a = {
ary: [1, 2],
obj: {foo: 5, bar: 10}
}
const a = {
ary: [3, 4],
obj: {foo: 6},
fish: 'tacos'
}
const result = daffMerge(
[a, b],
{
ary: daffArrayConcatMerger,
obj: daffDictAssignMerger
}
)
the value of result would be:
{
ary: [1, 2, 3, 4],
obj: {foo: 6, bar: 10},
fish: 'tacos'
}
const a = {
ary: [1, 2],
obj: {foo: 5, bar: 10}
}
const a = {
ary: [3, 4],
obj: {foo: 6},
fish: 'tacos'
}
const result = daffMerge(
[a, b],
{
ary: daffArrayConcatMerger,
obj: daffDictAssignMerger
}
)
the value of result would be:
{
ary: [1, 2, 3, 4],
obj: {foo: 6, bar: 10},
fish: 'tacos'
}
const a = {
ary: [1, 2],
obj: {foo: 5, bar: 10}
}
const a = {
ary: [3, 4],
obj: {foo: 6},
fish: 'tacos'
}
const result = daffMerge(
[a, b],
{
ary: daffArrayConcatMerger,
obj: daffDictAssignMerger
}
)
the value of result would be:
{
ary: [1, 2, 3, 4],
obj: {foo: 6, bar: 10},
fish: 'tacos'
}