verymodel

VeryModel (GitHub: fritzy/VeryModel, License: MIT) is a system for validation, creation, and editing of models. VeryModel is not tied to a framework, and it implements a full purpose Model system.

npm install verymodel

Here’s an example of a model definition:

// Create a User Factory
var User = new VeryModel({
  id: {primary: true, type: VeryType().isAlphanumeric(), default: 1},
  username: {required: true, type: VeryType().isAlphanumeric().len(4, 25), default: ''},
  password: {required: false, type: VeryType().len(6).custom(goodPassword)}, default: ''},
  passhash: {private: true},
});

Model defintions are recursive Javascript object. At each layer, you can have the following fields:

  • required (boolean): Error on validation if this field isn’t set.
  • type (VeryType): VeryType chain to validate field against if set.
  • default (any): Default value set automatically.
  • model (definition object or VeryModel): set this field as another model.
  • collection (definition object or VeryModel): set this field as a collection of a model.
  • derive function): Derive the value of this field with this function whenever field is accessed {derive: function(model) {return model.first + ' ' + model.last}
  • depends ({some_other_field: VeryType or true}, …): Require other fields when this field is set, optionally run VeryType chain check on other field.
  • primary (boolean): Set this on one of your fiels for easy saving and loading.
  • private (boolean): toObject() will not include this field in expect unless the argumnet usePrivate is true

There are plenty of examples and information on the . Check it out!