Registry / testing / doctrine

doctrine

JSON →
library0.6.0jsnpmunverified

Doctrine is a specialized JavaScript parser focused solely on extracting and interpreting JSDoc comments from string inputs, rather than processing entire JavaScript files. Maintained by the ESLint team, its current stable version is 3.0.0. Releases appear irregularly, often aligned with maintenance or feature updates related to its integration within the broader ESLint ecosystem. Its primary differentiator is its granular approach to JSDoc parsing, offering fine-grained control over extraction options like unwrapping comment wrappers, filtering by specific tags, and handling parsing errors. It's designed for scenarios where only the documentation blocks need analysis, making it a foundational tool for linters, documentation generators, and code analysis tools that rely on JSDoc annotations.

npm install doctrine
INSTALL
IMPORT
SIG · DOCTRINE
D
doctrine
testingjavascriptv0.6.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.

doctrine
const doctrine = require('doctrine');
import doctrine from 'doctrine';
Primary CommonJS export. Direct default ESM imports (`import doctrine from 'doctrine'`) may work via Node.js interop but explicit CommonJS `require` is the canonical approach.
parse
const { parse } = require('doctrine');
import { parse } from 'doctrine';
The `parse` method is the main API, available as a property of the default export. Direct named ESM imports (`import { parse } from 'doctrine'`) are generally not supported for CommonJS modules without explicit ESM wrappers.
Tag, Type (TypeScript types)
import type { Tag, Type } from '@types/doctrine';
import type { Tag, Type } from 'doctrine';
For TypeScript usage, type definitions are available via the separate `@types/doctrine` package and not bundled with the library itself.

Demonstrates basic JSDoc parsing with various options and filtering tags to obtain an AST representation.

const doctrine = require('doctrine'); // Example 1: Basic JSDoc parsing with multiple options const comment1 = [ '/**', ' * This is a test function.', ' * @param {string} name - The user\'s name.', ' * @param {number} [age=30] - The user\'s age (optional).', ' * @returns {boolean} True if successful, false otherwise.', ' * @deprecated Use `newName` instead.', ' */' ].join('\n'); const ast1 = doctrine.parse(comment1, { unwrap: true, recoverable: true, sloppy: true, lineNumbers: true }); console.log('AST 1 (parsed with full options):', JSON.stringify(ast1, null, 2)); // Example 2: Parsing with specific tags only const comment2 = [ '/**', ' * Another function.', ' * @param {Object} config - Configuration object.', ' * @property {string} config.url - The URL to use.', ' * @todo Implement error handling.', ' */' ].join('\n'); const ast2 = doctrine.parse(comment2, { unwrap: true, tags: ['param', 'property'], recoverable: true }); console.log('\nAST 2 (filtered tags):', JSON.stringify(ast2, null, 2));
Debug
Known issues
breakingVersion 3.0.0 dropped support for Node.js versions older than 6.0.0. Ensure your Node.js environment meets this minimum requirement.
fix
Upgrade your Node.js runtime to version 6.0.0 or higher.
affects: >=3.0.0
breakingVersion 2.0.0 changed the project's license from MIT to Apache License 2.0. Review the new license terms for compatibility with your project.
fix
Verify that the Apache License 2.0 is compatible with your project's licensing requirements.
affects: >=2.0.0
gotchaDoctrine is designed exclusively for parsing JSDoc comment strings, not entire JavaScript files. Passing a full script or arbitrary code will lead to parsing errors or incorrect AST output.
fix
Extract only the JSDoc comment block (e.g., `/** ... */`) as a string before passing it to `doctrine.parse()`.
affects: >=1.0.0
gotchaBy default, `doctrine.parse()` does not tolerate optional parameters defined with square brackets (e.g., `@param {string} [name]`). Parsing such comments requires enabling 'sloppy' mode.
fix
Include `{ sloppy: true }` in the options object when calling `doctrine.parse()` to correctly interpret optional parameters.
affects: >=1.0.0
gotchaWithout the `recoverable` option, `doctrine.parse()` will stop and potentially throw an error upon encountering syntax errors within the JSDoc comment. Errors will not be reported in the AST.
fix
Set `{ recoverable: true }` in the options object to allow parsing to continue after errors and report them in the AST's `problems` array.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Expected JSDoc comment string, received non-comment input or full file.
Attempting to pass an entire JavaScript file or an invalid string that is not a JSDoc comment to `doctrine.parse()`.
fix
Ensure you extract only the raw JSDoc comment block (e.g., `/** ... */`) as a string before invoking `doctrine.parse()`.
JSDoc parsing error: `@param {string} [foo]` syntax error
Using optional parameter syntax with square brackets (e.g., `@param {string} [name]`) without enabling the `sloppy` parsing option.
fix
Pass `{ sloppy: true }` in the options object to `doctrine.parse()` to allow this syntax.
Upgrade
Version history
0.6.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
doctrine — npm install doctrine · libregistry