Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function extract (str, fn, options) {
if (typeof fn !== 'function' && typeof options === 'undefined') {
options = fn
fn = identityFunction
}
// default filename is a javascript file (for backwards compatibility)
var filename = (options && options.filename) || 'abc.js'
var regexp = {}
// check for custom comment pattern
if (options && options.pattern) {
regexp = require('comment-patterns/build/variations/regexes')(options.pattern)
} else {
regexp = cp.regex(filename)
}
var result = {}
// This variable is an intermediate
// store for comments that have been extracted,
// but the next-line-of-code is still missing
// This property is not set until the following
// comment is processed.
var lastComment = null
var codeStart = null
var codeEnd = null
new Scanner(regexp)
.on('comment', function (comment) {
// Temporary save the comment
lastComment = comment
function removeBlockComments( text, fileName )
{
var commentPattern;
try
{
commentPattern = commentPatterns( fileName );
}
catch( e )
{
}
if( commentPattern && commentPattern.multiLineComment && commentPattern.multiLineComment.length > 0 )
{
commentPattern = commentPatterns.regex( fileName );
if( commentPattern && commentPattern.regex )
{
var commentMatch = commentPattern.regex.exec( text );
if( commentMatch )
{
for( var i = commentPattern.cg.contentStart; i < commentMatch.length; ++i )
{
if( commentMatch[ i ] )
{
text = commentMatch[ i ];
break;
}
}
}
}
}
var pathElement;
var name = match.match.substr( match.column - 1 );
var commentPattern;
try
{
commentPattern = commentPatterns( match.file );
}
catch( e )
{
}
if( commentPattern && commentPattern.multiLineComment && commentPattern.multiLineComment.length > 0 )
{
commentPattern = commentPatterns.regex( match.file );
if( commentPattern && commentPattern.regex )
{
var commentMatch = commentPattern.regex.exec( name );
if( commentMatch )
{
for( var i = commentPattern.cg.contentStart; i < commentMatch.length; ++i )
{
if( commentMatch[ i ] )
{
name = commentMatch[ i ];
break;
}
}
}
}
}