# gulp-wrap

> A gulp plugin to wrap the stream contents with a template.

Latest version **0.15.0** (published 2019-03-29) · 0 weekly downloads

## Install

```sh
npm install gulp-wrap
pnpm add gulp-wrap
yarn add gulp-wrap
bun add gulp-wrap
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.15.0 |
| Published | 2019-03-29 |
| First published | 2014-01-13 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.14 |
| Dependencies | 10 |
| Unpacked size | 9.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 83 |
| Author | Adam Ayres |
| Maintainers | adamayres, shinnn |
| Keywords | gulpplugin, wrap, template, lodash, consolidate, gulp |

## Links

- npm: https://www.npmjs.com/package/gulp-wrap
- Repository: https://github.com/adamayres/gulp-wrap
- Homepage: https://github.com/adamayres/gulp-wrap#readme
- Issues: https://github.com/adamayres/gulp-wrap/issues
- npm.io page: https://npm.io/package/gulp-wrap

## Dependencies (10)

- [tryit](https://npm.io/package/tryit.md) ^1.0.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.13.0
- [through2](https://npm.io/package/through2.md) ^3.0.1
- [consolidate](https://npm.io/package/consolidate.md) ^0.15.1
- [es6-promise](https://npm.io/package/es6-promise.md) ^4.2.6
- [node.extend](https://npm.io/package/node.extend.md) 2.0.2
- [plugin-error](https://npm.io/package/plugin-error.md) ^1.0.1
- [vinyl-bufferstream](https://npm.io/package/vinyl-bufferstream.md) ^1.0.1
- [fs-readfile-promise](https://npm.io/package/fs-readfile-promise.md) ^3.0.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.15.0 (latest) — 2019-03-29
- 0.14.0 — 2018-05-21
- 0.13.0 — 2016-05-21
- 0.12.0 — 2016-05-01
- 0.11.0 — 2015-02-12
- 0.10.1 — 2015-01-23
- 0.10.0 — 2015-01-15
- 0.9.0 — 2015-01-14
- 0.8.0 — 2015-01-08
- 0.7.0 — 2015-01-07
- 0.6.0 — 2015-01-07
- 0.5.0 — 2014-10-18
- 0.4.0 — 2014-10-18
- 0.3.0 — 2014-01-28
- 0.2.0 — 2014-01-13
- … 1 more at https://npm.io/package/gulp-wrap/versions

## README

# gulp-wrap

[![NPM version](https://img.shields.io/npm/v/gulp-wrap.svg?style=flat)](https://www.npmjs.com/package/gulp-wrap)
[![Build Status](https://secure.travis-ci.org/adamayres/gulp-wrap.svg?branch=master)](http://travis-ci.org/adamayres/gulp-wrap)
[![Coverage Status](https://img.shields.io/coveralls/adamayres/gulp-wrap.svg?style=flat)](https://coveralls.io/r/adamayres/gulp-wrap)
[![Dependency Status](https://img.shields.io/david/adamayres/gulp-wrap.svg?style=flat&label=deps)](https://david-dm.org/adamayres/gulp-wrap)
[![devDependency Status](https://img.shields.io/david/dev/adamayres/gulp-wrap.svg?style=flat&label=devDeps)](https://david-dm.org/adamayres/gulp-wrap#info=devDependencies)

> A [gulp](https://github.com/gulpjs/gulp) plugin to wrap the stream contents with a [lodash](http://lodash.com/docs#template) template.

## Usage

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

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

Then, add it to your `gulpfile.js`:

**Wrap the contents with an inline template:**

```javascript
var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap('angular.module(\'text\', []).value(<%= contents %>);', {}, { parse: false /* do not parse the JSON file for template data */ }))
    .pipe(gulp.dest("./dist"));
```

**Wrap the contents with a template from file:**

```javascript
var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap({ src: 'path/to/template.txt'}))
    .pipe(gulp.dest("./dist"));
```

**Use parsed contents within a template (supports JSON and YAML):**

```javascript
var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap('Hello, <%= contents.title %>, have a <%= contents.adjective %> day.'))
    .pipe(gulp.dest("./dist"));
```

**Provide additional data and options for template processing:**

```javascript
var wrap = require("gulp-wrap");

gulp.src("./src/*.json")
    .pipe(wrap('BEFORE <%= data.contents %> <%= data.someVar %> AFTER', { someVar: 'someVal'}, { variable: 'data' }))
    .pipe(gulp.dest("./dist"));
```

This gulp plugin wraps the stream contents in a template. If you want the stream contents to be the templates use the [gulp-template](https://github.com/sindresorhus/gulp-template) plugin.

## Template

The stream contents will be available in the template using the `contents` key. If the file extension is `json`, `yaml`, or `yml` then the contents will be parsed before being passed to the template. Properties from the vinyl file will be available in the template under the `file` object and are local to that stream. User supplied `data` values will always take precedence over namespace clashes with the file properties.

## API

### wrap(template\[,data\]\[,options\])

#### template
Type: `String` or `Object` or `Function`

The template to used. When a `String` then it will be used as the template. When an `Object` then the template will be loaded from file. When a `Function` then the function will be called and should return the template content. This function get the `data` object as first parameter.

#### template.src
Type: `String`

The file location of the template.

#### data
Type: `Object` or `Function`

The data object that is passed on to the [lodash](http://lodash.com/docs#template) template call. When a `Function` then the function will be called and should return the `Object` data used in the template.  

#### options
Type: `Object` or `Function`

The options object that is passed on to the [lodash](http://lodash.com/docs#template) template call. When a `Function` then the function will be called and should return the `Object` used as the options.

#### options.parse
Type: `Boolean`

Set to explicit `false` value to disable automatic JSON and YAML parsing.

#### options.engine
Type: `String`

Set the [consolidate template engine](https://www.npmjs.com/package/consolidate) to use. (default to `lodash`).
Using another engine that `lodash` may require installation of additional node package.

## License

[MIT License](http://en.wikipedia.org/wiki/MIT_License)

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