↩︎

assign

Recursive assign for objects, arrays and more

const assign = require('@recursive/assign');

assign({hash: {a: 1}}, {hash: {b: 2, c: 0}}, {hash: {c: 3}}) // {hash: {a: 1, b:2, c: 3}}

I will merge:

Array

assign(
    {array: [1, 2, 3]},
    {array: [3, 4]}
)
// {array: [3, 4, 3]}

Array of assignable members

assign(
    [{firstName: 'Omri'}, {firstName: 'Tom'}],
    [{lastName: 'Lotan'}, {lastName: 'Ben Amitai'}]
)
// [{firstName: 'Omri', lastName: 'Lotan'}, {firstName: 'Tom', lastName: 'Ben Amitai'}]

Set

assign(
    {set: new Set([1, 2])},
    {set: new Set([2, 3])}
);
// {set: [1, 2, 3]}

Map

assign(
    {map: new Map([[1, 2], [3, 4]])}
    {map: new Map([[1, 3], [4, 5]])}
);
// {map: [[1, 3], [3, 4], [4, 5]]}

Transpiled version

Environments which exclude node_modules from the transpiling pipeline should include the "browser" entry instead of "main". This exposes an ES5 commonjs module.

Also available for explicit import:

const assign = require('@recursive/assign/dist');