{"id":15769,"library":"prototxt-parser","title":"Prototxt Parser","description":"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.","status":"maintenance","version":"0.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/chaosmail/prototxt-parser","tags":["javascript","caffe","prototxt","parser","typescript"],"install":[{"cmd":"npm install prototxt-parser","lang":"bash","label":"npm"},{"cmd":"yarn add prototxt-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add prototxt-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core parser combinator library used as the foundation for defining the prototxt grammar.","package":"parsimmon","optional":false}],"imports":[{"note":"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()`.","wrong":"import prototxtParser from 'prototxt-parser'; // Not a default export\nimport { parse } from 'prototxt-parser'; // The main 'parse' function is a member of the 'prototxtParser' object","symbol":"prototxtParser","correct":"import * as prototxtParser from 'prototxt-parser';"},{"note":"For CommonJS environments (e.g., older Node.js projects), `require` imports the entire module object, consistent with the `* as` import pattern in ESM.","symbol":"prototxtParser","correct":"const prototxtParser = require('prototxt-parser');"},{"note":"The core parsing functionality is exposed as a method on the `prototxtParser` object. Ensure the object itself is correctly imported first.","wrong":"parse(prototxtString); // 'parse' is not a top-level export","symbol":"prototxtParser.parse","correct":"prototxtParser.parse(prototxtString);"}],"quickstart":{"code":"import * as prototxtParser from 'prototxt-parser';\n\nasync function fetchPrototxt(uri: string): Promise<string> {\n  try {\n    const response = await fetch(new Request(uri));\n    if (!response.ok) {\n      throw new Error(`HTTP error! status: ${response.status}`);\n    }\n    return await response.text();\n  } catch (error) {\n    console.error(`Failed to fetch prototxt from ${uri}:`, error);\n    throw error;\n  }\n}\n\n// Example .prototxt for a SqueezeNet model\nconst uri = \"https://raw.githubusercontent.com/DeepScale/SqueezeNet/master/SqueezeNet_v1.1/deploy.prototxt\";\n\n(async () => {\n  try {\n    const prototxtString = await fetchPrototxt(uri);\n    const parsedProto = prototxtParser.parse(prototxtString);\n    console.log('Successfully parsed .prototxt:');\n    console.log(JSON.stringify(parsedProto, null, 2));\n    // You can now access properties, e.g., console.log(parsedProto.name);\n  } catch (error) {\n    console.error('An error occurred during parsing:', error);\n  }\n})();","lang":"typescript","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"The `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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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');`.","cause":"The `parse` function is accessed directly as a named export, but it's actually a method of the default (or namespace) export `prototxtParser`.","error":"TypeError: prototxtParser.parse is not a function"},{"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`.","cause":"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.","error":"Module not found: Can't resolve 'prototxt-parser'"},{"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.","cause":"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).","error":"Error: Expected a Protobuf field assignment (like 'key: value' or 'key { ... }') but got something else"}],"ecosystem":"npm"}