cdocparser
Advanced tools
Comparing version 0.0.11 to 0.0.12
14
index.js
@@ -0,1 +1,5 @@ | ||
'use strict'; | ||
var stripIndent = require('strip-indent'); | ||
/** | ||
@@ -5,10 +9,8 @@ * Extract all C-Style comments from the input code | ||
var CommentExtractor = (function () { | ||
var docCommentRegEx = /\/\*\*((?:[^*]|[\r\n]|(?:\*+(?:[^*/]|[\r\n])))*)\*\//gm; | ||
var docCommentRegEx = /^[ \t]*\/\*\*((?:[^*]|[\r\n]|(?:\*+(?:[^*/]|[\r\n])))*)\*\//gm; | ||
var cleanComment = function (comment) { | ||
// Split all comments at \r or \n | ||
var commentLines = comment.replace(/^\s+|\s+$/g,'').match(/[^\r\n]+/g); | ||
return commentLines.map(function(line){ | ||
return line.replace(/^\s*\*\s*/, ''); | ||
}); | ||
var removeFirstLine = comment.replace(/^.*?[\r\n]+|[\r\n].*?$/g, ''); | ||
var removeLeadingStar = removeFirstLine.replace(/^[ \t]*\*/gm, ''); | ||
return stripIndent(removeLeadingStar).split(/\n/); | ||
}; | ||
@@ -15,0 +17,0 @@ |
{ | ||
"name": "cdocparser", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Extract C style comments and extract context from source", | ||
@@ -23,3 +23,6 @@ "main": "index.js", | ||
"assert": "^1.1.1" | ||
}, | ||
"dependencies": { | ||
"strip-indent": "^0.1.3" | ||
} | ||
} |
@@ -28,8 +28,8 @@ var assert = require("assert"); | ||
it('should extract more than one comment', function(){ | ||
var comments = extractor.extract('/**\n* Comment\n */ /**\n* Comment\n */ /**\n* Comment\n */'); | ||
var comments = extractor.extract('/**\n * Comment\n */\n/**\n * Comment\n */\n/**\n* Comment\n */'); | ||
assert.equal(comments.length, 3); | ||
}); | ||
it('should ignore block comments like /* comment */', function(){ | ||
var comments = extractor.extract('/**\n* Comment\n */ /*\n* Comment\n */ /**\n* Comment\n */'); | ||
it ('should ignore block comments like /* comment */', function(){ | ||
var comments = extractor.extract('/**\n* Comment\n */\n/*\n* Comment\n */\n/**\n* Comment\n */'); | ||
assert.equal(comments.length, 2); | ||
@@ -43,2 +43,14 @@ }); | ||
}); | ||
it('should ignore `**` in single line comments', function(){ | ||
var comments = extractor.extract('//** \n\n\n */'); | ||
assert.equal(comments.length, 0); | ||
}); | ||
it('should normalize the indentation', function(){ | ||
var comments = extractor.extract('/**\n * @example\n * @include chain(bright, ".test") {\n * color: #fff;\n * }\n */'); | ||
assert.deepEqual(comments[0].lines, ['@example', ' @include chain(bright, ".test") {', ' color: #fff;', ' }' ]); | ||
}); | ||
}); | ||
@@ -45,0 +57,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10236
191
1
+ Addedstrip-indent@^0.1.3
+ Addedstrip-indent@0.1.3(transitive)