Career Opportunities
    Find an Expert
    Insights & Analysis


Utility functions for gulp plugins

3.0.8  •  Published 3 years ago  •  by Fractal  •  MIT License


Description Utility functions for gulp plugins
Node Version >= 0.10


var gutil = require('gulp-util');

gutil.log('stuff happened', 'Really it did', gutil.colors.magenta('123'));

gutil.replaceExtension('', '.js'); // file.js

var opt = {
  name: 'todd',
  file: someGulpFile
gutil.template('test <%= name %> <%= file.path %>', opt) // test todd /js/hi.js


Logs stuff. Already prefixed with [gulp] and all that. If you pass in multiple arguments it will join them by a space.

The default gulp coloring using gutil.colors.:

values (files, module names, etc.) = cyan
numbers (times, counts, etc) = magenta


Is an instance of chalk.

replaceExtension(path, newExtension)

Replaces a file extension in a path. Returns the new path.


Returns true or false if an object is a stream.


Returns true or false if an object is a Buffer.

template(string[, data])

This is a lodash.template function wrapper. You must pass in a valid gulp file object so it is available to the user or it will error. You can not configure any of the delimiters. Look at the lodash docs for more info.

new File(obj)

This is just vinyl

var file = new gutil.File({
  base: path.join(__dirname, './fixtures/'),
  cwd: __dirname,
  path: path.join(__dirname, './fixtures/')


Returns a stream that does nothing but pass data straight through.

// gulp should be called like this :
// $ gulp --type production
gulp.task('scripts', function() {
    .pipe(gutil.env.type === 'production' ? uglify() : gutil.noop())


This is similar to es.wait but instead of buffering text into one string it buffers anything into an array (so very useful for file objects).

Returns a stream that can be piped to.

The stream will emit one data event after the stream piped to it has ended. The data will be the same array passed to the callback.

Callback is optional and receives two arguments: error and data

  .pipe(gutil.buffer(function(err, files) {

new PluginError(pluginName, message[, options])

  • pluginName should be the module name of your plugin
  • message can be a string or an existing error
  • By default the stack will not be shown. Set options.showStack to true if you think the stack is important for your error.
  • If you pass an error in as the message the stack will be pulled from that, otherwise one will be created.
  • Note that if you pass in a custom stack string you need to include the message along with that.
  • Error properties will be included in err.toString(). Can be omitted by including {showProperties: false} in the options.

These are all acceptable forms of instantiation:

var err = new gutil.PluginError('test', {
  message: 'something broke'

var err = new gutil.PluginError({
  plugin: 'test',
  message: 'something broke'

var err = new gutil.PluginError('test', 'something broke');

var err = new gutil.PluginError('test', 'something broke', {showStack: true});

var existingError = new Error('OMG');
var err = new gutil.PluginError('test', existingError, {showStack: true});


array-differ  ·  array-uniq  ·  beeper  ·  chalk  ·  dateformat  ·  fancy-log  ·  gulplog  ·  has-gulplog  ·  lodash._reescape  ·  lodash._reevaluate  ·  lodash._reinterpolate  ·  lodash.template  ·  minimist  ·  multipipe  ·  object-assign  ·  replace-ext  ·  through2  ·  vinyl  ·  buffer-equal  ·  coveralls  ·  event-stream  ·  istanbul  ·  istanbul-coveralls  ·  jshint  ·  lodash.templatesettings  ·  mocha  ·  rimraf  ·  should
Get an open source license report with a click
Whether it's for legal, customers or investors, upload your package.json files, and get a comprehensive license report page and spreadsheet. No hassle, it just works!
$49 one time fee, money back guarantee


Weekly Downloads

Issues and PRs


Last ver 3 years ago
Created 6 years ago
Last commit 2 years ago
8 days between commits


39 contributors


Node version: 0.10.41
0 unpacked

Legal and Compliance

MIT License
OSI Approved
0 vulnerabilities

Top Experts

Maintainer, 127 commits, 36 merges
Works at staeco
Sindre Sorhus
14 commits, 5 merges, 4 PRs
Matthew Smith
16 commits, 4 PRs
Works at Willis Towers Watson
Blaine Bublitz
Maintainer, 9 commits, 3 merges, 3 PRs
Works at Paying the maintainers Tidelift
Shinnosuke Watanabe
8 commits, 1 PRs
Milan Gardian
4 commits, 5 PRs
Works at Pandell Technology