Skip to content

ioncreature/simple-object-schema

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-schema-validation

Simple object schema description and validation

Simple Usage

const Schema = require( 'object-schema-validation' );

var someSchema = new Schema({
        name: String, 
        age: Number
    }),
    validation = someSchema.validate({
        name: 'Johny', 
        age: 88
    });

if ( validation.valid )
    console.log( 'yay, its valid' );
else
    console.warn( 'oh, no! It invalid', validation.error );

Available types

    
    var userSchema = new Schema({
        age: Number,
        name: String,
        birthDate: Date,
        about: {type: String, max: 100500, required: true},
        friends: [Number],
        posts: [{text: String, at: Date}],
        weight: {type: Number, min: 30, max: 300, required: true},
        meta: {
            la: Number,
            lalala: {type: Date},
            blabla: {
                list: [String],
                isTrue: Boolean
            }
        },
        complicated: function( val ){
            return Math.random() * 2 | 0;
        }
    })
        
    userSchema.validate( user ); // returns {valid: Boolean, error?: Error}

About

Simple object schema description and validation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published