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

multilang-extract-comments

Package Overview
Dependencies
Maintainers
3
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multilang-extract-comments

Extract comments from source files of various languages

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17K
increased by15.14%
Maintainers
3
Weekly downloads
 
Created
Source

multilang-extract-comments NPM version Build Status Coverage Status

Extract comments from source files of various languages

Overview

multilang-extract-comments is a package for extracting comments from source-code. It is compatible with the extract-comments-package by Jon Schlinkert:

It provides an extended API, which allows you to extract comments not only from JavaScript files, but also from Python, C, Handlebars etc.

The module was originally forked from extract-comments, with the purpose to allow verb to extract jsdoc-like comments from file other than JavaScript-files. In the end, the module was a complete rewrite of the original module. Now the only common file is spec/javascript-spec.js which is more or less equal to Jon Schlinkert's extract-comments/test.js.

The primary targets are Handlebars-files, for documenting bootprint template-modules.

Example (JavaScript)

For the following string:

/**
 * A javascript multiline-comment
 * with multiple lines
 */
function aLineOfCode () {
}

// A single line comments
// More of it directly below
function anotherFunction () {
  aLineOfCode()
}

anotherFunction()

and the following code

var comments = require('multilang-extract-comments')(string);

The variable comments now contains:

{
  "1": {
    "begin": 1,
    "end": 4,
    "codeStart": 5,
    "content": "A javascript multiline-comment\nwith multiple lines\n",
    "info": {
      "type": "multiline",
      "apidoc": true
    },
    "code": "function aLineOfCode () {"
  },
  "8": {
    "begin": 8,
    "end": 9,
    "codeStart": 10,
    "content": "A single line comments\nMore of it directly below\n",
    "info": {
      "type": "singleline"
    },
    "code": "function anotherFunction () {"
  }
}

Also have a look at the usage example of extract-comments

Example (Handlebars)

For the following string:

Some code here

and the following code

var comments = require('multilang-extract-comments')(string, { filename: 'handlebars.hbs'});

The variable comments now contains:

{
  "1": {
    "begin": 1,
    "end": 4,
    "codeStart": 5,
    "content": "This is an example\nof a handlebars multiline-comment.\n",
    "info": {
      "type": "multiline"
    },
    "code": "Some code here"
  }
}

Example (Custom)

For the following string:

<#
   A powershell multiline-comment
   with multiple lines
 #>
Function  aLineOfCode {
}

# A single line comment
# More of it directly below
Function anotherFunction () {
  Write-Output "test"
}

anotherFunction

and the following code

var options = {
  pattern: {
    name: 'Powershell',
    nameMatchers: ['.ps1'],
    singleLineComment: [{ start: '#' }],
    multiLineComment: [{ start: '<#', middle: '', end: '#>'}]
  }
}
var comments = require('multilang-extract-comments')(string,options);

The variable comments now contains:

{
  "1": {
    "begin": 1,
    "end": 4,
    "codeStart": 5,
    "content": "A powershell multiline-comment\nwith multiple lines\n ",
    "info": {
      "type": "multiline"
    },
    "code": "Function  aLineOfCode {"
  },
  "8": {
    "begin": 8,
    "end": 9,
    "codeStart": 10,
    "content": "A single line comment\nMore of it directly below\n",
    "info": {
      "type": "singleline"
    },
    "code": "Function anotherFunction () {"
  }
}

Also have a look at the usage example of extract-comments

API

TODO

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

see CONTRIBUTING.md

Changelog

see CHANGELOG.md

Author

Nils Knappmeier

License

Copyright © 2015-2017 Nils Knappmeier Released under the MIT license.

Keywords

FAQs

Package last updated on 08 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