replacestream
Advanced tools
Comparing version 0.0.3 to 0.0.4
14
index.js
@@ -32,2 +32,3 @@ var through = require('through'); | ||
totalMatches++; | ||
rewritten += before + replace; | ||
@@ -41,4 +42,13 @@ tail = ''; | ||
if (matchCount) { | ||
after = haystack.slice(lastPos, haystack.length - tail.length); | ||
this.queue(rewritten + after); | ||
after = haystack.slice(lastPos, haystack.length); | ||
if(tail.length + after.length < search.length){ | ||
tail += after; | ||
} | ||
else{ | ||
rewritten += tail +after; | ||
tail = ''; | ||
} | ||
this.queue(rewritten); | ||
} else if (tail) { | ||
@@ -45,0 +55,0 @@ this.queue(haystack); |
{ | ||
"name": "replacestream", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A node.js through stream that does basic streaming text search and replace and is chunk boundary friendly", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,2 +6,4 @@ # replacestream | ||
[![build status](https://secure.travis-ci.org/eugeneware/replacestream.png)](http://travis-ci.org/eugeneware/replacestream) | ||
## Installation | ||
@@ -8,0 +10,0 @@ |
@@ -13,4 +13,30 @@ var expect = require('chai').expect | ||
} | ||
describe('replace', function () { | ||
it('should only replace characters specified', function (done) { | ||
var haystack = [ | ||
'ab', | ||
'a', | ||
'b' | ||
].join('\n'); | ||
describe('replace', function () { | ||
var acc = ''; | ||
var replace = replaceStream('ab','Z'); | ||
replace.on('data', function (data) { | ||
acc += data; | ||
}); | ||
replace.on('end', function () { | ||
var expected = [ | ||
'Z', | ||
'a', | ||
'b' | ||
].join('\n'); | ||
expect(acc).to.equal(expected); | ||
done(); | ||
}); | ||
replace.write(haystack); | ||
replace.end(); | ||
}); | ||
it('should be able to replace within a chunk', function (done) { | ||
@@ -17,0 +43,0 @@ var haystack = [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15456
11
418
126