Registry / ai-ml / prototxt-parser

prototxt-parser

JSON →
library1.0jsnpmunverified

prototxt-parser is a JavaScript and TypeScript library designed to parse `.prototxt` files, commonly used for defining neural network architectures in frameworks like Caffe, into standard JavaScript objects. It is built upon the `parsimmon` parser combinator library, which provides a flexible and robust foundation for defining custom grammars. The current stable version is 0.1.5. Given its low version number and specialized use case, its release cadence is likely slow and driven by specific needs rather than a regular schedule. Key differentiators include its explicit focus on `.prototxt` syntax, providing a direct mapping to JavaScript objects, and shipping with TypeScript type definitions for enhanced developer experience. It offers a straightforward API for both browser and Node.js environments, allowing developers to integrate `.prototxt` parsing into various JavaScript-based applications. While it doesn't aim to be a general-purpose configuration parser, its dedicated approach makes it suitable for working with Caffe-related model definitions.

npm install prototxt-parser
INSTALL
IMPORT
SIG · PROTOTXT-PARSER
P
prototxt-parser
ai-mljavascriptv1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

prototxtParser
import * as prototxtParser from 'prototxt-parser';
import prototxtParser from 'prototxt-parser'; // Not a default export import { parse } from 'prototxt-parser'; // The main 'parse' function is a member of the 'prototxtParser' object
The library exports a namespace object, so `import * as` is the correct pattern for TypeScript and modern ESM. The primary parsing function is accessed as `prototxtParser.parse()`.
prototxtParser
const prototxtParser = require('prototxt-parser');
For CommonJS environments (e.g., older Node.js projects), `require` imports the entire module object, consistent with the `* as` import pattern in ESM.
prototxtParser.parse
prototxtParser.parse(prototxtString);
parse(prototxtString); // 'parse' is not a top-level export
The core parsing functionality is exposed as a method on the `prototxtParser` object. Ensure the object itself is correctly imported first.

This quickstart demonstrates how to asynchronously fetch a `.prototxt` file from a URL and then parse its content into a JavaScript object using `prototxt-parser`. It includes error handling and logs the structured output.

import * as prototxtParser from 'prototxt-parser'; async function fetchPrototxt(uri: string): Promise<string> { try { const response = await fetch(new Request(uri)); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.text(); } catch (error) { console.error(`Failed to fetch prototxt from ${uri}:`, error); throw error; } } // Example .prototxt for a SqueezeNet model const uri = "https://raw.githubusercontent.com/DeepScale/SqueezeNet/master/SqueezeNet_v1.1/deploy.prototxt"; (async () => { try { const prototxtString = await fetchPrototxt(uri); const parsedProto = prototxtParser.parse(prototxtString); console.log('Successfully parsed .prototxt:'); console.log(JSON.stringify(parsedProto, null, 2)); // You can now access properties, e.g., console.log(parsedProto.name); } catch (error) { console.error('An error occurred during parsing:', error); } })();
Debug
Known issues
gotchaThe library is specifically designed for `.prototxt` format as used by Caffe. It may not fully support all variations or advanced features of Google's Protocol Buffers text format, which can be more general. If your `.prototxt` deviates significantly from Caffe's conventions, parsing might fail or produce unexpected results.
fix
Validate the `.prototxt` against known Caffe syntax conventions. If encountering issues, manually inspect the `.prototxt` structure or refer to Caffe's documentation for expected format. Consider alternative parsers if your Protobuf text format is non-standard.
affects: >=0.1.0
gotchaThe development activity on the GitHub repository has been minimal since its last update approximately 4 years ago (as of 2026), and the latest release is version 0.1.5. While functional for its intended purpose, expect slow or non-existent updates for new features, bug fixes, or compatibility with newer JavaScript environments or parsing standards.
fix
Be aware that maintaining this package might require manual patches or forks for critical issues. Thorough testing of the parser's output for your specific `.prototxt` files is recommended, especially in production environments. Consider contributing if you need new features or bug fixes.
affects: >=0.1.0
gotchaThe `rawgit.com` CDN mentioned in the original README for browser usage has been deprecated and is no longer actively maintained since 2018. Relying on such deprecated services poses a security risk and can lead to broken deployments.
fix
Avoid using `rawgit.com`. For browser usage, consider bundling the library using tools like Webpack or Rollup, or serve it from a reliable CDN like `unpkg.com` if available and maintained for the specific version.
affects: all
Errors
Common errors & fixes
TypeError: prototxtParser.parse is not a function
The `parse` function is accessed directly as a named export, but it's actually a method of the default (or namespace) export `prototxtParser`.
fix
Ensure you are calling it as `prototxtParser.parse(yourString)`. If using ESM, make sure to `import * as prototxtParser from 'prototxt-parser';` or for CJS, `const prototxtParser = require('prototxt-parser');`.
Module not found: Can't resolve 'prototxt-parser'
The package `prototxt-parser` has not been installed or is not correctly listed in your project's dependencies, or there's a module resolution issue in your bundler/runtime.
fix
Run `npm install prototxt-parser` or `yarn add prototxt-parser` to add it to your project. Verify your bundler (e.g., Webpack, Rollup) or Node.js environment is configured to resolve modules from `node_modules`.
Error: Expected a Protobuf field assignment (like 'key: value' or 'key { ... }') but got something else
The input string is not a valid `.prototxt` format, or contains syntax that the `parsimmon`-based parser does not expect (e.g., missing colons, malformed blocks, unexpected characters).
fix
Carefully review the input string against the `.prototxt` syntax rules, especially for Caffe. Use a `.prototxt` linter if available, or compare against known working examples. The error message from `parsimmon` is usually quite specific about the unexpected token or position.
Upgrade
Version history
1.0latest on npm
Audit
Dependencies
parsimmonrequiredCore parser combinator library used as the foundation for defining the prototxt grammar.
Agent activity
7 hits · last 30 days
node
6
Resources
prototxt-parser — npm install prototxt-parser · libregistry