Socket
Socket
Sign inDemoInstall

replacestream

Package Overview
Dependencies
10
Maintainers
2
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.0 to 3.0.0

81

index.js

@@ -1,5 +0,8 @@

var through = require('through');
'use strict';
module.exports = ReplaceStream;
function ReplaceStream(search, replace, options) {
var escapeRegExp = require('escape-string-regexp');
var objectAssign = require('object-assign');
var Transform = require('readable-stream/transform');
module.exports = function ReplaceStream(search, replace, options) {
var tail = '';

@@ -9,6 +12,7 @@ var totalMatches = 0;

options = options || {};
options.limit = options.limit || Infinity;
options.encoding = options.encoding || 'utf8';
options.max_match_len = options.max_match_len || 100;
options = objectAssign({
limit: Infinity,
encoding: 'utf8',
max_match_len: 100
}, options);

@@ -27,3 +31,3 @@ var replaceFn = replace;

function write(buf) {
function transform(buf, enc, cb) {
var matches;

@@ -57,3 +61,3 @@ var lastPos = 0;

var dataToQueue = getDataToQueue(matchCount,haystack,rewritten,lastPos);
this.queue(dataToQueue);
cb(null, dataToQueue);
}

@@ -72,25 +76,25 @@

function getDataToQueue(matchCount, haystack, rewritten, lastPos) {
var dataToQueue;
if (matchCount > 0) {
if (haystack.length > tail.length) {
dataToQueue = rewritten + haystack.slice(lastPos, haystack.length - tail.length)
} else {
dataToQueue = rewritten
return rewritten + haystack.slice(lastPos, haystack.length - tail.length);
}
} else {
dataToQueue = haystack.slice(0, haystack.length - tail.length)
return rewritten;
}
return dataToQueue;
return haystack.slice(0, haystack.length - tail.length);
}
function end() {
if (tail) this.queue(tail);
this.queue(null);
function flush(cb) {
if (tail) {
this.push(tail);
}
cb();
}
var t = through(write, end);
return t;
}
return new Transform({
transform: transform,
flush: flush
});
};

@@ -110,6 +114,2 @@ function createReplaceFn(replace, isRegEx) {

var stringReplaceFunction = function () {
return replace;
};
if (isRegEx && !(replace instanceof Function)) {

@@ -120,17 +120,15 @@ return regexReplaceFunction;

if (!(replace instanceof Function)) {
return stringReplaceFunction
return function stringReplaceFunction() {
return replace;
};
}
return replace
return replace;
}
function escapeRegExp(s) {
return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
function matchFromRegex(regex, options) {
if (options.regExpOptions) {
regex = new RegExp(regex.source, options.regExpOptions)
}
function matchFromRegex(s, options) {
var regex = s
if (options.regExpOptions)
regex = new RegExp(s.source, options.regExpOptions)
// If there is no global flag then there can only be one match

@@ -140,10 +138,11 @@ if (!regex.global) {

}
return regex
return regex;
}
function matchFromString(s, options) {
if (options.regExpOptions)
return new RegExp(escapeRegExp(s), options.regExpOptions)
if (options.regExpOptions) {
return new RegExp(escapeRegExp(s), options.regExpOptions);
}
return new RegExp(escapeRegExp(s), options.ignoreCase === false ? 'gm' : 'gmi')
return new RegExp(escapeRegExp(s), options.ignoreCase === false ? 'gm' : 'gmi');
}
{
"name": "replacestream",
"version": "2.1.0",
"version": "3.0.0",
"description": "A node.js through stream that does basic streaming text search and replace and is chunk boundary friendly",
"main": "index.js",
"repository": "eugeneware/replacestream",
"author": "Eugene Ware <eugene@noblesamurai.com>",
"license": "BSD-3-Clause",
"files": [
"index.js"
],
"scripts": {
"test": "node_modules/.bin/mocha"
"test": "mocha --growl --full-trace"
},
"repository": {
"type": "git",
"url": "https://github.com/eugeneware/replacestream"
},
"keywords": [

@@ -22,11 +23,12 @@ "replace",

],
"author": "Eugene Ware <eugene@noblesamurai.com>",
"license": "BSD",
"dependencies": {
"escape-string-regexp": "^1.0.3",
"object-assign": "^3.0.0",
"readable-stream": "^2.0.1"
},
"devDependencies": {
"chai": "^1.9.1",
"mocha": "^1.21.4"
},
"dependencies": {
"through": "~2.3.4"
"chai": "^3.0.0",
"concat-stream": "^1.5.0",
"mocha": "^2.2.5"
}
}

@@ -265,3 +265,5 @@ # replacestream

<tr><th align="left">Tim Chaplin</th><td><a href="https://github.com/tjchaplin">GitHub/tjchaplin</a></td></tr>
<tr><th align="left">Bryce Gibson</th><td><a href="https://github.com/bryce-gibson">GitHub/bryce-gibson</a></td></tr>
<tr><th align="left">Romain</th><td><a href="https://github.com/Filirom1">GitHub/Filirom1</a></td></tr>
<tr><th align="left">Shinnosuke Watanabe</th><td><a href="https://github.com/shinnn">GitHub/shinnn</a></td></tr>
</tbody></table>
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc