![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@jackdbd/zod-to-doc
Advanced tools
Inject your [Zod](https://github.com/colinhacks/zod) schemas into your docs.
Inject your Zod schemas into your docs.
I was looking for a way to keep my documentation updated with my Zod schemas. To my surprise, I couldn't find any tool that would output a string representation of a Zod schema. So I decided to write my own. You can use this tool either as a library or as a CLI.
npm install --save-dev @jackdbd/zod-to-doc
📖 API Docs
This project uses API Extractor and api-documenter markdown to generate a bunch of markdown files and a
.d.ts
rollup file containing all type definitions consolidated into a single file. I don't find this.d.ts
rollup file particularly useful. On the other hand, the markdown files that api-documenter generates are quite handy when reviewing the public API of this project.See Generating API docs if you want to know more.
Here are some tables generated using a couple of Zod schemas exported by fixtures/schemas.mjs.
Zod to Doc can be used as a CLI. For example, if you run this command and have the correct placeholder in your document (see this README.md
in raw mode):
ztd --module ./fixtures/schemas.mjs \
--schema car \
--placeholder car-table \
--title '#### Car table'
You get this output:
Key | Default | Description |
---|---|---|
manufacturer | undefined | Car manufacturer |
model | undefined | Car model |
tires | undefined | Array of 4 elements |
year | undefined | Year in which the car was manufactured |
Zod to Doc can also be used as a library. For example, the readme.ts file in this repository uses markdownTableFromZodSchema
to replace a mustache-style placeholder with this markdown table:
Key | Default | Description |
---|---|---|
manufacturer | undefined | Car tire manufacturer |
pressure | 30 | Car tire pressure in PSI |
Key | Default | Description |
---|---|---|
owner | undefined | Owner of the dealership |
employees | undefined | Employees of the dealership (1 to ∞ elements) |
cars | [] | Cars sold by the dealership |
motorcycles | [] | Motorcycles sold by the dealership |
This package uses the debug library for logging.
You can control what's logged using the DEBUG
environment variable.
For example, if you set your environment variables in a .envrc
file, you can do:
# print all logging statements
export DEBUG=ztd:*
Package | Version |
---|---|
debug | ^4.3.4 |
zod | ^3.22.4 |
© 2024 Giacomo Debidda // MIT License
FAQs
Inject your [Zod](https://github.com/colinhacks/zod) schemas into your docs.
The npm package @jackdbd/zod-to-doc receives a total of 35 weekly downloads. As such, @jackdbd/zod-to-doc popularity was classified as not popular.
We found that @jackdbd/zod-to-doc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.