Today's npm package: jsdoc-to-markdown

ยท

2 min read

Today's npm package is jsdoc-to-markdown

Documentation is as important as solving the problem. And whats better than jsdocs for JavaScript apps.

The way you can define a simple JSDoc is as follows:

// index.js

/**
 * Function to generate the Square of a Number
 *
 * @param {Number} x - The number to be squared
 * @return {Number} Squared value of passed Number
 */
const square = (x) => {
  return Math.pow(x, 2);
};

export default square;

And what better than auto generating the Markdown Readme from JSDoc.

Todays package jsdoc-to-markdown will allow you to do so.

All you have to do is to add jsdoc-to-markdown as a dependency and then you can run it via npm scripts

Install as:

npm i -D jsdoc-to-markdown

Add to scripts. in package.json

{
  ...
  "scripts": {
    "gen-docs": "jsdoc2md index.js > API.md"
  }
}

And then executing the command on CLI as:

npm run gen-docs

will give us following API.md file:

<a name="square"></a>

## square(x) โ‡’ <code>Number</code>
Function to generate the Square of a Number

**Kind**: global function  
**Returns**: <code>Number</code> - Squared value of passed Number  

| Param | Type | Description |
| --- | --- | --- |
| x | <code>Number</code> | The number to be squared |

Stay tuned for tomorrow's package of the Day.