How to use the comment-patterns.regex function in comment-patterns

To help you get started, we’ve selected a few comment-patterns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nknapp / multilang-extract-comments / index.js View on Github external
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
github Gruntfuggly / todo-tree / utils.js View on Github external
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;
                    }
                }
            }
        }
    }
github Gruntfuggly / todo-tree / dataProvider.js View on Github external
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;
                        }
                    }
                }
            }
        }

comment-patterns

A list of comment-patterns for different languages

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis

Popular comment-patterns functions

Similar packages