Socket
Socket
Sign inDemoInstall

common-comment-parser

Package Overview
Dependencies
0
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    common-comment-parser

A universal comment parser (supports more than 30 languages)


Version published
Maintainers
1
Install size
14.5 kB
Created

Readme

Source

common-comment-parser

A universal comment parser (supports more than 30 languages)

Usage

npm install common-comment-parser
import parser from 'common-comment-parser';

const context = `// line1

const cc = 111;
/*
block1
*/
console.log(222);

console.log(11); /* block2 */ const c = 111; /* block3 */ console.log(111); // line2


const aaa = 111; // line3

const ddd = `//ddd//ddd//dddd`;
const eee = '//eee//eee//eee';
const fff = "//ddd//ddd//dddd";

const dd = `\`ddddd//dddd`;
const ee = '\'ddddd//dddd';
const ff = "\"ddddd//dddd";
`

const ext = 'js';

console.log(parser(context, ext));
// [
    {
        "type": "CommentLine",
        "value": " line1",
        "loc": {
            "start": {
                "line": 1,
                "column": 3
            },
            "end": {
                "line": 1,
                "column": 9
            }
        }
    },
    {
        "type": "CommentBlock",
        "value": "\nblock1\n",
        "loc": {
            "start": {
                "line": 4,
                "column": 2
            },
            "end": {
                "line": 6,
                "column": 1
            }
        }
    },
    {
        "type": "CommentBlock",
        "value": " block2 ",
        "loc": {
            "start": {
                "line": 9,
                "column": 19
            },
            "end": {
                "line": 9,
                "column": 27
            }
        }
    },
    {
        "type": "CommentBlock",
        "value": " block3 ",
        "loc": {
            "start": {
                "line": 9,
                "column": 47
            },
            "end": {
                "line": 9,
                "column": 55
            }
        }
    },
    {
        "type": "CommentLine",
        "value": " line2",
        "loc": {
            "start": {
                "line": 9,
                "column": 78
            },
            "end": {
                "line": 9,
                "column": 84
            }
        }
    },
    {
        "type": "CommentLine",
        "value": " line3",
        "loc": {
            "start": {
                "line": 12,
                "column": 19
            },
            "end": {
                "line": 12,
                "column": 25
            }
        }
    }
]

parser(context, ext)

  • context: What needs to be parsed

  • ext: File extension

AST

commentsAST {
  type: string;
  value: string;
  loc: {
    start: {
      line: number,
      column: number
    },
    end: {
      line: number,
      column: number
    }
  }
}

License

MIT

Copyright (c) 2019 蓝色的秋风

Keywords

FAQs

Last updated on 10 May 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc