
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
gulp-transform
Advanced tools
Gulp plugin for applying arbitrary transformations to the contents of files.
Install via npm:
npm install --save-dev gulp-transform
Source file:
I am constant as the northern star.
Transform task:
const gulp = require('gulp');
const transform = require('gulp-transform');
gulp.task('quadruple', function() {
return gulp.src('src/*.txt')
.pipe(transform(contents => Array(4).fill(contents).join('\n')))
.pipe(gulp.dest('dest'));
});
Destination file:
I am constant as the northern star.
I am constant as the northern star.
I am constant as the northern star.
I am constant as the northern star.
We can pair gulp-transform with vanilla node packages to reduce our dependence
on gulp-specific plugins. In this example, we use gulp-transform with
cheerio to add a role="main"
attribute to all <main>
elements, thus ensuring accessibility in older versions of Internet Explorer.
const gulp = require('gulp');
const transform = require('gulp-transform');
const cheerio = require('cheerio');
function transformFn(contents) {
var $ = cheerio.load(contents);
$('main').attr('role', 'main');
return $.html();
}
gulp.task('cheerio', function() {
return gulp.src('src/**/*.html')
.pipe(transform(transformFn, {encoding: 'utf8'}))
.pipe(gulp.dest('dest'));
});
transform(transformFn, [options])
function
The callback responsible for the transformation, whose return value will replace the file's contents. The return value may be a string, a Buffer, or a Promise resolvable to a string or Buffer. The callback is invoked once per file with the following arguments:
contents Buffer
| string
The initial contents of the file. Contents are passed as a Buffer unless the
encoding
option is set, in which case they are passed as a string.
Contents are normalized to ensure a consistent API regardless of whether
files are in streaming or buffer mode.
file File
The Vinyl file object to which the contents belong. Useful for
getting metadata about the file, such as its path. Making changes to
file.contents
is not recommended, however, as these contents are not
normalized and will in any case be replaced by the return value of the callback.
object
(optional)An object for configuring the behavior of the plugin. The following keys are accepted as options:
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. If omitted,
this
will be undefined.
Copyright © 2016–2017 Akim McMath. Licensed under the MIT License.
FAQs
A Gulp plugin for applying custom transformations to the contents of files
The npm package gulp-transform receives a total of 8,972 weekly downloads. As such, gulp-transform popularity was classified as popular.
We found that gulp-transform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.