property-accessor

1.0.0 • Public • Published

Property Accessor

Install package:

yarn add property-accessor

Usage example:

const PropertyAccessor = require('property-accessor');

let target = {
  users: [
    {
      firstName: 'John',
      surName: 'Doe',
      age: 25
    },
    {
      firstName: 'Ann',
      surName: 'Doe',
      age: 23
    }
  ]
};

let proxy = new PropertyAccessor(target);

console.log(proxy.get('users[0].firstName'));
// John

proxy.set('users[1].age', 24);
console.log(proxy.get('users[1].age'));
// 24

target.users[0].age = 26;
console.log(proxy.get('users[0].age'));
// 26

proxy.set('users[0].children[0]', { name: 'Nick', age: 1 });
console.log(target.users[0].children);
//  [ { name: 'Nick', age: 1 } ]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.040latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.040

Package Sidebar

Install

npm i property-accessor

Weekly Downloads

40

Version

1.0.0

License

ISC

Unpacked Size

4.37 kB

Total Files

4

Last publish

Collaborators

  • pashaman