You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a proposal for the new version of the library: v2.0.0 which implies a complete change (refactoring) of how the data is returned by the library.
The current behaviour is quite simple:
constNope=require("nope-validator")constschema=Nope.string().email().required()schema.validate('[email protected]')// 🟢 returns undefined since there are no errorsschema.validate('invalid-email')// 🔴 returns a string message with the error: "Input is not a valid email"
There is absolutely nothing wrong with this pattern, however as we are thinking of implementing transformers (handlers for input data), we assumed that it would make more sense to return something different that could benefit users.
So the API return was defined to meet all possible needs, returning not only the error but also the input data and the data that was transformed, as follows:
Key
Description
data
returns always exactly the input data
transformed
returns the transformed data (if any transformation has taken place), otherwise it returns the input data
errors
returns an empty array (if there are no errors), otherwise it returns an array of errors
Let's see what the return should look like for both cases (success/error):
You may be wondering, but what are the transformers? And the truth is that currently we don't have many defined, only one that was introduced last week (trim#824), however another one has already been requested, it is the case of (default#641), and along with the new version, we plan to release others, like: (toLowerCase, toUpperCase, round.floor**, round.ceil, round.trunc and round.round).
** By the way, round a.k.a. Math['type'].
If you have any ideas/suggestions or if you'd like to contribute to the release of the new version, feel free to reply in this thread and I'll explain how you can. If you want to keep up with the work in progress, keep an eye on the branch where the temp work is being done: https://github.com/ftonato/nope-validator/tree/feat/nope-2.0.0.
Thanks for your attention 🎈
The text was updated successfully, but these errors were encountered:
It would be nice to change the behaviour of min. Currently it's just an alias to greaterThan but it's more intuitive that it's actually equal or greater than. For example, I would expect this to be valid:
This is a proposal for the new version of the library: v2.0.0 which implies a complete change (refactoring) of how the data is returned by the library.
The current behaviour is quite simple:
There is absolutely nothing wrong with this pattern, however as we are thinking of implementing transformers (handlers for input data), we assumed that it would make more sense to return something different that could benefit users.
So the API return was defined to meet all possible needs, returning not only the error but also the input data and the data that was transformed, as follows:
Let's see what the return should look like for both cases (success/error):
🟢 Success scenario (no errors will be returned)
🔴 Failure scenario (a errors list will be returned)
You may be wondering, but what are the transformers? And the truth is that currently we don't have many defined, only one that was introduced last week (
trim
#824), however another one has already been requested, it is the case of (default
#641), and along with the new version, we plan to release others, like: (toLowerCase
,toUpperCase
,round.floor
**,round.ceil
,round.trunc
andround.round
).** By the way,
round
a.k.a.Math['type']
.If you have any ideas/suggestions or if you'd like to contribute to the release of the new version, feel free to reply in this thread and I'll explain how you can. If you want to keep up with the work in progress, keep an eye on the branch where the temp work is being done: https://github.com/ftonato/nope-validator/tree/feat/nope-2.0.0.
Thanks for your attention 🎈
The text was updated successfully, but these errors were encountered: