
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@voliware/node-data-transform
Advanced tools
Transforms data in a stream. Supports append, prepend, replace, erase, and compare
Transforms data in a stream. Supports append, prepend, replace, erase, and compare. In the future it will support split.
npm install @voliware/node-data-transform
If you have any stream in Node.js - a file, a TCP stream, a native Node request or response object - and you need to append data, prepend data, erase data, compare data, or replace data in the stream, you need this.
An enhanced Transform
object, which is a native Nodejs stream object. Transforms are passed to the pipe()
function when dealing with readable streams. When data flows through the readable stream, it also flows through the transform. The transform can actually change the data as it goes down the pipe. DataTransform
is able to process the chunks perfectly, whether you receive massive chunks at a time, or literally one byte at a time.
Create one or many DataTransform
objects that do as many of the following actions
append(match, content)
prepend(match, content)
replace(match, content)
erase(match)
compare(match)
Here, match
means what are we looking for in the stream, and content
is what we will append, prepend, or replace it with. For erase
and compare
, we don't need any content. erase
simply removes the data while compare
emits an event.
In this example, we will create just one DataTransform
that will erase data, append some data with a file, prepend some data with a file, and replace some data with text. Note that the matches are named the same as the functions for clarity.
<div>
<!-- append -->
<!-- prepend -->
</div>
<div>
<!-- replace -->
<!-- erase -->
</div>
let readable = Fs.createReadStream("base.html");
let writable = Fs.createWriteStream("index.html");
let datatransform = new DataTransform()
.erase('<!-- erase -->') // erase <!-- erase -->
.append('<!-- append -->', {file: "append.html"}) // append with contents of a file
.prepend('<!-- prepend -->', {file: "prepend.html"}) // prepend with contents of a file
.replace('<!-- replace -->', {string: "Replaced!"}); // replace with text
The result will be
<div>
<!-- append --><div id="append"></div>
<div id="prepend"></div><!-- prepend -->
</div>
<div>
Replaced!
</div>
A minifier
let datatransform = new DataTransform()
.erase(' ') // erase spaces
.erase(Buffer.from([0x0d, 0x0a])) // erase new lines
An HTML injector
let datatransform = new DataTransform()
.append('<!-- templates -->', {file: "templates.html"}) // append with contents of a file
Search and replace in a file
let datatransform = new DataTransform()
.replace('youre', {string: "you're"}) // search and replace
There are two options when creating a DataTransform
.
concat
modifiers
action
- "append", "prepend", "compare", "replace", or "erase"match
- the string or buffer to match againstcontent
- the string or buffer or filepath to append, prepend, or replace withAppend " Senior" each time we find "Joe".
Prepend "Mr. " each time we find "Joe".
Replace "dog" with "cat".
Erase all "bad words"!
let datatransform = new DataTransform({
concat: false,
modifiers: [
new Modifier("append", "Joe", {string: " Senior"}),
new Modifier("prepend", "Joe", {string: " Mr."}),
new Modifier("replace", "dog", {string: "cat"}),
new Modifier("erase", {string: "bad words"})
]
});
Even better, you can use an array to, for example, append many files or strings after one match.
let datatransform = new DataTransform({
concat: false,
modifiers: [
new Modifier("append", "<!--templates-->", [
{file: './src/html/template1.html'},
{file: './src/html/template2.html'},
{string: '<template id="abc">ABC</template>'}
])
]
});
FAQs
Transforms data in a stream. Supports append, prepend, replace, erase, and compare
We found that @voliware/node-data-transform demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.