From 99474b37d9a983b11828dc4075bd0a98cffd2491 Mon Sep 17 00:00:00 2001 From: Sebastian Szymbor Date: Wed, 18 Jan 2017 12:08:05 +0100 Subject: [PATCH] Pass filename to replace callback --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 12ab796..3635214 100644 --- a/index.js +++ b/index.js @@ -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_; + } + function doReplace() { if (file.isStream()) { file.contents = file.contents.pipe(rs(search, replacement));