extract-comments
Advanced tools
+1
-1
| { | ||
| "name": "extract-comments", | ||
| "description": "Extract code comments from string or from a glob of files.", | ||
| "version": "0.7.0", | ||
| "version": "0.7.1", | ||
| "homepage": "https://github.com/jonschlinkert/extract-comments", | ||
@@ -6,0 +6,0 @@ "author": { |
+23
-0
@@ -5,2 +5,4 @@ # extract-comments [](http://badge.fury.io/js/extract-comments) | ||
| **Heads up!** As of v0.7.0 this no longer has a `.fromFile()` method to read from the file system. See [extracting from files]. | ||
| This goes well with [code-context](https://github.com/jonschlinkert/code-context). | ||
@@ -84,3 +86,24 @@ | ||
| ## Extracting from files | ||
| Prior to v0.7.0, there was a method to extract code comments from files. Here is the equivalent code to accomplish the same thing: | ||
| ```js | ||
| var fs = require('fs'); | ||
| var extract = require('extract-comments'); | ||
| var mapFiles = require('map-files'); | ||
| function extractComments(patterns, opts) { | ||
| opts = opts || {}; | ||
| opts.name = opts.rename || function(fp) { | ||
| return fp; | ||
| }; | ||
| opts.read = opts.read || function(fp, options) { | ||
| var code = fs.readFileSync(fp, 'utf8'); | ||
| return extract(code, options); | ||
| }; | ||
| return mapFiles(patterns, opts); | ||
| } | ||
| ``` | ||
| ## Related | ||
@@ -87,0 +110,0 @@ * [parse-comments](https://github.com/jonschlinkert/parse-comments): Parse code comments from JavaScript or any language that uses the same format. |
8426
9.09%137
20.18%