New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

comments-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comments-parser

This scripts extracts comments from JavaScript code

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
225
increased by69.17%
Maintainers
1
Weekly downloads
 
Created
Source

node-comments-parser

Description

This scripts extracts comments from JavaScript code. It's built on esprima.

Example

This script will transform example.js:

'use strict';

/**
 * Class description
 * @class Test
 * @constructor
 */
function Test() {
  
}

Test.prototype = {
  /**
   * 
   * @param {string} text
   */
  log: function(text) {
    console.log(text);
  }
};

module.exports = Test;

to Object:

[
  {
	start: 3,
	end: 7,
	jsDoc: true,
	lines: [ 'Class description' ],
	tags: [
	  { name: 'class',       value: 'Test' },
	  { name: 'constructor', value: true   }
	]
  },
  {
	start: 13,
	end: 16,
	jsDoc: true,
	lines: [],
	tags: [
	  { name: 'param', value: '{string} text' }
	]
  }
]

Installation

Install with npm:

npm install node-comments-parser

Usage

var fs     = require('fs');
var parser = require('comments-parser');

var source = fs.readFileSync(__dirname + '/example.js', 'utf-8');
var comments = parser(source);

// Test parsed data
expect(comments[0].lines).to.equal([ 'Class description' ]);

Options

parser(options:Object):

NameDefaultDescription
addEsprimaInfofalseAdd esprima parser data to a comment
parseJsDocTagstrueIf false jsdoc tags processed as text
hideJsDocTagstrueIf parseJsDocTags is true remove tags from lines property
trimtrueTrim lines, values: true, false, 'right'

License

Licensed under MIT.

Keywords

FAQs

Package last updated on 10 Mar 2016

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