2.0.2-0 • Published 10 years ago
checkpoint v2.0.2-0
Currently under construction, please post issues on GitHub.
Example
var checkpoint = require('checkpoint');
var checkpoints = {
register: checkpoint({
email: {
required: true,
message: 'A valid email is required!',
test: /\S+@\S+\.\S+/ // a basic regex for testing emails, don't use in production
},
username: {
required: true,
message: 'A valid username is required!'
test: function(val, next) {
if(val === expectedVal) {
next();
} else {
next('Val was not expected value.'); // error string, if left blank defaults to validator message
}
}
}
})
}
app.post('/register', checkpoints.register, function(req, res) {
if(req.checkpoint.passed) {
// all required values passed their tests
} else {
res.send(req.checkpoint.errors); // array of failed values messages
}
});
Api
// require checkpoint
var checkpoint = require('checkpoint');
app.use(checkpoint(config));
Config Options:
Option | Description |
---|---|
required? | optional, defaults to true |
method? | optional, defaults to 'post', |
min? | optional, checks if value is greater than or equal to the min, works on strings, numbers, and dates |
max? | optional, checks if value is less than or equal to the max, works on strings, numbers, and dates |
test? | a function(val, next) or RegExp - message can be supplied in next |
message? | optional, defaults to test message or 'key' |
2.0.2-0
10 years ago
2.0.2
10 years ago
2.0.1-3
10 years ago
2.0.1-2
10 years ago
2.0.1-1
10 years ago
2.0.1
10 years ago
2.0.0
10 years ago
1.1.1
10 years ago
1.1.0
10 years ago
1.0.9
10 years ago
1.0.8
10 years ago
1.0.7
10 years ago
1.0.6
10 years ago
1.0.5
10 years ago
1.0.4
10 years ago
1.0.3
10 years ago
1.0.2
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.1.4
12 years ago
0.1.3
12 years ago
0.1.2
12 years ago
0.1.1
12 years ago
0.1.0
12 years ago