kripod / kripod/bookshelf-validate
Optional validation
- Dominant language
- JavaScript
- Stars
- 8
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
How can one validate a field _only if it's present_?
Currently, If a value is null or undefined, validation [always passes](https://github.com/kripod/bookshelf-validate/blob/master/lib/index.js#L15).
My use case is allowing null values for postcodes, but if one is provided then it must be valid.
So there either must be a valid one, or none at all.
I was hoping to achieve this with a custom validator:
```
postcode: [{
method: 'isPostcode',
error: 'Postcode is invalid',
args: { optional: true }
}]
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Read lib/index.js around line 15 to trace how null and undefined values currently bypass validation. Define the optional-validation behavior for a missing postcode versus a provided valid or invalid postcode, then verify those three cases against the repository's existing validation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100