gulp-replace
Advanced tools
Comparing version
30
index.js
@@ -1,14 +0,15 @@ | ||
var es = require('event-stream'); | ||
'use strict'; | ||
var through = require('through2'); | ||
var rs = require('replacestream'); | ||
var stream = require('stream'); | ||
var istextorbinary = require('istextorbinary'); | ||
module.exports = function(search, replacement, options) { | ||
var doReplace = function(file, callback) { | ||
var isRegExp = search instanceof RegExp; | ||
var isStream = file.contents && typeof file.contents.on === 'function' && typeof file.contents.pipe === 'function'; | ||
var isBuffer = file.contents instanceof Buffer; | ||
var doReplace = function(file, enc, callback) { | ||
if (file.isNull()) { | ||
return callback(null, file); | ||
} | ||
function doReplace() { | ||
if (isStream) { | ||
if (file.isStream()) { | ||
file.contents = file.contents.pipe(rs(search, replacement)); | ||
@@ -18,4 +19,4 @@ return callback(null, file); | ||
if (isBuffer) { | ||
if (isRegExp) { | ||
if (file.isBuffer()) { | ||
if (search instanceof RegExp) { | ||
file.contents = new Buffer(String(file.contents).replace(search, replacement)); | ||
@@ -54,3 +55,2 @@ } | ||
callback(null, file); | ||
} | ||
@@ -65,3 +65,3 @@ | ||
if (!result) { | ||
return callback(null, file); | ||
callback(null, file); | ||
} else { | ||
@@ -71,10 +71,10 @@ doReplace(); | ||
}); | ||
return; | ||
} | ||
else { | ||
doReplace(); | ||
} | ||
doReplace(); | ||
}; | ||
return es.map(doReplace); | ||
return through.obj(doReplace); | ||
}; |
{ | ||
"name": "gulp-replace", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "A string replace plugin for gulp", | ||
"main": "index.js", | ||
"dependencies": { | ||
"event-stream": "3.2.1", | ||
"istextorbinary": "1.0.2", | ||
"replacestream": "2.0.0", | ||
"istextorbinary": "1.0.2" | ||
"through2": "0.6.3" | ||
}, | ||
"devDependencies": { | ||
"should": "^4.6.0", | ||
"event-stream": "^3.2.2", | ||
"mocha": "^2.1.0", | ||
"gulp-util": "^3.0.2" | ||
"should": "^5.0.0", | ||
"vinyl": "^0.4.6" | ||
}, | ||
"scripts": { | ||
"test": "./node_modules/.bin/mocha" | ||
"test": "mocha" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
5690
-2.72%4
33.33%61
-1.61%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed