🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

comment-regex

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comment-regex

Regular expression for matching JavaScript comments

2.0.0
latest
Source
npm
Version published
Weekly downloads
16K
40.34%
Maintainers
1
Weekly downloads
 
Created
Source

comment-regex

Regular expression for matching JavaScript comments

This is pretty fragile and created for performance reasons where using a real parser would be overkill. Do not use it with untrusted user input.

Install

npm install comment-regex

Usage

import {commentRegex} from 'comment-regex';

// Contains a comment
commentRegex().test('/* unicorn */\nvar foo = true;');
//=> true

// Get the contents of a comment
commentRegex().exec('/* unicorn */\nvar foo = true;')[2].trim();

// Get all the comments
'/* unicorn */\nvar foo = true;\nvar unicorn = "rainbows"; // rainbow'.match(commentRegex());
//=> ['/* unicorn */', ' // rainbow']

API

The contents of the comment is in the first submatch.

commentRegex()

Returns a regex for matching line and block comments.

lineCommentRegex()

Returns a regex for matching line comments.

blockCommentRegex()

Returns a regex for matching block comments.

Keywords

text

FAQs

Package last updated on 13 Oct 2021

Did you know?

Socket

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