@recursive/assign
v3.0.1
Published
๐ Recursive assign for objects, arrays and more
Downloads
23,498
Maintainers
Readme
@recursive/assign
๐ Recursive assign for objects, arrays and more
import { assign } from "@recursive/assign";
assign({ hash: { a: 1 } }, { hash: { b: 2, c: 0 } }, { hash: { c: 3 } }); // {hash: {a: 1, b:2, c: 3}}
I will merge:
- โ objects
- โ arrays
- โ functions
- โ sets
- โ maps
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]]}