busypeoples / spected

Validation library
MIT License
703 stars 32 forks source link

How to stop after first validation failure #99

Closed ahallock closed 6 years ago

ahallock commented 6 years ago

If a property is null or undefined, it's useful to stop validation there rather than execute the other validations. Otherwise, you have to check for null/undefined on all your subsequent validations.

ahallock commented 6 years ago

I feel like this can be handled by a simple higher order function, similar to what's in https://codeburst.io/composable-object-validations-in-js-efa1ebacc34e

busypeoples commented 6 years ago

Yes, this sounds reasonable. Not sure if this should be part of spected. The example shown by @Emilios1995 would solve the problem. Delegating the decision to user land should be the better approach. Would that example work for your case?

ahallock commented 6 years ago

It works, thank you.