StefanTerdell / zod-to-json-schema

Converts Zod schemas to Json schemas
ISC License
886 stars 71 forks source link

Emoji regex is not supported in some environments #132

Closed jacoblee93 closed 2 months ago

jacoblee93 commented 2 months ago

Unicode regexes are not supported in all environments - React Native in particular. One is used here:

https://github.com/StefanTerdell/zod-to-json-schema/blob/master/src/parsers/string.ts#L26

This is problematic because even if we don't use a schema containing z.string().emoji(), the regex is instantiated immediately as the object is imported. The fix in Zod was to lazily instantiate the regex:

https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b

With this, the rest of the library is usable in such environments (though .emoji() still won't be).

I'll open a PR with a similar fix.

StefanTerdell commented 2 months ago

@jacoblee93 Out now in 3.23.2. Thanks for the fix!

jacoblee93 commented 2 months ago

Thank you @StefanTerdell!