{"_id":"@000alen/fuzzy-xml","name":"@000alen/fuzzy-xml","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@000alen/fuzzy-xml","version":"1.0.0","main":"dist/index.js","types":"dist/index.d.ts","type":"module","repository":{"type":"git","url":"git+https://github.com/000alen/fuzzy-xml.git"},"author":{"name":"Alen Rubilar","email":"lclc.alen@gmail.com"},"license":"MIT","packageManager":"yarn@4.5.1","scripts":{"prepare":"ts-patch install -s","build":"tsc"},"devDependencies":{"ts-patch":"^3.2.1","typescript":"5.5.4","typescript-transform-paths":"^3.5.1"},"workspaces":["examples/*"],"_id":"@000alen/fuzzy-xml@1.0.0","gitHead":"15e354a2f3fefccf07637539a307de66e968b593","description":"![License](https://img.shields.io/badge/license-MIT-blue.svg)","bugs":{"url":"https://github.com/000alen/fuzzy-xml/issues"},"homepage":"https://github.com/000alen/fuzzy-xml#readme","_nodeVersion":"20.12.2","_npmVersion":"10.9.0","dist":{"integrity":"sha512-1E/M509UmlG7ux2GfVnX9cRotDZUxYZYPdSVkwyJKHH/FpqS1p2n4enqdMTji++DWtUtlvopj3U4h7Avt5zt0Q==","shasum":"360ec855de02860d86fc784be95c2bb7da8abdd1","tarball":"https://registry.npmjs.org/@000alen/fuzzy-xml/-/fuzzy-xml-1.0.0.tgz","fileCount":7,"unpackedSize":14580,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFuF5N3rjWypWzWRnhPn3Gc5uHTEOYQZEJ3R6xZ8uIlwAiEAopu3Ot5sTYlSfQWewMBd14qh8fmB3VHfRdSsgaT7CyI="}]},"_npmUser":{"name":"000alen","email":"lclc.alen@gmail.com"},"directories":{},"maintainers":[{"name":"000alen","email":"lclc.alen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fuzzy-xml_1.0.0_1729519242179_0.10724548979850357"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-21T14:00:42.074Z","1.0.0":"2024-10-21T14:00:42.358Z","modified":"2024-10-21T14:00:42.660Z"},"maintainers":[{"name":"000alen","email":"lclc.alen@gmail.com"}],"description":"![License](https://img.shields.io/badge/license-MIT-blue.svg)","homepage":"https://github.com/000alen/fuzzy-xml#readme","repository":{"type":"git","url":"git+https://github.com/000alen/fuzzy-xml.git"},"author":{"name":"Alen Rubilar","email":"lclc.alen@gmail.com"},"bugs":{"url":"https://github.com/000alen/fuzzy-xml/issues"},"license":"MIT","readme":"# fuzzy-xml\n\n![License](https://img.shields.io/badge/license-MIT-blue.svg)\n\n**fuzzy-xml** is a robust TypeScript library designed to parse semi-structured, XML-like tags interleaved with natural language text, commonly found in responses from Large Language Models (LLMs). It gracefully handles fuzzy and malformed tags, ensuring reliable extraction of structured data from otherwise unpredictable outputs.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Basic Example](#basic-example)\n  - [Handling Nested Tags](#handling-nested-tags)\n  - [Error Handling](#error-handling)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Features\n\n- **Fuzzy Parsing**: Handles semi-structured inputs with interleaved natural language and XML-like tags.\n- **Error Tolerance**: Continues parsing despite malformed or incomplete tags.\n- **Nested Tag Support**: Accurately parses nested tags, maintaining hierarchical relationships.\n- **Lightweight**: Minimal dependencies, ensuring fast and efficient parsing.\n- **Extensible**: Easily extendable to handle custom parsing requirements.\n- **TypeScript Support**: Provides strong type definitions for enhanced developer experience.\n\n## Installation\n\nYou can install **fuzzy-xml** via npm:\n\n```bash\nnpm install @000alen/fuzzy-xml\n```\n\nOr using yarn:\n\n```bash\nyarn add @000alen/fuzzy-xml\n```\n\n## Usage\n\n### Basic Example\n\n```typescript\nimport { FuzzyXMLParser, ParsedNode } from \"@000alen/fuzzy-xml\";\n\nconst llmResponse = `\nHere is the summary of our findings:\n\n<findings>\n  The indemnification clause is overly broad.\n  Additionally, the limitation of liability is insufficient.\n  <details>\n    This could expose us to significant risks.\n  </details>\n</findings>\n\nPlease review these points at your earliest convenience.\n\n<recommendations>\n  We should renegotiate the indemnification terms.\n  Also, consider increasing the liability cap.\n</recommendations>\n\nThank you.\n`;\n\nconst parser = new FuzzyXMLParser(llmResponse);\nconst parsedNodes: ParsedNode[] = parser.parse();\n\nconsole.log(JSON.stringify(parsedNodes, null, 2));\n```\n\n**Output:**\n\n```json\n[\n  {\n    \"content\": \"Here is the summary of our findings:\",\n    \"children\": []\n  },\n  {\n    \"tagName\": \"findings\",\n    \"content\": \"The indemnification clause is overly broad.\\nAdditionally, the limitation of liability is insufficient.\",\n    \"children\": [\n      {\n        \"tagName\": \"details\",\n        \"content\": \"This could expose us to significant risks.\",\n        \"children\": []\n      }\n    ]\n  },\n  {\n    \"content\": \"Please review these points at your earliest convenience.\",\n    \"children\": []\n  },\n  {\n    \"tagName\": \"recommendations\",\n    \"content\": \"We should renegotiate the indemnification terms.\\nAlso, consider increasing the liability cap.\",\n    \"children\": []\n  },\n  {\n    \"content\": \"Thank you.\",\n    \"children\": []\n  }\n]\n```\n\n### Handling Nested Tags\n\nThe parser accurately captures nested structures, maintaining the hierarchy of tags and their respective contents.\n\n```typescript\nconst complexResponse = `\n<report>\n  Overview:\n  <section>\n    <title>Revenue Growth</title>\n    Our revenue increased by 20%.\n    <details>\n      Major contributors include product A and product B.\n    </details>\n  </section>\n  <section>\n    <title>Profit Margins</title>\n    Profit margins remained stable.\n  </section>\n</report>\n`;\n\nconst parser = new FuzzyXMLParser(complexResponse);\nconst parsedNodes = parser.parse();\n\nconsole.log(JSON.stringify(parsedNodes, null, 2));\n```\n\n**Output:**\n\n```json\n[\n  {\n    \"tagName\": \"report\",\n    \"content\": \"Overview:\",\n    \"children\": [\n      {\n        \"tagName\": \"section\",\n        \"content\": \"Our revenue increased by 20%.\",\n        \"children\": [\n          {\n            \"tagName\": \"title\",\n            \"content\": \"Revenue Growth\",\n            \"children\": []\n          },\n          {\n            \"tagName\": \"details\",\n            \"content\": \"Major contributors include product A and product B.\",\n            \"children\": []\n          }\n        ]\n      },\n      {\n        \"tagName\": \"section\",\n        \"content\": \"Profit margins remained stable.\",\n        \"children\": [\n          {\n            \"tagName\": \"title\",\n            \"content\": \"Profit Margins\",\n            \"children\": []\n          }\n        ]\n      }\n    ]\n  }\n]\n```\n\n### Error Handling\n\n**fuzzy-xml** is designed to handle malformed tags without interrupting the parsing process. Text outside of tags or incorrect tag formats are treated as plain text.\n\n```typescript\nconst malformedResponse = `\nHere is an overview:\n\n<findings>\n  The terms are unclear.\n  <details>\n    Missing clauses on liability.\n  <!-- Missing closing tag for findings\n\nRecommendations follow.\n\n<recommendations>\n  Clarify liability clauses.\n  Add termination conditions.\n</recommendations>\n`;\n\nconst parser = new FuzzyXMLParser(malformedResponse);\nconst parsedNodes = parser.parse();\n\nconsole.log(JSON.stringify(parsedNodes, null, 2));\n```\n\n**Output:**\n\n```json\n[\n  {\n    \"content\": \"Here is an overview:\",\n    \"children\": []\n  },\n  {\n    \"tagName\": \"findings\",\n    \"content\": \"The terms are unclear.\",\n    \"children\": [\n      {\n        \"tagName\": \"details\",\n        \"content\": \"Missing clauses on liability.\",\n        \"children\": []\n      }\n    ]\n  },\n  {\n    \"content\": \"<!-- Missing closing tag for findings\\n\\nRecommendations follow.\",\n    \"children\": []\n  },\n  {\n    \"tagName\": \"recommendations\",\n    \"content\": \"Clarify liability clauses.\\nAdd termination conditions.\",\n    \"children\": []\n  }\n]\n```\n\n## Contributing\n\nContributions are welcome! Whether it's reporting bugs, suggesting features, or submitting pull requests, your help is appreciated.\n\n1. **Fork the Repository**\n2. **Create a Feature Branch**\n   ```bash\n   git checkout -b feature/YourFeature\n   ```\n3. **Commit Your Changes**\n   ```bash\n   git commit -m \"Add some feature\"\n   ```\n4. **Push to the Branch**\n   ```bash\n   git push origin feature/YourFeature\n   ```\n5. **Open a Pull Request**\n\nPlease ensure your code adheres to the existing style and includes relevant tests.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n","readmeFilename":"README.md"}