Removes comments from JSON/JavaScript, CSS/HTML, CPP/H, etc.
npm install decomment-nextdecomment-next
==============
A fork of [decomment] similar to [esprima-next] being a fork of [esprima].
Removes comments from JSON/JavaScript, CSS/HTML, CPP/H, etc.
- Rename to decomment-next
- Uses [esprima-next] instead of [esprima]
- Change to using ES6 module format
- Removing package-lock.json from .gitignore
- Remove getEOL export, which didn't fit in the library in the first place
- Remove support for Node <= 12
- Switch from jamsine-node to jasmine
```
$ npm i decomment-next
``
$ npm test
Testing with coverage:
``
$ npm run coverage
`js
import decomment from 'decomment-next';
const code = 'var t; // comments';
decomment(code); //=> var t;
`
* Removes both single and multi-line comments from JSON, JavaScript and CSS/Text
* Automatically recognizes HTML and removes all from it
* Does not change layout / formatting of the original document
* Removes lines that have only comments on them
* Compatible with CSS3, JSON5 and ECMAScript 6
The library does not support mixed content - HTML with JavaScript or CSS in it.
Once the input code is recognized as HTML, only the HTML comments will be removed from it.
For JSON and JavaScript this library uses [esprima] to guarantee correct processing for regular expressions.
As an example, it can process AngularJS 1.5 Core
in under 100ms, which is 1.1MB ~ 30,000 lines of JavaScript.
This method first checks if the code starts with <, as an HTML, and if so, all entriesoptions
are removed, according to the .
When the code is not recognized as HTML, it is assumed to be either JSON or JavaScript. It is then parsed
through [esprima] for ECMAScript 6 compliance, and to extract details about regular expressions.
If [esprima] fails to validate the code, it will throw a parsing error. When successful, this method will remove
// and /**/ comments according to the options (see below).
##### options.safe ⇒ Boolean
* false (default) - remove all multi-line commentstrue
* - keep special multi-line comments that begin with:
- entries from it according to the options`.
Copyright © 2023 Kristian Kraljic;
Original [decomment] Copyright © 2021 Vitaly Tomilov;
Released under the MIT license.
[decomment]:https://github.com/vitaly-t/decomment
[esprima]:https://github.com/jquery/esprima
[esprima-next]:https://github.com/node-projects/esprima-next