0.1.8 • Published 10 years ago

wrong v0.1.8

Weekly downloads
4
License
BSD
Repository
github
Last release
10 years ago

wrong

Another JS object validation module with focus on simplicity.

API

buildValidator(rules)

Builds function which promises validation errors for given object.

var validate = buildValidator({
	name: ['required'],
	cash: ['required', 'positive number']
});

var user = {
	name: '',
	cash: -10
};

validate(user).then(function (errors) {
	console.log('User is not valid!', errors);
});

rules

Contains hash of rules: key is name, value is validation function.

Validation function has following signature: function (value, fieldName, wholeObject). It must promise error or return nothing if value is valid. Note: context (this) of validate function will be applied to each field validator, so you can use it to pass additional information, like current user.

arrayValidator(itemValidator)

Constructs array value validator by taking item validator as parameter.

existanceValidator(finder, message)

Constructs existance validator (value must be an ID of existing object).

License

BSD

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago