2.0.0 • Published 8 years ago

wadofgum-validation v2.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

wadofgum-validation Build Status

A validation mixin for wadofgum based on joi.

Usage

After extending your model with this mixin, instances of your class will have a validate method. This method returns a promise that resolves when validation is complete, or throws if validation fails.

To provide a schema for validation, assign it to the schema property on your class. Most Joi features are covered, including type coercion, required keys, renaming keys, and more.

const Wadofgum = require('wadofgum');
const Validation = require('wadofgum-validation');
const Joi = require('joi');

class Model extends Wadofgum.mixin(Validation) {};
Model.schema = Joi.object({
  name: Joi.string().required(),
  age: Joi.number().integer()
});

let model = new Model({ name: 'test', age: '45' });
model.validate().then(function () {
  model.name; // 'test'
  model.age; // 45
});

If the wadofgum-events mixin is also loaded, this module will emit preValidate and postValidate events.

2.0.0

8 years ago

1.1.0

8 years ago

1.0.0

9 years ago