-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for zod effectors and defaults (#8)
Current source is lacking support for effectors and zod defaults support, causing it to default to a base64 representation of the data which is not ideal as something like: ```ts const schema = z.object({ a: z.string().default("hi"), b: z.number().default(1), }); const data = {a: "test", b: 10}; const outputParams = serialize({schema, data}); ``` produces the output `a=InRlc3Qi&b=MTA` instead of `a=test&b=10` ## Expected outputs ```ts const schema = z.object({ a: z.string().transform(Number), }); const input = new URLSearchParams("a=1"); const parsed = parse({schema, input}) // {a: 1} const serailized = serialize({schema, data: parsed}) // new URLSearchParams("a=1") ``` or with defaults ```ts const schema = z.object({ a: z.string().default("hi"), b: z.number().default(1), }); const input = new URLSearchParams("b=10"); const parsed = parse({schema, input}) // {a: "hi", b: 10} const serialized = serialize({schema, data: parsed}) // new URLSearchParams("b=10") ``` Note: both are also supported in serialize too, defaults will be omitted if they match (to reduce the url length, following the same existing behaviour in the optional `defaults` argument)
- Loading branch information
1 parent
fe96695
commit 9886757
Showing
2 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters