O6lvl4/zod-to-markdown(opens in a new tab)
Language: JavaScript
- stars
- 0
- watchers
- 1
- forks
- 2
- open issues
- 0
- Last updated
- 03/26/2024
Language: JavaScript
A utility function to convert Zod schemas to Markdown documentation.
Install the package using npm:
npm install zod-to-markdown
Import the zodSchemaToMarkdown function from the package:
import { zodSchemaToMarkdown } from 'zod-to-markdown';
Use the function to convert a Zod schema to Markdown:
import { z } from 'zod'; const mySchema = z.object({ name: z.string(), age: z.number(), email: z.string().email(), }); const markdown = zodSchemaToMarkdown(mySchema); console.log(markdown);
Output:
- name: String - age: Number - email: String (email)
The zodSchemaToMarkdown function takes a Zod schema as input and returns a string representing the schema in Markdown format.
The following Zod types are supported by zodSchemaToMarkdown:
ZodObjectZodArrayZodStringZodNumberZodEnumZodUnionZodBooleanZodDefaultZodOptionalZodNullableThe zodSchemaToMarkdown function accepts an optional second parameter indentLevel to specify the initial indentation level. By default, it is set to 0.
const markdown = zodSchemaToMarkdown(mySchema, 2);
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository.
This package is open source and available under the MIT License.