2.0.2-0 • Published 8 years ago

checkpoint v2.0.2-0

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

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:
OptionDescription
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

8 years ago

2.0.2

8 years ago

2.0.1-3

8 years ago

2.0.1-2

9 years ago

2.0.1-1

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.4

11 years ago

0.1.3

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago