# gulp-plugin-fabric

> Generate gulp plugin from a class or function

Latest version **1.0.0** (published 2017-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-plugin-fabric
pnpm add gulp-plugin-fabric
yarn add gulp-plugin-fabric
bun add gulp-plugin-fabric
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-09-10 |
| First published | 2017-07-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Roman Spiridonov |
| Maintainers | romars |
| Keywords | gulp |

## Links

- npm: https://www.npmjs.com/package/gulp-plugin-fabric
- Repository: https://github.com/roman-spiridonov/gulp-plugin-fabric
- Homepage: https://github.com/roman-spiridonov/gulp-plugin-fabric#readme
- Issues: https://github.com/roman-spiridonov/gulp-plugin-fabric/issues
- npm.io page: https://npm.io/package/gulp-plugin-fabric

## Dependencies (2)

- [through2](https://npm.io/package/through2.md) ^2.0.3
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.8

## Recent versions

- 1.0.0 (latest) — 2017-09-10
- 0.1.1 — 2017-09-10
- 0.1.0 — 2017-07-15

## README

Create gulp plugin from a function or object that works with string data (e.g. a converter).

# API
Exposes function that returns a gulp plugin: `gulpPluginFabric(name, run, [init])`.
* `name`: name of the plugin (will be `gulp-name`)
* `run`: function that transforms incoming data, can be both sync or async
* `init`: function that is launched before `run` with options (optional)

The following types of functions are supported:
1. Sync: `run(data, options)` returns resulting string, or throws an error
2. Async: `run(data, options, cb)` calls `cb(null, result)` upon successful completion, or `cb(err)` in case of an error

# Examples
Let's create a simple gulp plugin that adds a custom suffix to the input string. 
For example, suffix "!" would result in "str" -> "str!" transformation. 

Convert function to gulp plugin: 
```javascript
let run = (text, options) => text + options.suffix;
let plugin = require('gulp-plugin-fabric')("my-plugin", run);
```

Convert object to gulp plugin:
```javascript
let runner = {
  _suffix: "!", 
  run: function(text, options) {
    return text + this._suffix;
  }, 
  init: function (options) { 
    this._suffix = options.suffix | ""; 
  }
};

let plugin = require('gulp-plugin-fabric')("my-plugin", runner.run.bind(runner), runner.init.bind(runner));
```

Then you can use plugin in gulp as follows:
```javascript
gulp.src('.')
    .pipe(plugin({suffix: "!"}))
    .pipe(gulp.dest('out'));
```

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