1.0.3 • Published 3 years ago

pick-comments v1.0.3

Weekly downloads
2
License
MPL-2.0
Repository
github
Last release
3 years ago

Pick comments from source code

Install

npm i pick-comments

Usage

Write comments in ./test.js:

/*
@myTag
Basic test, right way.
 */
console.log('This is JS program.')

Get comments:

const pickComments = require('pick-comments');
const commentWithFileAsyncIterator = await pickComments('./test.js', 'myTag');
    for await(const commentWithFile of commentWithFileAsyncIterator) {
        /*
        commentWithFile:
        {
          "filePath": "./test.js",
          "commentList": [
            {
              "filePath": "./test.js",
              "lineList": [
                {
                  "filePath": "./test.js",
                  "number": 3,
                  "content": "Basic test, right way."
                }
              ]
            }
          ]
        }
         */
    }

Or just use core function:

const pickComments = require('pick-comments').pickComments;
const fileWithContent = pickComments(
        `
/*
@myTag
Basic test, right way.
 */
        `,
        'myTag',
        './test.js',
    );
/*
fileWithContent:
{
  "filePath": "./test.js",
  "commentList": [
    {
      "filePath": "./test.js",
      "lineList": [
        {
          "filePath": "./test.js",
          "number": 4,
          "content": "Basic test, right way."
        }
      ]
    }
  ]
}
 */
1.0.3

3 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago