Skip to content

Commit

Permalink
Pass filename to replace callback
Browse files Browse the repository at this point in the history
  • Loading branch information
thesebas authored Jan 18, 2017
1 parent 65b5deb commit 99474b3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ var Transform = require('readable-stream/transform');
var rs = require('replacestream');
var istextorbinary = require('istextorbinary');

module.exports = function(search, replacement, options) {
module.exports = function(search, replacement_, options) {
return new Transform({
objectMode: true,
transform: function(file, enc, callback) {
if (file.isNull()) {
return callback(null, file);
}


if (typeof replacement_ === 'function') {
var replacement = replacement_.bind({file:file});
}else{
var replacement = replacement_;

This comment has been minimized.

Copy link
@keradus

keradus Jun 20, 2017

take a look what is hoisting...

This comment has been minimized.

Copy link
@lazd

lazd Jun 20, 2017

Owner

This was actually done wrong, twice. The final code looks like 6692191

}

function doReplace() {
if (file.isStream()) {
file.contents = file.contents.pipe(rs(search, replacement));
Expand Down

0 comments on commit 99474b3

Please sign in to comment.