1.0.0 • Published 8 years ago

valydet v1.0.0

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

Valydet

  • A tiny module to validate JSON data.

Status

Build Status

Usage

const valydet = require('valydet');
const PostSchema = new valydet.Schema({
  id: { type: 'string', required: true },
  title: { type: 'string', required: true },
  by: { type: 'email', required: true }
});

// Validate data.
let result = PostSchema.validate({
  id: 'testId',
  title: '',
  by: 'invalidemail'
});

// access errors list
console.log(result.failures());

API

new valydet.Schema(schemaDefinition)

  • Generates a new schema for the given schema definition
  • Params
    • schemaDefinition - Schema Definition containing the rules.

      • Uses is.js for validation each attribute.

Usage:

const valydet = require('valydet');
const SomeSchema = new valydet.Schema({
  id: { type: 'string',
   required: true,
   // You can have custom error message to override
   // the default message. 
   message: 'Custom error message' 
  },
  email: { type: 'email': required: true }
});

schemaInstance.validate(data)

  • Validates the supplied data against the schema definition.
  • returns: [] of errors

schemaInstance.failures()

  • returns: list of errors

      // error format
      {
        key: 'id' // property name.,
        message: 'Something went wrong' // Error message.
      } 
1.0.0

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago