Nukem's Possible Manifestation
Miss any of our Open RFC calls?Watch the recordings here! »

gulp-transform

1.0.2 • Public • Published

gulp-transform

Version License Build Coverage Dependencies

Gulp plugin for applying arbitrary transformations to the contents of files. Useful for incorporating non-gulp functions and modules into your pipeline. Files may be in streaming mode or buffer mode.

Install

Install via npm:

npm install --save-dev gulp-transform

Example

Source file (caesar.txt):

I am constant as the northern star...

Transform task:

const gulp = require('gulp');
const transform = require('gulp-transform');
 
// Repeat contents three times and prepend filename.
function transformFn(contents, file) {
  return [file.path, contents, contents, contents].join('\n');
}
 
gulp.task('silly-task', function() {
  return gulp.src('/path/to/src/**/*.txt')
    .pipe(transform(transformFn)) // Apply transform.
    .pipe(gulp.dest('/path/to/dest'));
});

Destination file:

/path/to/src/caesar.txt
I am constant as the northern star...
I am constant as the northern star...
I am constant as the northern star...

API

The package exports a single plugin function that takes a callback and an optional options object. The callback is invoked once per file. The contents of the file are passed to the callback and replaced by the return value.

Usage
transform(transformFn, [options])
Param Type Details
transformFn Function Function that transforms the contents of each file. Invoked with the following arguments:
  • contents (Buffer|String) The contents of the file. Will be a Buffer unless otherwise specified.
  • file (File) The vinyl file object whose contents are to be transformed. Useful for getting metadata about the file, such as its name or path.
The return value will replace the file's contents and must be either a String or a Buffer.
options
(optional)
Object Options to modify the behavior of the plugin.
  • encoding (String) Casts contents to a string with the specified encoding before it is passed to transformFn. If no encoding is specified, contents will be passed as a Buffer.
  • thisArg (*) Determines the value of this within transformFn. Defaults to undefined.

License

Copyright © 2016 Akim McMath. Licensed under the MIT License.

Install

npm i [email protected]

Version

1.0.2

License

MIT

Last publish

Collaborators

  • avatar