1.1.3 • Published 6 years ago

add-props v1.1.3

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

Add Props

Easiest way to add props and values to the object

Installation

npm install add-props

Usage

const addProps = require('add-props');


var myObject = {};

// Just create properties structure
addProps(myObject, 'click.url');

/*{
   "click": {
      "url": {}
   }
}*/


// Add value to the property
addProps(myObject, 'events.tracker.pixel.url', 12346789);

/*{
   "events": {
      "tracker": {
         "pixel": {
            "url": 12346789
         }
      }
   }
}*/


// Create multiple properties and fill them with the same value
addProps(myObject, ['stat.user_id', 'html.footer.block_id'], 'id123456789');

/*{
   "stat": {
      "user_id": "id123456789"
   },
   "html": {
      "footer": {
         "block_id": "id123456789"
      }
   }
}*/


// Create multiple properties with own values
addProps(myObject, ['video.duration', 'audio.sound.muted'], [120.459, true]);

/*{
   "video": {
      "duration": 120.459
   },
   "audio": {
      "sound": {
         "muted": true
      }
   }
}*/


console.log(JSON.stringify(myObject, true, 3));

Also you can create new object with specified props. Just skip the first argument like so:

var new_object = addProps('new.object.says', 'yey!');
1.1.3

6 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago