Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@apaleslimghost/zod2md

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apaleslimghost/zod2md

Generate Markdown docs from Zod schemas

next
latest
Source
npmnpm
Version
0.2.0-0
Version published
Maintainers
1
Created
Source

zod2md

NPM package version MIT license Zod peer dependency version CI status

Generate Markdown docs from Zod schemas.

image

Setup

Install the zod2md package (optional):

npm install --save-dev zod2md

Run the CLI. The following arguments are required:

  • entry - path to file which exports Zod schemas,
  • title - heading text for Markdown document,
  • output - path where output Markdown file will be generated.
npx zod2md --entry src/schemas.ts --title "Models reference" --output docs/models.md

Configuration

Although most arguments may be provided directly to the CLI, it may be more convenient to use a configuration file.

For example, create the following zod2md.config.ts and then you can simply run npx zod2md:

import type { Config } from 'zod2md';

const config: Config = {
  entry: 'src/schemas.ts',
  title: 'Models reference',
  output: 'docs/models.md',
};

export default config;

CLI arguments take precedence over configuration file values.

CLI arguments

OptionTypeRequiredDescription
-e, --entrystring[] (*)yesEntry point(s), i.e. paths to modules with Zod schema exports
-t, --titlestringyesHeading text for Markdown document
-o, --outputstringyesOutput file path where Markdown document will be generared
--tsconfigstringnoPath to tsconfig.json to be used when importing entry point(s)
-f, --format'esm' | 'cjs'noModule type to assume when importing entry point(s)
-c, --configstringnoPath to configuration file (default is zod2md.config.{ts,mjs,js})
-h, --helpbooleannoDisplay CLI help and exit

(*) Use --entry PATH_1 --entry PATH_2 to provide multiple paths.

Configuration file reference

PropertyTypeRequiredDescription
entrystring | string[]yesEntry point(s), i.e. paths to modules with Zod schema exports
tsconfigstringnoPath to tsconfig.json to be used when importing entry point(s)
format'esm' | 'cjs'noModule type to assume when importing entry point(s)
titlestringyesHeading text for Markdown document
transformName(name: string | undefined, path: string) => stringnoCustom function for convert exported variable name and file path to display title (*)

(*) Default is to strip Schema-suffix and convert to PascalCase (e.g. userSchema becomes User). In case of a default export, the file path is used.

Programmatic usage

It's also possible to import the core zod2md function to generate the Markdown string in your own code:

import { zod2md } from 'zod2md';

const markdown = await zod2md({
  entry: 'src/schemas.ts',
  title: 'Models reference',
});

Examples

A few examples of inputs and outputs are provided (used in E2E tests):

ExampleSource filesGenerated docs
Prettier config filee2e/fixtures/prettiere2e/__snapshots__/prettier-example.md
Commitlint config objecte2e/fixtures/commitlinte2e/__snapshots__/commitlint-example.md
User REST APIe2e/fixtures/user-rest-apie2e/__snapshots__/user-rest-api-example.md

Contributing

  • Install dependencies with npm install.
  • Run unit tests with npm test (uses Vitest).
  • Run E2E tests with npm run e2e (uses Vitest and Verdaccio).
  • Build library with npm run build (uses tsup).
  • Release new version with npm run release (uses release-it).

Keywords

markdown

FAQs

Package last updated on 23 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts