1.0.3 • Published 4 years ago
setupdate v1.0.3
setupdate
The lightweight util to update an JS object
Installation
Using npm
npm install setupdate
Using yarn
yarn add setupdate
Usage
import setupdate from 'setupdate';
or
const setupdate = require('setupdate');
Use
let obj = {};
obj = setupdate(obj, setUpdateObj);
/* where "setUpdateObj" defines only the properties to set/update */
Example
let user = {
name: 'Adam',
karma: 22,
friends: [{
name: 'Bernard',
mutuals: 22,
}],
};
user = setupdate(user, {
karma: 33,
friends: [
{
name: 'Charles',
mutuals: 0,
}
]
});
/* Output */
/*
{
name: 'Adam',
karma: 33,
friends: [
{
name: 'Bernard',
mutuals: 22,
},
{
name: 'Charles',
mutuals: 0,
}
]
}
*/
Limitations:
- Will not go deeper when its an array ( pushes into the array even if its nested array of objects)