Skip to content
Get simple properties from object of getters.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src
test
.gitignore
README.md
bower.json
index.js
package.json

README.md

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'
}
Something went wrong with that request. Please try again.