1.0.0-beta.9 • Published 5 years ago
@helcor/merge-collections v1.0.0-beta.9

@helcor/merge-collections
Merge two arrays of objects by identifier.
API
mergeCollections(array1, array2, options)
Array array1- Source collection.Array array2- Collection to merge.Object options- Options. (Optional)string id- The identifier. Default:'id'. (Optional)boolean shallow- Shallow extend. Default:false. (Optional)
- Returns
Array- A new collection with the merged items.
Example
import mergeCollections from '@helcor/merge-collections';
const col1 = [
{ myId: 'x1', v: 'a' },
{ myId: 'x2', v: 'b' },
{ myId: 'x3', v: 'c' }
];
const col2 = [
{ myId: 'x1', v: 'x' },
{ myId: 'x2', v: 'y' },
{ myId: 'x4', v: 'z' }
];
const received = mergeCollections(col1, col2, { id: 'myId' });
const expected = [
{ myId: 'x1', v: 'x' },
{ myId: 'x2', v: 'y' },
{ myId: 'x3', v: 'c' },
{ myId: 'x4', v: 'z' }
];
expect(received).toEqual(expected);1.0.0-beta.9
5 years ago
1.0.0-beta.6
7 years ago
1.0.0-beta.5
7 years ago
1.0.0-beta.3
7 years ago
1.0.0-beta.2
7 years ago