Added lowerCase and upperCase mutate options to string validation.
Why?
For example, the email address is not case-sensitive. Also, the e-mail address is a unique value. I know rules.email() has already lowerCase sanitization but that's only an example. Username can be given as an example instead of email address.
[ ] Bugfix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist
Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.
[x] Lint and unit tests pass locally with my changes
[x] I have added tests that prove my fix is effective or that my feature works.
[ ] I have added necessary documentation (if appropriate)
Further comments
I made a type check to don't use both lowerCase and upperCase at the same time but type controls are constantly duplicated in the project. (In validator.ts, schema/index.ts and etc.) I think this can be improved.
Proposed changes
Added lowerCase and upperCase mutate options to string validation.
Why?
For example, the email address is not case-sensitive. Also, the e-mail address is a unique value. I know
rules.email()
has already lowerCase sanitization but that's only an example. Username can be given as an example instead of email address.email: schema.string({ trim: true }, [ rules.email(), rules.unique({ table: 'users', column: 'email' }) ])
The unique validation above will be unnecessary for these 2 values:
We can validate this just by add the lowercase property to string options:
email: schema.string({ trim: true, lowerCase: true }, [ rules.email(), rules.unique({ table: 'users', column: 'email' }) ])
Unique control is now really functional.
Types of changes
What types of changes does your code introduce?
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.Further comments
I made a type check to don't use both lowerCase and upperCase at the same time but type controls are constantly duplicated in the project. (In validator.ts, schema/index.ts and etc.) I think this can be improved.