Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
comment-eraser
Advanced tools
comment-eraser is a Node.js package that removes comments from JavaScript files efficiently. It offers customizable options for tailoring the comment removal process and includes an interactive mode for selective file cleanup. Overall, comment-eraser simp
Removing comments from JavaScript files has never been this easy.
Please consider following this project's author, Sina Bayandorian, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save comment-eraser
const { erase } = require('comment-eraser');
// reads eraser.config.json - falls back to DEFAULT_CONFIG if not specified
// removes comments from specified .js files
erase();
const { eraseFromString } = require('comment-eraser');
// config
const config = {
type: 'both',
code: jsCodeString
};
const [commentsRemoved, removedCharsCount, elapsedTime] = eraseFromString(config);
console.log(commentsRemoved, removedCharsCount, elapsedTime);
Erases comments from the specified files - Read Configuration and Interactive Mode for more.
Returns
{ filePath, outputPath, commentsRemoved, removedCharsCount, elapsedTime }[] | undefined
: { String, String, String, Number, TimeStamp }[ ] | undefinedNotes
interactive
is set to true
the logs will no longer be available to you and the function will return undefined
Example
// note that this function needs no argument to be passed to it
// since it reads and utilizes eraser.config.json
const { erase } = require('comment-eraser');
const logs = erase();
console.log(logs);
Erases comments from the given string
.
Params
code
: Stringconfig
: Object
type
: 'both' | 'inline' | 'block'excludePatterns
: String[ ] - specifies comment patterns not to be excluded - default is []
RegExp
pattern or an error will be thrownoutput
: { path: String, file: String, append: Boolean }
path
: String - default is ''
file
: String - default is 'output.js'
append
: Boolean - default is false
Returns
[commentsRemoved, removedCharsCount, outputPath, elapsedTime]
: [ String, Number, (String | null), TimeStamp ]Notes
output
object is passed then the result won't be written to a fileoutput
config pass {}
as the output
optionoutput
option:
append
set to true
- all results will be appended to the fileappend
set to false
- only the result of the last function call will be written to the fileExample
// note that in this example no new file is created
// as no config or output option is passed down to the function
const { eraseFromString } = require('comment-eraser');
const sampleString = '// a comment \n sample js code';
const [ commentsRemoved, removedCharsCount, elapsedTime ] = eraseFromString(sampleString);
console.log(commentsRemoved, removedCharsCount, outputPath, elapsedTime);
utilized by the erase function
eraser.config.json
type
: 'both' | 'inline' | 'block' specifies the comment type to be erased
both
: default - all commentsinline
: inline comments onlyblock
: block comments onlyinclude
: String | String[ ] - glob pattern - js files to be included - default is ./**/*
exclude
: String[ ] - glob pattern - js files to be excluded - default is []
writeToOutput
: Boolean - specifies whether to write the output string into specific files - default is true
replace
, outputDir
, postfix
replace
: Boolean - specifies whether to replace the file's content after removing the comments or not - default is false
outputDir
and postfix
if specifiedoutputDir
: String - specifies the directory in which the new files are going the be created - default is no-comments
postfix
: String - specifies the postfix to be added to the new files generated after the comment removal process - default is -no-comments
excludePatterns
: String[ ] - specifies comment patterns not to be excluded - default is []
RegExp
pattern or an error will be throwninteractive
: Boolean - activates interactive mode if set to true
- default is false
In this mode a temp file named prelog
is created in which you can specify which files to include or not include one by one and then hit Enter
to continue the process based on the prelog
file
interactive
to true
to activate in eraser.config.json
=y
: include file - default for all files=n
: exclude fileprelog
file will be removed after the process is finishedExmaple - prelog
sample.js=y
sample-2.js=n
FAQs
comment-eraser is a Node.js package that removes comments from JavaScript files efficiently. It offers customizable options for tailoring the comment removal process and includes an interactive mode for selective file cleanup. Overall, comment-eraser simp
The npm package comment-eraser receives a total of 0 weekly downloads. As such, comment-eraser popularity was classified as not popular.
We found that comment-eraser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.