1.3.0 • Published 11 years ago
checky v1.3.0
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
11 years ago
1.2.3
11 years ago
1.2.2
11 years ago
1.2.1
11 years ago
0.2.1
11 years ago
0.2.0
11 years ago
0.2.6
11 years ago
1.1.7
11 years ago
1.1.6
11 years ago
1.1.5
11 years ago
1.1.4
11 years ago
1.1.3
11 years ago
1.1.2
11 years ago
1.1.1
11 years ago
1.1.0
11 years ago
1.0.2
11 years ago
1.0.1
11 years ago
1.0.0
11 years ago