# gulp-strip-comments

> Strip comments from code

Latest version **2.6.0** (published 2023-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-strip-comments
pnpm add gulp-strip-comments
yarn add gulp-strip-comments
bun add gulp-strip-comments
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.6.0 |
| Published | 2023-08-14 |
| First published | 2014-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/gulp-strip-comments) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | rnbwd, vitaly.tomilov |
| Keywords | strip comments, gulpplugin, strip, gulp, comment, decomment, remove, clean, stream, minimize, reduce, remove, comments |

## Links

- npm: https://www.npmjs.com/package/gulp-strip-comments
- Repository: https://github.com/RnbWd/gulp-strip-comments
- Issues: https://github.com/RnbWd/gulp-strip-comments/issues
- npm.io page: https://npm.io/package/gulp-strip-comments

## Dependencies (3)

- [through2](https://npm.io/package/through2.md) ^4.0.2
- [decomment](https://npm.io/package/decomment.md) ^0.9.5
- [plugin-error](https://npm.io/package/plugin-error.md) ^2.0.1

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 2.6.0 (latest) — 2023-08-14
- 2.5.2 — 2018-01-06
- 2.5.1 — 2017-07-22
- 2.5.0 — 2017-07-18
- 2.4.5 — 2017-02-27
- 2.4.4 — 2017-02-09
- 2.4.3 — 2016-04-11
- 2.4.2 — 2016-03-07
- 2.4.1 — 2016-03-07
- 2.4.0 — 2016-03-07
- 2.3.2 — 2016-03-02
- 2.3.1 — 2016-03-02
- 2.3.0 — 2016-03-02
- 2.2.1 — 2016-01-13
- 2.2.0 — 2016-01-09
- … 11 more at https://npm.io/package/gulp-strip-comments/versions

## README

# [gulp](http://gulpjs.com)-strip-comments

[![Coverage Status](https://coveralls.io/repos/RnbWd/gulp-strip-comments/badge.svg?branch=master&service=github)](https://coveralls.io/github/RnbWd/gulp-strip-comments?branch=master)
[![downloads](https://img.shields.io/npm/dt/gulp-strip-comments.svg?style=flat-square)](https://www.npmjs.com/package/gulp-strip-comments)
[![decomment](https://img.shields.io/badge/decomment-v0.9.5-blue.svg?style=flat-square)](https://github.com/vitaly-t/decomment)

> [decomment](https://github.com/vitaly-t/decomment) - removes comments from JSON, JavaScript, CSS, HTML, etc.

[![NPM](https://nodei.co/npm/gulp-strip-comments.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/gulp-strip-comments/)

## Features

- Removes both single and multi-line comments from JSON, JavaScript and CSS/Text
- Automatically recognizes HTML and removes all `<!-- comments -->` 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.

## Performance

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](https://code.angularjs.org/1.5.0/angular.js)
in under 100ms, which is 1.1MB ~ 30,000 lines of JavaScript.

## Install

```sh
$ npm install --save-dev gulp-strip-comments
```

## Usage

```js
var gulp = require("gulp");
var strip = require("gulp-strip-comments");

gulp.task("default", function () {
  return gulp.src("template.js").pipe(strip()).pipe(gulp.dest("dist"));
});
```

## API

See [decomment](https://github.com/vitaly-t/decomment#api) for examples and more information.

```
let strip = require('gulp-strip-comments') // == decomment
```

### [strip(options)](https://github.com/vitaly-t/decomment#decommentcode-options--string)

This method first checks if the code starts with `<`, as an HTML, and if so, all `<!-- comment -->` entries
are removed, according to the `options`.

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 comments
- `true` - keep special multi-line comments that begin with:
  - `<!--[if` - for conditional comments in HTML
  - `/*!` - for everything else (other than HTML)

##### options.ignore ⇒ RegExp | [RegExp,...]

Takes either a single or an array of regular expressions to match against.
All matching blocks are then skipped, as well as any comment-like content inside them.

Examples:

- CSS may contain Base64-encoded strings with comment-like symbols:

```css
src: url(data:font/woff;base64,d09GRg//ABAAAAAAZ);
```

You can isolate all `url(*)` blocks by using:

```js
{
  ignore: /url\([\w\s:\/=\-\+;,]*\)/g;
}
```

- If you want to isolate jsDoc blocks (start with `/**`, followed by a line break, end with `*/`),
  you can use the following:

```js
{
  ignore: /\/\*\*\s*\n([^\*]|(\*(?!\/)))*\*\//g;
}
```

##### options.space ⇒ Boolean

- `false (default)` - remove comment blocks entirely
- `true` - replace comment blocks with white spaces where needed, in order to preserve the original line + column position of every code element.

NOTE: When this option is enabled, option `trim` is ignored.

##### options.trim ⇒ Boolean

- `false (default)` - do not trim comments
- `true` - remove empty lines that follow removed full-line comments

NOTE: This option has no effect when option `space` is enabled.

##### options.tolerant ⇒ Boolean

- `false (default)` - perform strict JavaScript parsing (parser throws on invalid JavaScript)
- `true` - pass `tolerant` flag to [esprima] parser (the parser _may_ choose to continue parsing and produce a syntax tree).
  Usefull for parsing Angular/TypeScript code, for example.

### [strip.text(options)](https://github.com/vitaly-t/decomment#decommenttexttext-options--string)

Unlike the default **strip** method, it instructs the library that `text` is not a JSON, JavaScript or HTML, rather a plain text that needs no parsing or validation, only to remove `//` and `/**/` comments from it according to the `options`.

This method is good for any text file that uses syntax `//` and `/**/` for comments, such as: `.CSS`, `.CPP`, `.H`, etc.

Please note that while the same rules apply for the text blocks (`''`, `""` and \`\`), you should not use this method for JSON or JavaScript, as it can break your regular expressions.

### [strip.html(options)](https://github.com/vitaly-t/decomment#decommenthtmlhtml-options--string)

Unlike the default **strip** method, it instructs the library not to parse
or validate the input in any way, rather assume it to be HTML, and remove all
`<!-- comment -->` entries from it according to the `options`.

### [strip.getEOL()](https://github.com/vitaly-t/decomment#decommentgeteoltext--string)

Returns End-of-Line string used within the `text`, based on the occurrence frequency:

- `\n` - for Unix-encoded text
- `\r\n` - for Windows-encoded text

When impossible to conclude (the same or 0 occurrence), it returns the default End-of-Line for the current OS.

---

[![licence](https://img.shields.io/npm/l/gulp-strip-comments.svg?style=flat-square)](https://opensource.org/licenses/MIT)

---
_Source: https://npm.io/package/gulp-strip-comments · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
