Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docblock

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docblock

DocBlock parser

  • 0.4.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
494
increased by2.28%
Maintainers
3
Weekly downloads
 
Created
Source

DocBlock

Build Status

A powerfull docblock parser for comment blocks. DocBlock isn't tethered to any language. It simply parses docblocks and returns the result as a JSON object.

// banana.js

/**
 * Banana constructor
 *
 * Banana example object
 *
 * @constructor
 */
var Banana = function() {

}

/**
 * DocBlock comment
 *
 * @method peelIt
 * @chainable
 * @param {string} startPoint Sets the peeling start point.
 * @param {function} [callback] Callback function
 * @returns {object} Returns this value
 */
Banana.prototype.peelIt = function(startPoint, callback) {
    return this;
}

Let's parse the banana object.

var fs = require('fs');
var DocBlock = require('docblock');

var source = fs.readFileSync('./banana.js');
var docBlock = new DocBlock();
var result = docBlock.parse(source, 'js');

The result looks like:

[
    {
        "title": "Banana constructor",
        "description": "Creates a banana instance",
        "tags": {
            "isPublic": false,
            "isProtected": false,
            "isPrivate": false,
            "isDeprecated": false,
            "ignore": false,
            "constructor": "Banana"
        },
        "code": "var Banana = function() {\n    \n}",
        "raw": "/**\n * Banana constructor\n *\n * Creates a banana instance\n *\n * @constructor\n */",
        "pos": 80
    },
    {
        "title": "Peels a banana",
        "description": "This method peels a banana and calls a callback",
        "tags": {
            "isPublic": false,
            "isProtected": false,
            "isPrivate": false,
            "isDeprecated": false,
            "ignore": false,
            "method": "peelIt",
            "chainable": true,
            "params": [
                {
                    "type": "string",
                    "name": "startPoint",
                    "description": "Sets the peeling start point."
                },
                {
                    "type": "function",
                    "name": "[callback]",
                    "description": "Callback function"
                }
            ],
            "returns": {
                "type": "object",
                "description": "Returns this value"
            }
        },
        "code": "Banana.prototype.peelIt = function(startPoint, callback) {\n    return this;\n}",
        "raw": "/**\n * Peels a banana\n *\n * This method peels a banana and calls a callback\n * \n * @method peelIt\n * @chainable\n * @param {string} startPoint Sets the peeling start point.\n * @param {function} [callback] Callback function\n * @returns {object} Returns this value\n */",
        "pos": 380
    }
]

Parse markdown

Docblock parse markdown per default. Markdown parsing can be disabled by setting the skipMarkdown option

var docblock = new DocBlock({
    skipMarkdown: true
});

Rules

DockBlock parse all comment blocks per default. The common rules defined in lib/rules/all.js.It comes with 2 predefined programming languages. If you look into lib/rules/ there are predefined rules for Javascript and Styles like CSS/LESS/SASS. These rules are extended rules, they only get load if the second type argument is set in parse().

const dockBlock = new DocBlock()
dockBlock.parse(source, 'js')

This would enable the extended Javascript parsing. The difference is, you get a better result for a language specific parsing. A class tag in css is different then in Javascript. Feel free to add more languages by creating more rules files and send me a PR.

Keywords

FAQs

Package last updated on 07 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc