[//]: # ( )
[//]: # (This file is automatically generated by a `metapak`)
[//]: # (module. Do not change it  except between the)
[//]: # (`content:start/end` flags, your changes would)
[//]: # (be overridden.)
[//]: # ( )
# gulp-cond
> Ternary operator for Gulp.

[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/nfroidure/gulp-cond/blob/main/LICENSE)


[//]: # (::contents:start)

## Usage

First, install `gulp-cond` as a development dependency:

```shell
npm install --save-dev gulp-cond
```

Then, use it to conditionally pipe plugins in your `gulpfile.js`:

```js
import cond from 'gulp-cond';
var prod = gulp.env.prod;

// Images
gulp.task('build_images', function() {
  gulp.src('assets/images/**/*.svg')
    .pipe(cond(prod,
      gSvgmin(options), // minify SVG images under production
      gWatch().pipe(gLivereload(server))) // use live reload in dev mode
    )
    .pipe(gulp.dest('www/images'))
});
```

Alternatively, you can provide plugin functions instead of streams to
  instantiate streams only when needed :

```js
import cond from 'gulp-cond';
var prod = gulp.env.prod;

// Images
gulp.task('build_images', function() {
  gulp.src('assets/images/**/*.svg')
    .pipe(cond(prod,
      gSvgmin.bind(null, options), // minify SVG images under production
      function () { // use live reload in dev mode
        return gWatch().pipe(gLivereload(server));
      })
    )
    .pipe(gulp.dest('www/images'))
});
```

## API

### cond(condition, expr1, expr2)

#### condition
Type: `Boolean` or `Function`

Required. A value or a function providing a value. If the value is truthy, expr1
 will be used, else, expr2 will be use if provided.

#### expr1
Type: `Stream` or `Function`

Required. A stream or a function providing a stream.

#### expr2
Type: `Stream` or `Function`
Default value: `Stream.PassThrough`

A stream or a function providing a stream.

### Contributing / Issues

You may want to contribute to this project, pull requests are welcome if you
 accept to publish under the MIT license.



[//]: # (::contents:end)

# Authors
- [Nicolas Froidure](https://insertafter.com/en/index.html)

# License
[MIT](https://github.com/nfroidure/gulp-cond/blob/main/LICENSE)
