This package, `tagged-comment-parser`, provides a straightforward utility for extracting structured data from specially formatted string comments. Its current stable version is 1.3.8. The library focuses on simplicity, offering two main functions: `parse` for strict parsing which throws errors on invalid input, and `tryParse` for a more resilient approach that returns an empty object on invalid input rather than an exception. It handles various tag syntaxes, including boolean flags (`@tag`), key-value pairs (`@tag:value`), and array-like values (`@tag(val1, "val2")`). The library ships with TypeScript types, enhancing developer experience. It appears to have a stable, though not rapid, release cadence, characteristic of a focused utility. Its key differentiator is its minimal API and focused scope on comment parsing, contrasting with larger AST parsing libraries.
npm install tagged-comment-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of `parse` and `tryParse` with various tag syntaxes and input types, logging the structured output.
Wrap calls to `parse` in a `try/catch` block, or use `tryParse(input)` instead.
Standardize your comment format or implement post-parsing logic to handle positional ambiguity if needed.
Use TypeScript type guards or runtime checks (e.g., `typeof result.tags.myTag === 'string'`) to handle different tag value types.
Consult the package's changelog or migration guide for detailed instructions when upgrading to a new major version.
Ensure the input to `parse` is always a valid string. Use `tryParse(input ?? '')` or `parse(String(input))` for potentially non-string inputs.
Migrate to ES module imports: `import { parse, tryParse } from 'tagged-comment-parser';`. Ensure your project is correctly configured for ESM.Access tags with a type guard (e.g., `if ('myTag' in result.tags) { /* ... */ }`) or cast the result to a more specific type if known: `const result = parse(...) as CommentParseResult & { tags: { myTag?: boolean } };`No dependency data recorded yet.