1.0.3 • Published 4 years ago

setupdate v1.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

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)
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago