1.1.1 • Published 5 years ago

getters-to-props v1.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

getters-to-props.js

Get simple properties from object of getters.

Install

Node

npm install --save getters-to-props

Bower (AMD, Global)

bower install --save getters-to-props

Use

var gettersToProps = require('getters-to-props');

var obj = {
  getThing: function () {
    return 1;
  },
  setThing: function () {},
  getMore: function () {
    return { another: 'yep' };
  },
  notMe: 'nope',
  getFailure: function () {
    throw new Error("oops");
  }
};

props = gettersToProps(obj);

// props is now:
{
  thing: 1,
  more: { another: 'yep' },
  failure: undefined
}

// or options, e.g. "others"

props = gettersToProps(obj, {
  others: true
});

// props is now:
{
  thing: 1,
  more: { another: 'yep' },
  failure: undefined,
  notMe: 'nope'
}