zod
zod copied to clipboard
Feature request for reverse transform
I love how the .transform
function works and how it all makes working with external data so easy. In my example I'm loading and parsing an ini file and then transform it into usable JSON to work with in forms in my app. This is all great and smooth but the problem I encountered was when I wanted to save the modified data back into an ini file. What I had to do was basically double all my schemas, one for parsing data from the ini (MatrixValueSchema
) and one for parsing my form values back to the shape of the ini file data (RawMatrixValueSchema
).
Here is the schema file for full context.
One solution that I think would work nicely, would be to add an optional reverse callback to the .transform
helper and then a new .reverseParse
function which would take a output value and return a input value.
I'm sure there are a bunch of more steps to think through for this to work, but I'd like to hear your opinion on usefulness of feature like this or some way to better solve this problem with current features.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.