Skip to content

Lets a model specify custom getters and setters when changing an attribute

Notifications You must be signed in to change notification settings

treygriffith/model-setters

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Lets a model specify custom getters and setters when changing an attribute

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published