GithubHelp home page GithubHelp logo

gulp-edit's Introduction

Information

Packagegulp-edit
Description Edit files with gulp

Usage

edit(modifier)

  • modifier(src, cb): [function]
var edit = require('gulp-edit')

gulp.task('edit', function() {
  return gulp.src('./*.txt')
    .pipe(edit(function(src, cb){
      // this === file
      var err = null
      src += '- modified!'
      cb(err, src)
    }))
    .pipe(gulp.dest('./'))
})

gulp-edit's People

Contributors

fritx avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

simevidas

gulp-edit's Issues

Proposal for simpler API

Your API passes both the src and cb arguments to the modifier function. I think, this can be simplified. Here’s my suggestion:

  • only pass src to the modifier function (the file contents)
  • the modifier function returns the modified file contents or explicitly throws an error

So, instead of this:

gulp.src('./*.txt')
    .pipe(edit(function (src, cb) {
        var err = null;

        src += '- modified!';

        if (/* something went wrong */) {
            err = new Error(/* explain what went wrong */);
        } 

        cb(err, src);
    }))
    .pipe(gulp.dest('./'))

I propose this:

gulp.src('./*.txt')
    .pipe(edit(function (src) {
        src += '- modified!';

        if (/* something went wrong */) {
            throw new Error(/* explain what went wrong */);
        } 

        return src;
    }))
    .pipe(gulp.dest('./'))

I think, this API is more straight-forward, since the modifier function both receives and returns a string value, and the users of your Gulp plugin don’t have to understand that cb pattern, but instead just throw errors when needed.

I can make a PR with this change. Tell me what you think.

Please note that if you don’t like this API change, I intend to fork your repo and implement the change in my fork instead ^_^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.