Skip to content

Parses a list of comments from an ECMAScript (JavaScript) source file. 0 dependencies, 482 bytes minified + gzipped.

License

Notifications You must be signed in to change notification settings

DrewML/es-comments

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

es-comments

Parses a list of comments from an ECMAScript (JavaScript) source file. 0 dependencies, 482 bytes minified + gzipped.

Install

npm install es-comments

Usage

const parseESComments = require('es-comments');
const someSourceCode = `
    // Some single line comment
    console.log('hello world');
`;
const comments = parseESComments(someSourceCode);
/* Outputs:
    [
      {
        "value": "// Some single line comment",
        "start": 9,
        "end": 36
      }
    ]
*/

Benchmarks

Benchmarks run on a mid-2015 MacBook Pro. Benchmarks compare running time to other similar npm packages.

+--------------+----------------------------+------------------+---------------+---------------+
|              │ es-comments (this package) │ extract-comments │ get-comments  │ comment-regex |
+--------------+----------------------------+------------------+---------------+---------------+
| jQuery 1.7.2 │ 49.36 ops/sec              │ 9.27 ops/sec     │ 22.05 ops/sec │ 1,474 ops/sec |
+--------------+----------------------------+------------------+---------------+---------------+

tl;dr: If location information is not necessary, and some misses are ok, use a RegExp. Otherwise, this package is a good alternative.

About

Parses a list of comments from an ECMAScript (JavaScript) source file. 0 dependencies, 482 bytes minified + gzipped.

Resources

License

Stars

Watchers

Forks

Packages

No packages published