Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

gulp-replace-fix

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-replace-fix - npm Package Compare versions

Comparing version 0.5.5 to 0.6.0

@@ -8,84 +8,84 @@ 'use strict';

module.exports = function(search, replacement, options) {
return new Transform({
objectMode: true,
transform: function(file, enc, callback) {
if (file.isNull()) {
return callback(null, file);
}
return new Transform({
objectMode: true,
transform: function(file, enc, callback) {
if (file.isNull()) {
return callback(null, file);
}
function doReplace() {
if (file.isStream()) {
file.contents = file.contents.pipe(rs(search, replacement));
return callback(null, file);
}
function doReplace() {
if (file.isStream()) {
file.contents = file.contents.pipe(rs(search, replacement));
return callback(null, file);
}
if (file.isBuffer()) {
if (search instanceof RegExp) {
file.contents = new Buffer(String(file.contents).replace(search, replacement));
}
else {
var chunks = String(file.contents).split(search);
if (file.isBuffer()) {
if (search instanceof RegExp) {
file.contents = new Buffer(String(file.contents).replace(search, replacement));
}
else {
var chunks = String(file.contents).split(search);
var result;
if (typeof replacement === 'function') {
// Start with the first chunk already in the result
// Replacements will be added thereafter
// This is done to avoid checking the value of i in the loop
result = [ chunks[0] ];
var result;
if (typeof replacement === 'function') {
// Start with the first chunk already in the result
// Replacements will be added thereafter
// This is done to avoid checking the value of i in the loop
result = [ chunks[0] ];
// The replacement function should be called once for each match
for (var i = 1; i < chunks.length; i++) {
// Add the replacement value
result.push(replacement(search));
// The replacement function should be called once for each match
for (var i = 1; i < chunks.length; i++) {
// Add the replacement value
result.push(replacement(search));
// Add the next chunk
result.push(chunks[i]);
}
// Add the next chunk
result.push(chunks[i]);
}
result = result.join('');
}
else {
result = chunks.join(replacement);
}
result = result.join('');
}
else {
result = chunks.join(replacement);
}
file.contents = new Buffer(result);
}
return callback(null, file);
}
file.contents = new Buffer(result);
}
return callback(null, file);
}
callback(null, file);
}
callback(null, file);
}
if (options) {
if (options.passFileName && typeof replacement === 'function') {
var userReplacement = replacement;
replacement = function () {
var context = {
filePath: file.path
};
userReplacement.apply(context, arguments);
};
}
if (options) {
if (options.passFileName && typeof replacement === 'function') {
var userReplacement = replacement;
replacement = function () {
var context = {
filePath: file.path
};
return userReplacement.apply(context, arguments);
};
}
if(options.skipBinary) {
istextorbinary.isText(file.path, file.contents, function(err, result) {
if (err) {
return callback(err, file);
}
if(options.skipBinary) {
istextorbinary.isText(file.path, file.contents, function(err, result) {
if (err) {
return callback(err, file);
}
if (!result) {
callback(null, file);
} else {
doReplace();
}
});
if (!result) {
callback(null, file);
} else {
doReplace();
}
});
return;
}
return;
}
}
}
doReplace();
}
});
doReplace();
}
});
};
{
"name": "gulp-replace-fix",
"version": "0.5.5",
"version": "0.6.0",
"description": "A string replace plugin for gulp",

@@ -5,0 +5,0 @@ "dependencies": {