zod-to-markdown
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

zod-to-markdown

A utility function to convert Zod schemas to Markdown documentation.

Installation

Install the package using npm:

npm install zod-to-markdown

Usage

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.

Supported Zod Types

The following Zod types are supported by zodSchemaToMarkdown:

  • ZodObject
  • ZodArray
  • ZodString
  • ZodNumber
  • ZodEnum
  • ZodUnion
  • ZodBoolean
  • ZodDefault
  • ZodOptional
  • ZodNullable

Options

The 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);

Contributing

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.

License

This package is open source and available under the MIT License.

Package Sidebar

Install

npm i zod-to-markdown

Weekly Downloads

12

Version

1.0.2

License

MIT

Unpacked Size

6.7 kB

Total Files

9

Last publish

Collaborators

  • o6lvl4