validator.js
validator.js copied to clipboard
Added Exact Condition for String Length & Updated README.md
feat(isLength): Added Conditions for checking if String's length is equal to exact if exact provided
If the string length falls in the range and if exact number/array/object is provided, then exact conditions are checked. If not provided, then true is returned is len>=min & len<=max and false is returned is not in the range [min, max]. README.md File is also updated for the same.
Checklist
- [x] README updated (where applicable)
- [x] PR contains only changes related; no stray files, etc.
- [x] Tests written (where applicable)
Codecov Report
Patch coverage: 100.00
% and no project coverage change.
Comparison is base (
531dc7f
) 100.00% compared to head (3ef2588
) 100.00%.
:exclamation: Current head 3ef2588 differs from pull request most recent head 22bb2f0. Consider uploading reports for the commit 22bb2f0 to get more accurate results
Additional details and impacted files
@@ Coverage Diff @@
## master #2019 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 104 104
Lines 2308 2311 +3
Branches 578 579 +1
=========================================
+ Hits 2308 2311 +3
Impacted Files | Coverage Ξ | |
---|---|---|
src/lib/isLength.js | 100.00% <100.00%> (ΓΈ) |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Hello, I have added the required feature. If the string length falls in the range and if exact number/array/object is mentioned, then exact conditions are checked. If not provided, then true is returned is len>=min & len<=max and false is returned is not in range [min, max]. All the checks have also been passed :) PR#2019 - https://github.com/validatorjs/validator.js/pull/2019
Thanks for the updates! I have some additional comments
And I'll tag @rubiin here as well for the more official review and approval for having
exact
be either a number, a array or an object of numbers since I'm not a maintainer of this library
Okkay
Keep the old test and then I think we should be good. I'll leave other reviews up to the actual maintainers of this library. Thanks again for working on this!
Yess!! The old test is been added again... Anyways, Feeling happy after working on this!! Thank You
@rubiin @WikiRik @chuyeow @boutell @timoxley Please have the final look.
As mentioned before, my review won't help. But it all looks good to me!
As mentioned before, my review won't help. But it all looks good to me!
The woes of being an active contributor without write access π₯²
@rubiin Please have a final look.
Before further review lets wait for approval from @profnandaa
Sorry for late review on this.
I'm struggling to understand the use-case for
exact
. And also why we have as an object or array too. Could you explain where this could be used?
Instead of just giving users the only feature of passing the minimum and the maximum length of string, if at all a user wants to check if the length of string matches the exact number/s then he can simply pass exact
values.
This can be understood by the following use case-
- If the user wants a string length to be exactly 10, then he would have to pass
minimum
: 10 &maximum
: 10 whereas this could be done by simpleexact
: 10. - If the user wants to check if the string length matches multiple values, then passing just
minimum
&maximum
values are of no use, instead, he can simply pass an array of integers.
I hope this solves your confusion.
@bevatsal1122 -- thanks for the clarification. I'd thought .length
will be enough but I guess for the sarogate pairs/some unicode chars, that the function support, this will be handly.
Let me merge, thanks! And thanks too @WikiRik @rubiin for your reviews on this.
One more approval and I'll merge. @rubiin @WikiRik
@pixelbucket-dev I made all the necessary changes and also synced the branch with the latest commits.
I was just thinking: A future improvement could be to improve the options API to have consistent fields. This is because, with discreteLengths
, we have a new field, and the API might become less intuitive to use now.
Something like:
{
range: {
min: 0,
max: undefined
}, // optional
discreteLengths: undefined // optional
}
With the above proposal, it also becomes clear, that there is another permutation of the rules set:
-
range
defined ANDdiscreteLengths
undefined β implemented by this PR -
range
undefined ANDdiscreteLengths
undefined β implemented by this PR -
range
defined ANDdiscreteLengths
defined β implemented by this PR -
range
undefined ANDdiscreteLengths
defined β NOT implemented by this PR
So basically, we would have to discuss if this API should allow checking against discrete lengths w/o using the range rule/option. Currently, to check discreteLengths
, min
and max
, i.e. range
, are also considered.
Just some food for thoughts π.
I was just thinking: A future improvement could be to improve the options API to have consistent fields. This is because, with
discreteLengths
, we have a new field, and the API might become less intuitive to use now.Something like:
{ range: { min: 0, max: undefined }, // optional discreteLengths: undefined // optional }
With the above proposal, it also becomes clear, that there is another permutation of the rules set:
range
defined ANDdiscreteLengths
undefined β implemented by this PRrange
undefined ANDdiscreteLengths
undefined β implemented by this PRrange
defined ANDdiscreteLengths
defined β implemented by this PRrange
undefined ANDdiscreteLengths
defined β NOT implemented by this PRSo basically, we would have to discuss if this API should allow checking against discrete lengths w/o using the range rule/option. Currently, to check
discreteLengths
,min
andmax
, i.e.range
, are also considered.Just some food for thoughts π.
Yeahh that's a really good idea. Making it segregated into key-value pairs would be easier to use and understand. @WikiRik @rubiin What do you think ??
I was just thinking: A future improvement could be to improve the options API to have consistent fields. This is because, with
discreteLengths
, we have a new field, and the API might become less intuitive to use now. Something like:{ range: { min: 0, max: undefined }, // optional discreteLengths: undefined // optional }
With the above proposal, it also becomes clear, that there is another permutation of the rules set:
range
defined ANDdiscreteLengths
undefined β implemented by this PRrange
undefined ANDdiscreteLengths
undefined β implemented by this PRrange
defined ANDdiscreteLengths
defined β implemented by this PRrange
undefined ANDdiscreteLengths
defined β NOT implemented by this PRSo basically, we would have to discuss if this API should allow checking against discrete lengths w/o using the range rule/option. Currently, to check
discreteLengths
,min
andmax
, i.e.range
, are also considered. Just some food for thoughts π.Yeahh that's a really good idea. Making it segregated into key-value pairs would be easier to use and understand. @WikiRik @rubiin What do you think ??
It would be a breaking change! So I'd suggest keep the existing API (min
and max
), like with the other PRs here, and add the new fields range
and discreteLengths
. min
and max
should probably be prioritised if defined, for now. You can document the new syntax already in this PR and deprecate min
and max
. With the next major version, min
and max
will be removed.
@rubiin any reason why you approved this while the GitHub Actions have not passed?
@bevatsal1122 could you please fix the formatting issues that break the CI? View the βFiles Changedβ tab so see details about the linting issues.
N.B. we have to discuss better linter integration. Errors like this should never arrive in the PR, but rather fixed at commit time or push time by running commit hooks.