Registry / devops / pb-parser

pb-parser

JSON →
library0.1.6jsnpmunverified

pb-parser is a lightweight protobuf parser written in TypeScript, version 0.1.6. It provides a simple API to parse protocol buffer definitions (proto files) into an AST. This package is maintained on an as-needed basis with no fixed release cadence. Compared to alternatives like protobufjs, pb-parser focuses solely on parsing without code generation or serialization, making it a smaller dependency for projects that only need to analyze proto syntax.

npm install pb-parser
INSTALL
IMPORT
SIG · PB-PARSER
P
pb-parser
devopsjavascriptv0.1.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'pb-parser'
import parse from 'pb-parser'
parse is a named export, not default.
SyntaxType
import { SyntaxType } from 'pb-parser'
Type export for TypeScript users.
FileNode
import type { FileNode } from 'pb-parser'
import { FileNode } from 'pb-parser'
FileNode is a type, use 'import type' to avoid runtime overhead.

Parses a protobuf definition string and accesses the syntax version using the exported enum.

import { parse, SyntaxType } from 'pb-parser'; const proto = ` syntax = "proto3"; package example; message Person { string name = 1; int32 age = 2; } `; const ast = parse(proto); console.log(ast.syntax); // SyntaxType.PROTO3 if (ast.syntax === SyntaxType.PROTO3) { console.log('Parsed proto3 file'); }
Debug
Known issues
gotchaparse() does not validate semantics - only syntax. Malformed proto may not throw errors.
fix
Validate the AST manually or use a more comprehensive tool like protobufjs for full validation.
affects: >=0.0.0
deprecatedThe package currently lacks support for some proto3 features like 'optional' keyword (as of 0.1.6).
fix
Use alternative parser if you need full proto3 support.
affects: <0.2.0
gotchaImports within proto files are not resolved; parse() only handles a single file.
fix
Combine multiple files manually before parsing or use a multi-file parser.
affects: >=0.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected token, expected ";" (2:0) 1 | syntax = "proto3" > 2 | package foo; | ^
Missing semicolon after syntax statement.
fix
Add semicolon: syntax = "proto3";
TypeError: parse is not a function
Incorrect default import instead of named import.
fix
Use: import { parse } from 'pb-parser'
Cannot find module 'pb-parser' or its corresponding type declarations.
TypeScript cannot resolve the module because of missing types or incorrect module resolution.
fix
Ensure you have installed the package (npm install pb-parser) and set "esModuleInterop": true in tsconfig.json if needed.
Upgrade
Version history
0.1.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
pb-parser — npm install pb-parser · libregistry