Skip to content

brandhaug/zod-to-protobuf

Repository files navigation

zod-to-protobuf

NPM Version NPM Downloads

Summary

Convert Zod schemas to Protocol Buffers definitions.

Installation

npm install zod-to-protobuf

Usage

import { z } from 'zod'
import { zodToProtobuf } from 'zod-to-protobuf'

const schema = z.object({
    name: z.string(),
    age: z.number()
})

const proto = zodToProtobuf(schema)
console.log(proto)

Expected Output

syntax = "proto3";
package default;

message Message {
    string name = 1;
    double age = 2;
}

Options

Option Description Default
packageName Name of the protobuf package default
rootMessageName Name of the protobuf message Message
typePrefix Prefix for each type (empty string)

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Releases

No releases published

Packages

No packages published