1.3.0 • Published 9 years ago

checky v1.3.0

Weekly downloads
17
License
MIT
Repository
github
Last release
9 years ago

checky

Declarative JavaScript object validation.

Usage

var checky = require('checky');

var checkPerson = checky({
   name: String,
   age: {
      type: Number,
      min: 18,
      max: 80
   },
   hobby: ['Running', 'Gaming', 'Hacking'],
   other: {
      type: String,
      optional: true
   }
});

var dennis = {
   name: 'Dennis Ritchie',
   age: 70,
   hobby: 'Hacking'
};

checkPerson(dennis); // true

Recursive Schemas

var checkNested = checky({
   name: String,
   age: Number,
   nested: {
      type: Object,
      fields: {
         name: String,
         age: Number,
         nested: {
            type: Object,
            fields: {
               name: String,
               age: Number
            }
         }
      }
   }
});

var russianStallmans = {
   name: 'Richard Stallman',
   age: 61,
   nested: {
      name: 'Richard Stallman',
      age: 61,
      nested: {
         name: 'Richard Stallman',
         age: 61
      }
   }
};

checkNested(russianStallmans); // true

Options

The second argument to the schema checking function returned by checky is an options object. Options include:

  • debug (true|false) - print error messages for invalid objects
  • sparse (true|false) - all schema fields are made optional
  • err (true|false) - instead of returning false, return an err object containing details of the schema violation
1.3.0

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.2.6

9 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago