Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 893 Bytes

README.md

File metadata and controls

47 lines (38 loc) · 893 Bytes

model-setters

Lets a model specify custom getters and setters for attributes.

Installation

$ component install treygriffith/model-setters

API

var setters = require('model-setters')
  , model = require('model');

// all specified up front
var person = model('person')
  .use(setters({
    name: {
      get: function (name) {
        return name.toUpperCase();
      },
      set: function (name) {
        return name.toLowerCase();
      }
    },
    age: {
      set: function (age) {
        return parseInt(age, 10);
      }
    } 
  }))
  .attr('name')
  .attr('age');

// or specified individually
var person = model
  .use(setters)
  .attr('name', {
    get: function (name) { return name.toUpperCase(); }
    set: function (name) { return name.toLowerCase(); }
  })
  .attr('age', { set: function (age) { return parseInt(age, 10); } });

License

MIT