zod-meta-parser
v0.0.2
Published
A utility to extract metadata descriptions from Zod schemas into a structured format.
Downloads
29
Maintainers
Readme
Zod Meta Parser
Summary
zod-meta-parser is a utility that extracts metadata descriptions from Zod schemas into a structured format. This is particularly useful for generating documentation or for other meta-programming purposes.
Usage
Basic Example
import { z } from "zod"
import { zodMetaParser } from "zod-meta-parser"
const schema = z.object({
id: z.number(), // no description
email: z.string().describe(JSON.stringify({ unique: true })),
image: z
.string()
.optional()
.describe(JSON.stringify({ s3: true })),
createdAt: z.date().describe("Read-only field"),
}),
console.log(zodMetaParser(schema))Expected Output
{
"email": {
"_meta": {
"unique": true
}
},
"image": {
"_meta": {
"s3": true
}
},
"createdAt": {
"_meta": "Read-only field"
}
}Installation
You can install the package via npm:
npm install zod-meta-parseror via bun (recommended):
bun add zod-meta-parserFeatures
- Extracts metadata descriptions from Zod schemas.
- Supports nested objects and various Zod types.
- Provides a structured output format for easy consumption.
Options
The zodMetaParser function currently does not accept any additional options. All metadata extraction is done based on the structure and descriptions provided in the Zod schema.
Known Issues
- The
zodToJsonSchemalibrary used internally might not handle all Zod types perfectly, such assymbol. Custom handling is added for types not supported natively. - Ensure all fields you want metadata for are described using the
.describe()method in Zod.
Versioning
This package follows semantic versioning. New features and bug fixes will be released as minor or patch updates, while breaking changes will be released as major updates.
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Sponsors
If you enjoy this package, consider sponsoring the project on my GitHub Sponsors page. Your support is greatly appreciated!
Feel free to adjust the links and other details as per your project specifics.
