All Projects → jonschlinkert → Extract Comments

jonschlinkert / Extract Comments

Licence: mit
Extract JavaScript code comments from a string or glob of files.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Extract Comments

Leasot
Parse and output TODOs and FIXMEs from comments in your files
Stars: ✭ 729 (+1925%)
Mutual labels:  comments, parse, extract
Parser
Generate a JSON documentation for a SFC Vue component. Contribute: https://gitlab.com/vuedoc/parser#contribute
Stars: ✭ 74 (+105.56%)
Mutual labels:  parse, extract
Parse Code Context
Parse code context in a single line of javascript, for functions, variable declarations, methods, prototype properties, prototype methods etc.
Stars: ✭ 7 (-80.56%)
Mutual labels:  comments, parse
Parse Comments
Parse JavaScript code comments. Works with block and line comments, and should work with CSS, LESS, SASS, or any language with the same comment formats.
Stars: ✭ 53 (+47.22%)
Mutual labels:  comments, parse
Swiftsoup
SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
Stars: ✭ 3,079 (+8452.78%)
Mutual labels:  parse, extract
Chatistics
💬 Python scripts to parse Messenger, Hangouts, WhatsApp and Telegram chat logs into DataFrames.
Stars: ✭ 814 (+2161.11%)
Mutual labels:  parse, extract
Rdf Dereference.js
Dereference any URL for its RDF contents
Stars: ✭ 18 (-50%)
Mutual labels:  parse
Html React Parser
📝 HTML to React parser.
Stars: ✭ 846 (+2250%)
Mutual labels:  parse
Apifier
Apifier is a very simple HTML parser written in Python based on CSS selectors
Stars: ✭ 5 (-86.11%)
Mutual labels:  parse
3ds Titleid Extractor
This is an open source c++ application that extracts the title ID from a .cia file used by current nintendo systems.
Stars: ✭ 5 (-86.11%)
Mutual labels:  extract
Byte
A low-level, zero-copy, panic-free, binary serializer and deserializer. (parser and encoder)
Stars: ✭ 29 (-19.44%)
Mutual labels:  parse
Algebra Latex
Parse and calculate latex formatted math
Stars: ✭ 20 (-44.44%)
Mutual labels:  parse
Librini
Rini is a tiny, non-libc dependant, .ini file parser programmed from scratch in C99.
Stars: ✭ 25 (-30.56%)
Mutual labels:  parse
Chr
🔤 Lightweight R package for manipulating [string] characters
Stars: ✭ 18 (-50%)
Mutual labels:  extract
Talend Tableau Extract
Tableau Extract output component for Talend
Stars: ✭ 12 (-66.67%)
Mutual labels:  extract
Nativexplatform
Akeeba Portable Tools (cross-platform) - Desktop utilities for use with Akeeba Backup and Akeeba Solo
Stars: ✭ 17 (-52.78%)
Mutual labels:  extract
Quip Export
Export all folders and documents from Quip
Stars: ✭ 28 (-22.22%)
Mutual labels:  comments
Vue Filter Date Parse
Simple date parsing filter for Vue.js
Stars: ✭ 24 (-33.33%)
Mutual labels:  parse
Protodate
Better Javascript Dates.
Stars: ✭ 14 (-61.11%)
Mutual labels:  parse
Excalibur
A web interface to extract tabular data from PDFs
Stars: ✭ 916 (+2444.44%)
Mutual labels:  extract

extract-comments NPM version NPM monthly downloads NPM total downloads Linux Build Status

Uses esprima to extract line and block comments from a string of JavaScript. Also optionally parses code context (the next line of code after a comment).

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your ❤️ and support.

Install

Install with npm:

$ npm install --save extract-comments

Usage

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

// pass a string of JavaScript
extract(string);

Example

var str = '/**\n * this is\n *\n * a comment\n*/\n\n\nvar foo = "bar";\n';
var comments = extract(str);
console.log(comments);

[{
  type: 'block',
  raw: '/**\n * this is\n *\n * a comment\n*/',
  value: 'this is\na comment',
  loc: { start: { line: 1, column: 0 }, end: { line: 5, column: 33 } },
  code:
   { line: 7,
     loc: { start: { line: 7, column: 36 }, end: { line: 7, column: 52 } },
     value: 'var foo = "bar";' }

Extractors

By default, esprima is used for extracting comments. This can easily be changed by passing a function to options.extractor.

The easy way

Use a published module, such as:

Example:

extract(str, {extractor: require('babel-extract-comments')});

If you create a compatible extractor, feel free to do pr or create an issue to add it to the readme!

Roll your own

extract(str, {
  extractor: function(str) {
    // must return an array of tokens with:
    // - type: 'Block', 'CommentBlock', 'Line' or 'CommentLine'
    // - value: the comment inner string
    // - loc: with `start` and `end` line and column
    // example:
    return [
      { 
        type: 'Block',
        {start: { line: 1, column: 0 },
          end: { line: 5, column: 33 }},
        value: ' this is a comment string '
      }
    ];
  }
});

API

extract

Extract comments from the given string.

Params

  • string {String}
  • options {Object}: Pass first: true to return after the first comment is found.
  • tranformFn {Function}: (optional) Tranform function to modify each comment
  • returns {Array}: Returns an array of comment objects

Example

const extract = require('extract-comments');
console.log(extract(string, options));

.block

Extract block comments from the given string.

Params

  • string {String}
  • options {Object}: Pass first: true to return after the first comment is found.
  • returns {String}

Example

console.log(extract.block(string, options));

.line

Extract line comments from the given string.

Params

  • string {String}
  • options {Object}: Pass first: true to return after the first comment is found.
  • returns {String}

Example

console.log(extract.line(string, options));

.first

Extract the first comment from the given string.

Params

  • string {String}
  • options {Object}: Pass first: true to return after the first comment is found.
  • returns {String}

Example

console.log(extract.first(string, options));

Release history

v0.10.0

  • Parsing is now handled by esprima, so only JavaScript can be parsed. I'm working on parsers for other languages and will cross-link those here when they're pushed up.
  • Breaking change: since parsing is now done by esprima, on both the line and block comment objects, the loc.start.pos and loc.end.pos properties have been renamed to loc.start.column and loc.end.column.

v0.9.0

  • Breaking change: lines property was removed from Block comments, since this can easily be done by splitting value

About

Contributing

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

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Related projects

You might also be interested in these projects:

Contributors

Commits Contributor
93 jonschlinkert
3 cazzer
1 architectcodes

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on February 12, 2018.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].