validator.js
validator.js copied to clipboard
Truthy. and Falsy validation
- Added new function
isTruthy(...)
andisFalsy(...)
which help to validate if a value istrue
orfalse
. This also include testing for[yes,no,y,n]
to the boolean values. This validation is great forcheckboxes
orradioboxes
in web dev. - Also added readme file changes , formatting ever single function description casing.
Checklist
- [X] PR contains only changes related; no stray files, etc.
- [X] README updated (where applicable)
- [X] Tests written (where applicable)
Codecov Report
Merging #1855 (08a3286) into master (45901ec) will not change coverage. The diff coverage is
100.00%
.
@@ Coverage Diff @@
## master #1855 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 102 104 +2
Lines 2054 2068 +14
Branches 464 467 +3
=========================================
+ Hits 2054 2068 +14
Impacted Files | Coverage Δ | |
---|---|---|
src/index.js | 100.00% <100.00%> (ø) |
|
src/lib/isFalsy.js | 100.00% <100.00%> (ø) |
|
src/lib/isTruthy.js | 100.00% <100.00%> (ø) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 45901ec...08a3286. Read the comment docs.
I was trying to validate if validation result from custom validation was true and it seems from the description of what the toBoolean
does is to sanitize values to be true or false and not check if the incoming value is truthy or flasy . The function was more of a sanitizer and less of a validator
Is it a sanitizer? It doesn't return a new value. https://github.com/validatorjs/validator.js/blob/master/src/lib/isBoolean.js
But I think isBoolean
is not a better way of naming the function but rather isTruthy
or isFalsy
since we might be validating a payload property and asking the question is this property true or false
. I feel `isBoolean might not be a proper name for that .
Anyway it is just my opinion.
I'm not totally sure about this and it's practicality as isBoolean covers most cases. We try to make the validators as generic as possible and not tied to particular usecase