Skip to content

Commit

Permalink
upgrade deps
Browse files Browse the repository at this point in the history
  • Loading branch information
RnbWd committed Aug 14, 2023
1 parent ab7b5b3 commit ba17dde
Show file tree
Hide file tree
Showing 7 changed files with 453 additions and 1,574 deletions.
10 changes: 0 additions & 10 deletions .travis.yml

This file was deleted.

76 changes: 42 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# [gulp](http://gulpjs.com)-strip-comments

[![Build Status](https://img.shields.io/travis/RnbWd/gulp-strip-comments.svg?style=flat-square)](https://travis-ci.org/RnbWd/gulp-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.0-blue.svg?style=flat-square)](https://github.com/vitaly-t/decomment)
[![David](https://david-dm.org/rnbwd/gulp-strip-comments.svg?style=flat-square)](https://david-dm.org/rnbwd/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
- 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.
Expand All @@ -29,7 +26,6 @@ For JSON and JavaScript this library uses [esprima] to guarantee correct process
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
Expand All @@ -39,13 +35,11 @@ $ npm install --save-dev gulp-strip-comments
## Usage

```js
var gulp = require('gulp');
var strip = require('gulp-strip-comments');
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'));
gulp.task("default", function () {
return gulp.src("template.js").pipe(strip()).pipe(gulp.dest("dist"));
});
```

Expand All @@ -70,10 +64,10 @@ If [esprima] fails to validate the code, it will throw a parsing error. When suc

##### 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)
- `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,...]

Expand All @@ -82,34 +76,49 @@ All matching blocks are then skipped, as well as any comment-like content inside

Examples:

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

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

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

```js
{ignore: /url\([\w\s:\/=\-\+;,]*\)/g}
{
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:

- 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}
{
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.
- `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
- `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`.
Expand All @@ -128,12 +137,11 @@ or validate the input in any way, rather assume it to be HTML, and remove all

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
- `\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)
48 changes: 28 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
'use strict';
"use strict";

var through = require('through2');
var decomment = require('decomment');
var PluginError = require('plugin-error');
var through = require("through2");
var decomment = require("decomment");
var PluginError = require("plugin-error");

function main(options, func) {
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new PluginError("gulp-strip-comments", "Streaming not supported."));
}
file.contents = new Buffer(func(file.contents.toString(), options));
this.push(file);
return cb();
});
return through.obj(function (file, enc, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
if (file.isStream()) {
cb(new PluginError("gulp-strip-comments", "Streaming not supported."));
}
try {
file.contents = Buffer.from(func(file.contents.toString(), options));
this.push(file);
} catch (error) {
this.emit(
"error",
new PluginError("gulp-strip-comments", error, {
fileName: file.path,
}),
);
}
return cb();
});
}

function gulpDecomment(options) {
return main(options, decomment);
return main(options, decomment);
}

gulpDecomment.text = function (options) {
return main(options, decomment.text);
return main(options, decomment.text);
};

gulpDecomment.html = function (options) {
return main(options, decomment.html);
return main(options, decomment.html);
};


module.exports = gulpDecomment;

0 comments on commit ba17dde

Please sign in to comment.