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

Refactor assertString: Faster, less nested and more consistent.

Open EmersonRabelo opened this issue 1 year ago • 5 comments

@profnandaa, I have a possible improvement for the assertString. I am reducing the number of necessary validations and also a more assertive approach, in my point of view (if this approach doesn't make sense, I would appreciate feedback on it, if possible). The performance has also improved, it wasn't something incredible, but it was considerable.

image

Unit tests: image

EmersonRabelo avatar Feb 08 '24 22:02 EmersonRabelo

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (b958bd7) 99.95% compared to head (f8e62de) 99.95%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2372      +/-   ##
==========================================
- Coverage   99.95%   99.95%   -0.01%     
==========================================
  Files         107      107              
  Lines        2454     2445       -9     
  Branches      619      617       -2     
==========================================
- Hits         2453     2444       -9     
  Partials        1        1              

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 09 '24 03:02 codecov[bot]

Hi, @WikiRik! I made a small change in the code and also committed the unit tests. But it failed in one of the tests.

image

EmersonRabelo avatar Feb 09 '24 03:02 EmersonRabelo

codecov/project will be fixed with https://github.com/validatorjs/validator.js/pull/2341

WikiRik avatar Feb 09 '24 06:02 WikiRik

when you pass literally null, it gives

Uncaught TypeError: Cannot read properties of null (reading 'constructor')

because it is not caught by the first check.

Should we explicitly check for null there as well?

pano9000 avatar Feb 09 '24 19:02 pano9000

Hello, @pano9000! Do you have any further comments on this or is everything okay? If necessary, I will make the alterations!

EmersonRabelo avatar Feb 14 '24 18:02 EmersonRabelo