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

extract-comments

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extract-comments - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

README.md

42

.verbrc.md

@@ -8,4 +8,44 @@ # {%= name %} {%= badge('fury') %}

## Usage
```js
var extract = require('extract-comments');
```
Pass file paths or glob patterns for the files with comments to be extracted:
```js
extract('lib/*.js');
```
Results in an object like this:
```js
{
"somefile": {
"filepath": "lib/somefile.js",
"comments": [
// array of code comments here
]
},
"anotherfile": {
"filepath": "lib/another.js",
"comments": [
// array of code comments here
]
}
// ... etc
}
```
Pass `true` as a second parameter to generate an array instead of an object.
## Tests
Run `mocha`
## Author
{%= author.name %}
{%= contrib("jon") %}

@@ -12,0 +52,0 @@ ## License

44

index.js

@@ -1,29 +0,33 @@

var file = require('fs-utils');
var path = require('path');
var fs = require('fs');
var glob = require('globule');
var esprima = require('esprima');
// var extract = function (code) {
// return esprima.parse(code, { comment: true })
// .comments.map(function (comment) {
// return comment.value;
// }).join('\n\n');
// };
var extract = function (code) {
var extractComments = function (code) {
return esprima.parse(code, { comment: true })
.comments.map(function (comment) {
return comment.value;
}).join('\n\n');
return comment;
});
};
module.exports = function(patterns, arr) {
var comments = arr ? [] : {};
var files = glob.find(patterns);
var files = file.find('test/fixtures/*.js');
files.forEach(function(filepath) {
var name = path.basename(filepath, path.extname(filepath));
var str = fs.readFileSync(filepath, 'utf8');
files.forEach(function(filepath) {
var str = file.readFileSync(filepath);
var comments = extract(str);
// console.log(comments);
console.log(JSON.stringify(comments, null, 2));
});
var fileComments = {
filepath: filepath,
comments: extractComments(str)
};
module.exports = extract;
if (arr) {
comments.push(fileComments);
} else {
comments[name] = fileComments;
}
});
return comments;
};
{
"name": "extract-comments",
"description": "Extract code comments from a string.",
"version": "0.1.0",
"description": "Thin wrapper around esprima for extracting code comments from a glob of files.",
"version": "0.1.1",
"homepage": "https://github.com/jonschlinkert/extract-comments",

@@ -24,9 +24,7 @@ "author": {

"keywords": [
"docs",
"documentation",
"generate",
"generator",
"markdown",
"templates",
"verb"
"code",
"comments",
"extract",
"esprima",
"glob"
],

@@ -43,3 +41,2 @@ "main": "index.js",

"fs-utils": "^0.4.3",
"lodash": "^2.4.1",
"mocha": "~1.18.2",

@@ -49,4 +46,5 @@ "verb": "~0.2.0"

"dependencies": {
"esprima": "^1.2.2"
"esprima": "^1.2.2",
"globule": "^0.2.0"
}
}

@@ -0,13 +1,25 @@

var file = require('fs-utils');
var expect = require('chai').expect;
var extract comments = require('../');
var extract = require('../');
var fixtures = 'test/fixtures/**/*.js';
describe('when extract-comments is passed an array of file paths:', function () {
it('should read each file as a string and extract comments from the code.', function () {
var files = file.find(fixtures);
var firstFileName = file.basename(files[0]);
var actual = extract(fixtures);
describe('when foo is passed:', function () {
it('should convert foo to bar.', function () {
var fixture = 'foo';
var actual = 'bar';
var expected = 'bar';
expect(extract comments(actual)).to.eql(expected);
expect(actual).to.be.an('object');
expect(Object.keys(actual)).to.have.length.above(1);
expect(actual).to.have.property(firstFileName);
});
});
describe('when true is passed as a second parameter', function () {
it('should generate an array, instead of an object', function () {
var actual = extract(fixtures, true);
expect(actual).to.be.an('array');
expect(actual).to.have.length.above(1);
});
});

Sorry, the diff of this file is not supported yet

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