Code Comment Generator A Node.js package to automatically generate JSDoc and inline comments for JavaScript and TypeScript codebases. Features
Generates JSDoc for functions and inline comments for variables. Supports both JavaScript and TypeScript files. Configurable comment styles via a JSON configuration file. CLI interface for easy integration into workflows. Extensible for linter/IDE integration.
Installation npm install code-comment-generator
Usage CLI npx code-comment [--config ]
Example: npx code-comment ./src/sample.js --config ./code-comment-config.json
Programmatic const { generateComments } = require('code-comment-generator'); generateComments('./src/sample.js', './code-comment-config.json') .then(() => console.log('Comments generated!')) .catch(err => console.error(err));
Configuration Create a code-comment-config.json file: { "commentStyle": "jsdoc", // or "inline" "includeInline": true, // Include inline comments for variables "outputDir": "output" // Output directory for commented files }
Example Input (sample.js): function add(a, b) { return a + b; } const counter = 0;
Output (output/commented_sample.js): /**
- add - Function to perform its intended operation.
- @param {any} a - Parameter a
- @param {any} b - Parameter b
- @returns {any} Result of the function. */ function add(a, b) { return a + b; } // counter: Stores relevant data for the operation. const counter = 0;
Development To contribute:
Clone the repository. Install dependencies: npm install. Run tests: npm test. Build: npm start.
License MIT