Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: greaterThan, smallerThan #975

Open
MickL opened this issue Dec 12, 2024 · 8 comments
Open

Feature request: greaterThan, smallerThan #975

MickL opened this issue Dec 12, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@MickL
Copy link

MickL commented Dec 12, 2024

Great library! I only realized there is no possibility to add a "greater than" or "smaller than" validation. Of course, minValue() can be used, but it is not really accurate. E.g. when I want a number to be positive (> 0) I have to do minValue(0.001) but now 0.0001 would be invalid so I need to use a very small number minValue(0.0000001) but still a smaller number that is positive would be invalid.

Therefor I would like to add a feature request to add:

  • greaterThan(), or gt()
  • lessThan(), or lt()
  • Optional: I found positive() from Zod very useful, but it is just a more humanly readable version greaterThan(0)
@fabian-hiller
Copy link
Owner

Thank you for creating this issue. I agree that we should add such actions. I am just unsure about the naming. It would be great if they would match somehow with minValue and maxValue.

@MickL
Copy link
Author

MickL commented Dec 12, 2024

Maybe:

  • valueGreaterThan
  • valueGt
  • greaterThanValue
  • gtValue

@fabian-hiller
Copy link
Owner

Feel free to create a PR with gtValue and stValue.

@fabian-hiller
Copy link
Owner

What is more common? "smaller than" or "less than"? Maybe we should use ltValue instead of stValue.

@MickL
Copy link
Author

MickL commented Dec 12, 2024

Sorry it should be less than, not smaller than. See for example https://orm.drizzle.team/docs/operators#lt

I am afraid I will not have the time to get in the project and make a PR.

@fabian-hiller
Copy link
Owner

Don't worry. I am already thankful for your contribution. I am sure someone else will work on it soon.

@fabian-hiller fabian-hiller self-assigned this Dec 12, 2024
@fabian-hiller fabian-hiller added the enhancement New feature or request label Dec 12, 2024
@EltonLobo07
Copy link
Contributor

I'll work on adding ltValue & gtValue. I would recommend using a pattern like shown here till I complete adding the actions. The expected field of the issue might not make sense (Eg: parsing -1 would set expected to ≥0 and 0 to !0) but if the expected field is not used, it does the job.

@fabian-hiller
Copy link
Owner

This has been implemented by Elton in #978 and #985 over the last few weeks and will probably be reviewed and merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants