diff --git a/next.config.js b/next.config.js index 7900a6a..db97770 100644 --- a/next.config.js +++ b/next.config.js @@ -1,3 +1,7 @@ +const crypto = require("crypto"); +const cryptoOrigCreateHash = crypto.createHash; +crypto.createHash = algorithm => + cryptoOrigCreateHash(algorithm === "md4" ? "sha256" : algorithm); const webpack = require("webpack"); const config = { diff --git a/package.json b/package.json index 11a6230..a095ff1 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build:analyze": "ANALYZE=true yarn build" }, "engines": { - "node": "16.x" + "node": "20.x" }, "dependencies": { "@babel/plugin-transform-flow-strip-types": "^7.16.0", diff --git a/pages/js-object-to-zod.tsx b/pages/js-object-to-zod.tsx new file mode 100644 index 0000000..ea49c30 --- /dev/null +++ b/pages/js-object-to-zod.tsx @@ -0,0 +1,64 @@ +import ConversionPanel from "@components/ConversionPanel"; +import { EditorPanelProps } from "@components/EditorPanel"; +import Form, { InputType } from "@components/Form"; +import { useSettings } from "@hooks/useSettings"; +import * as React from "react"; +import { useCallback } from "react"; + +interface Settings { + rootName: string; +} + +const formFields = [ + { + type: InputType.TEXT_INPUT, + key: "rootName", + label: "Root Schema Name" + } +]; + +export default function JsObjectToZod() { + const name = "JS Object to Zod Schema"; + + const [settings, setSettings] = useSettings(name, { + rootName: "schema" + }); + + const transformer = useCallback( + async ({ value }) => { + const { jsonToZod } = await import("json-to-zod"); + const objectValue = eval("(" + value + ")"); + return jsonToZod(objectValue, settings.rootName, true); + }, + [settings] + ); + + const getSettingsElement = useCallback( + ({ open, toggle }) => { + return ( + + title={name} + onSubmit={setSettings} + open={open} + toggle={toggle} + formsFields={formFields} + initialValues={settings} + /> + ); + }, + [] + ); + + return ( + + ); +} diff --git a/utils/routes.tsx b/utils/routes.tsx index cb19f16..b7ad1fc 100644 --- a/utils/routes.tsx +++ b/utils/routes.tsx @@ -223,6 +223,12 @@ export const categorizedRoutes = [ path: "/js-object-to-typescript", desc: "An online REPL for converting JS Object to Typescript." }, + { + label: "to Zod Schema", + path: "/js-object-to-zod", + packageUrl: "https://www.npmjs.com/package/json-to-zod", + packageName: "json-to-zod" + } ] }, {