npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

convert-proto-to-ts

v1.7.2

Published

[![CI](https://github.com/joshuaslate/convert-proto-to-ts/actions/workflows/main.yml/badge.svg)](https://github.com/joshuaslate/convert-proto-to-ts/actions/workflows/main.yml) [![npm downloads](https://img.shields.io/npm/dm/convert-proto-to-ts)](https://w

Downloads

62

Readme

Convert Proto to TS

CI npm downloads

A CLI tool to generate TypeScript type definitions from Protocol buffer (.proto) files.

How to Use

Run the following command, then answer the prompts. See below for more configuration options.

npx convert-proto-to-ts

Configuration

To further configure the CLI, create a file called .proto_to_ts_config.js at your project root with a default export matching the following type. The available options are below.

interface Config {
  // tempDir is the path, relative to the root, that the proto files are cloned into if an option is provided for protoGitRepository
  tempDir: string;
  // protoGitRepository is the repository (or repositories) that will be git cloned in order to pull proto definitions
  protoGitRepository?: string | string[];
  // protoPath is the path, relative to the root, to proto definitions on your local file system
  protoPath?: string;
  // outputPath is the path, relative to the root, where the generated TypeScript files will be saved
  outputPath: string;
  // clearOutputPath is true if you'd like to clear the output path before generating new files (default: true)
  clearOutputPath?: boolean;
  // fieldNameKeepCase is true if you'd like to keep field casing instead of camel casing (passed to protobufjs loadSync options), defaults to false
  fieldNameKeepCase?: boolean;
  // namespacesToIgnore is an array of namespaces that you would like to avoid resolving types for, e.g., ["google"]
  namespacesToIgnore?: string[];
  /**
   * typeNameCase determines the casing for generated interface types
   *  Available options:
   *    camelCase (e.g., camelCase)
   *    constantCase (e.g., CONSTANT_CASE)
   *    pascalCase (e.g., PascalCase)
   *    snakeCase (e.g., snake_case)
   *
   *    default: pascalCase
   */
  typeNameCase: TypeNameCase;
  /**
   * enumNameCase determines the casing for generated enum types
   *  Available options:
   *    camelCase (e.g., camelCase)
   *    constantCase (e.g., CONSTANT_CASE)
   *    pascalCase (e.g., PascalCase)
   *    snakeCase (e.g., snake_case)
   *
   *    default: pascalCase
   */
  enumNameCase: TypeNameCase;
  /**
   * typeNameTemplate determines how the generated interface types are named.
   *  Available variables:
   *    parentNodeNames
   *    typeName
   *
   *    default: "{{parentNodeNames}}{{typeName}}"
   */
  typeNameTemplate: string;
  /**
   * enumNameTemplate determines how the generated enum types are named.
   *  Available variables:
   *    parentNodeNames
   *    typeName
   *
   *    default: "{{parentNodeNames}}{{typeName}}"
   */
  enumNameTemplate: string;
  /**
   * typeNameIgnoreParentNodeNames is an array of parent node names in the generated type names that you'd like to leave off.
   * This is only used when {{parentNodeNames}} is included in typeNameTemplate/enumNameTemplate.
   * For example, if the package is your_app.services.auth.v1, and the message name is RegisterRequest, ["your_app", "services"] would yield:
   * export interface AuthV1RegisterRequest {}
   */
  typeNameIgnoreParentNodeNames?: string[];
  // generatedTypeOverrides is a Record<string, string> for type overrides (key == Protobuf type, value == TypeScript type)
  generatedTypeOverrides?: Record<string, string>;
  // generatedTypeComments is a Record<string, string> for leading comments for types, e.g., { 'google.protobuf.Timestamp': 'format: date-time' }
  generatedTypeComments?: Record<string, string>;
  // generateIndexFile is true if an index.ts file exporting all generated types should be generated (default: true)
  generateIndexFile?: boolean;
  /**
   * generateEnumType can be set to either 'union' or 'enum'
   *    union: export type FakeEnum = 'FAKE_ENUM_UNSPECIFIED' | 'FAKE_ENUM_VALUE';
   *    enum: export enum FakeEnum { Unspecified: 'FAKE_ENUM_UNSPECIFIED', Value: 'FAKE_ENUM_VALUE' };
   * Nested enums will always be generated as inline union types, because enums can't be declared inline
   */
  generateEnumType?: 'union' | 'enum';
  /**
   * fileHeaderCommentTemplate can be set to define a header that will be prepended to all generated TypeScript files. Variables available:
   *    generationTimestamp, sourceFile
   * Example: "DO NOT EDIT! Types generated from {{sourceFile}} at {{generationTimestamp}}."
   */
  fileHeaderCommentTemplate?: string;
  /**
   * indexFileHeaderCommentTemplate can be set to define a header that will be prepended to the generated TypeScript file (if enabled). Variables available:
   *    generationTimestamp
   * Example: "DO NOT EDIT! Types generated at {{generationTimestamp}}."
   */
  indexFileHeaderCommentTemplate?: string;
  /**
   * customInterfaceBuilder can be set to provide custom overrides for how interfaces are generated. This allows you to assert more control over the
   *  generated types. For example, you could use this to generate interfaces that have generic type parameters based on proto annotations. See the
   *  .proto_to_ts_config.js in the root of this project for an example. Returning null will skip the interface being generated. Be careful there are
   *  no dependencies on the skipped interface.
   */
  customInterfaceBuilder?: CustomInterfaceBuilder;
  /**
   * customMemberBuilder can be set to provide custom overrides for how fields (interface members) are generated. This allows you to assert more control over the
   * generated types. For example, you can use this to generate a custom comment for a member or to have more control over how oneofs are generated.
   * Returning null will skip the member being generated. Returning undefined will use the default member builder.
   */
  customMemberBuilder?: CustomMemberBuilder;
  /**
   * customFileBuilder allows you to generate entire custom files. This is helpful in the case where you'd like to generate something like an API client
   * based on the Protobuf service definitions.
   */
  customFileBuilder?: CustomFileBuilder;
  /**
   * customEnumBuilder allows you to generate custom enums. This allows you to assert more control over the generated types.
   */
  customEnumBuilder?: CustomEnumBuilder;
}