0.1.3 • Published 1 year ago

comment-finder v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

comment-finder

npm Package NPM Downloads Build Status License: MIT

a comment parser for code language

Features

  • Support for Multiple Languages: While the library can automatically detect the language of the provided code snippet, you can also explicitly set the language to JavaScript, TypeScript, Python, and others.
  • Custom Regular Expressions: The library allows users to define custom regular expressions for matching comments.
  • Position Information: Optionally return the location of each comment within the source code.

Install

npm install --save comment-finder

Usage

import { parse } from 'comment-finder'

parse({
    content:`
        // this is a log
    `,
    filter:[CommentType.singleLineComment]
})

/*
output:
[
  {
    match: '// this is a log',
    startLine: 0,
    endLine: 0,
    startColumn: 0,
    endColumn: 15,
    content: ' this is a log',
    type: 0
  }
]

*/

Config

PropertyTypeDescriptionOptional
contentstring要解析的代码字符串No
filterCommentType[]需要解析的注释类型,如果不指定,则会根据语言类型自动选择Yes
regExpIRegExp[]自定义正则匹配Yes
needPosboolean是否需要返回注释的位置信息Yes
languagestring代码的语言,如:JavaScript, TypeScript, Python 等Yes
beautifyOutputboolean是否美化注释内容后输出Yes
mergeSingleLineboolean是否将连行的单行注释合并成一条输出Yes

License

MIT © hcl-z

0.1.2

1 year ago

0.1.3

1 year ago

0.1.1

1 year ago

0.0.3

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.6

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago