0.0.1 • Published 7 years ago
deep-object-assign v0.0.1
deep-object-assign
Generate a copy of an object while modifiyng a part of its attributes. Can be useful for instance in Redux reducers.
Installation
npm install --save deep-object-assign
Usage
Let's consider the following object:
const person = {
lastname: 'Potter',
firstname: 'Harry',
address: {
country: 'Scotland',
position: {
latitude: 2.35311,
longitude: 50.3534,
}
}
}
Let's imagine that we want to create a copy of this object while modifying the latitude
attribute.
Using deep-object-assig
, the code will looks like:
const deepAssign = require('deep-object-assign');
const modifiedCopy = deepAssign(person, { address: { position: { latitude: 1234}}});
/*
modifiedCopy is: {
lastname: 'Potter',
firstname: 'Harry',
address: {
country: 'Scotland',
position: {
latitude: 1234,
longitude: 50.3534,
},
},
}
*/
0.0.1
7 years ago