{"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.","language":"javascript","status":"maintenance","last_verified":"Tue Apr 21","install":{"commands":["npm install prototxt-parser"],"cli":null},"imports":["import * as prototxtParser from 'prototxt-parser';","const prototxtParser = require('prototxt-parser');","prototxtParser.parse(prototxtString);"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}