Registry / serialization / docblock-parser

docblock-parser

JSON →
library1.0.0jsnpmunverified

docblock-parser is a standalone, line-based library designed for parsing JSDoc-style comment blocks. Currently at version 1.0.0, it differentiates itself by offering a less opinionated approach compared to many other parsers, providing extensive customization through configurable regular expression patterns and tag-specific consumer functions. It avoids making fixed assumptions about the values associated with tags, empowering developers to precisely define how lines following a tag are interpreted. The v1.0.0 release notably introduced new configuration options for `docblockPattern`, `startPattern`, `endPattern`, and `linePattern`, significantly enhancing its flexibility for adapting to various docblock formats. While no explicit release cadence is provided, the library aims for stable, configurable parsing solutions.

npm install docblock-parser
INSTALL
IMPORT
SIG · DOCBLOCK-PARSER
D
docblock-parser
serializationjavascriptv1.0.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.

docblockParser
const docblockParser = require('docblock-parser');
import docblockParser from 'docblock-parser';
The package is primarily CommonJS. For ESM environments, ensure proper CommonJS interop or use dynamic import.
docblockParser.parse
const parser = require('docblock-parser'); parser.parse(docstring);
const { parse } = require('docblock-parser');
The `parse` method is a property of the main exported function, not a named export. It can also be called directly if no custom config is needed.
docblockParser.booleanTag
const docblockParser = require('docblock-parser'); const config = { tags: { public: docblockParser.booleanTag } };
import { booleanTag } from 'docblock-parser';
Helper consumers like `booleanTag` are properties of the main `docblockParser` export, not top-level named exports.

This example demonstrates parsing a multi-line docblock with custom tag consumers for standard JSDoc tags like `@public`, `@extends`, `@param`, and `@returns`, as well as a custom `multiline-example` tag.

const docblockParser = require('docblock-parser'); const docstring = [ '/**', ' * Some free text for the block.', ' * This can span multiple lines.', ' *', ' * @public', ' * @extends MyBaseClass', ' * @multiline-example', ' * function exampleFunc() {', ' * console.log("Hello");', ' * }', ' *', ' * With additional description after the code.', ' *', ' * @param {string} foo - The first parameter.', ' * @param {number} bar - The second parameter.', ' * @returns {boolean} True if successful, false otherwise.', ' */' ].join('\n'); const result = docblockParser({ tags: { public: docblockParser.booleanTag, extends: docblockParser.singleParameterTag, 'multiline-example': docblockParser.multilineTilTag, param: docblockParser.multilineTilTag, // JSDoc @param structure is handled by multilineTilTag returns: docblockParser.multilineTilTag // JSDoc @returns structure is handled by multilineTilTag } }).parse(docstring); console.log(JSON.stringify(result, null, 2));
Debug
Known issues
breakingAlthough not explicitly labeled a breaking change, version 1.0.0 introduced configurable patterns for `docblockPattern`, `startPattern`, `endPattern`, and `linePattern`. While existing defaults are maintained, custom configurations from prior versions (if any) might need review if they relied on internal, non-exposed patterns.
fix
Review the new `docblockPattern`, `startPattern`, `endPattern`, and `linePattern` configuration options in the README for custom parsing scenarios.
affects: >=1.0.0
gotchaThe return type of the `text` field in the parsed result can be either a `string` or an `Array` of strings, depending on whether the docblock contains multiple distinct sections of free text. Similarly, tag values can be single items or arrays if a tag appears multiple times.
fix
Always check `Array.isArray(result.text)` and `Array.isArray(result.tags[tagName])` if your logic depends on the cardinality of these fields. Design your consumers to consistently return a single type (e.g., always an array) if uniform handling is required.
affects: >=1.0.0
gotchaThe library is primarily designed for CommonJS (`require`). While modern Node.js environments and bundlers often provide CommonJS interop for ESM `import` statements, direct `import docblockParser from 'docblock-parser';` might lead to issues without proper configuration (e.g., `type: module` in `package.json` and a default export).
fix
Use `const docblockParser = require('docblock-parser');` for robust compatibility in Node.js. If using ESM, ensure your build setup correctly handles CommonJS module interop or consider using dynamic `import('docblock-parser')`.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: docblockParser is not a function
Attempting to call `docblockParser()` when it's `undefined` or not correctly imported.
fix
Ensure `const docblockParser = require('docblock-parser');` is used and the variable name matches. If you're trying to call the `parse` method directly, it's `docblockParser.parse(docstring)` or `docblockParser(config).parse(docstring)`.
TypeError: Cannot read properties of undefined (reading 'parse')
This usually means `docblockParser` itself is `undefined` because the `require` call failed to resolve the module or returned an unexpected value.
fix
Verify that `docblock-parser` is correctly installed via `npm install docblock-parser` and that the `require('docblock-parser')` path is correct relative to your file.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
docblock-parser — npm install docblock-parser · libregistry