@mzvonar/mergein
v0.1.7
Published
Merge new object with value at provided path in context object
Downloads
13
Readme
mergeIn
Merges value in object by path with provided object. Path can be string or array (e.g. ['user', 'profile', 'gender']).
If any part of path doesn't exist it is created. Always returns new copy of object.
Installation
npm install @mzvonar/mergein
Usage
const mergeIn = require('@mzvonar/mergein');
const context = {
user: {
profile: {
gender: 'female'
}
}
};
const newContext = mergeIn(context, ['user', 'profile'], {
gender: 'male',
address: {
country: 'slovakia'
}
});
returns:
{
user: {
profile: {
gender: 'male',
address: {
country: 'slovakia'
}
}
}
}
const newContext = mergeIn(context, 'user', {
address: {
country: 'slovakia'
}
);
returns:
{
user: {
profile: {
gender: 'female',
},
address: {
country: 'slovakia'
}
}
}
Tests
npm test