validator.js icon indicating copy to clipboard operation
validator.js copied to clipboard

Truthy. and Falsy validation

Open caleberi opened this issue 3 years ago • 5 comments

  • Added new function isTruthy(...) and isFalsy(...) which help to validate if a value is true or false. This also include testing for [yes,no,y,n] to the boolean values. This validation is great for checkboxes or radioboxes 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)

caleberi avatar Oct 31 '21 16:10 caleberi

Codecov Report

Merging #1855 (08a3286) into master (45901ec) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            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.

codecov[bot] avatar Oct 31 '21 16:10 codecov[bot]

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

caleberi avatar Nov 05 '21 03:11 caleberi

Is it a sanitizer? It doesn't return a new value. https://github.com/validatorjs/validator.js/blob/master/src/lib/isBoolean.js

fedeci avatar Nov 05 '21 08:11 fedeci

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.

caleberi avatar Nov 05 '21 14:11 caleberi

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

rubiin avatar Jul 27 '22 06:07 rubiin