Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@quadient/evolve-data-transformations
Advanced tools
The Data Transformations package contains helper utilities to wrestle with JSON, XML and CSV data formats.
Add to project:
npm install @quadient/evolve-data-transformations
Async streaming XML Parser and Writer.
XmlParser
can be used to process strings with parts of the XML content.
The callback given to parser constructor receives events
of type XmlEvent.
XmlWriter
is the opposite component. It receives XmlEvent
objects through the
write
method and the callback given to constructor receives a string with the
XML content.
To integrate XML processing with streams there are
TransformStream
classes StringToXmlTransformStream
and XmlToStringTransformStream
for convenient
use with streams.
const writer = new XmlWriter(async (str) => {
console.log(str);
});
const parser = new XmlParser(async (event) => {
if (event.type === XmlEventType.START_TAG) {
let elem = event.details as ElementDetails;
if (elem.name == "name") {
elem.name = "fixedName"
}
} else if (event.type === XmlEventType.END_TAG) {
if (event.details === "name") {
event.details = "fixedName"
}
}
await writer.write(event);
});
await parser.parse(`<person><name>Fred</name></person>`);
await parser.flush(); // must be called at the end of parsing
await writer.flush(); // must be called at the end of writing
Output:
<person><fixedName>Fred</fixedName></person>
Async streaming JSON Parser and Writer.
JsonParser
can be used to process strings with parts of the JSON content.
The callback given to parser constructor receives events
of type JsonEvent.
JsonWriter
is the opposite component. It receives JsonEvent objects in the
write
method and the callback given to constructor receives a string with the
JSON content.
To integrate XML processing with streams there are
TransformStream
classes StringToJsonTransformStream
and JsonToStringTransformStream
for convenient
use with streams.
let writer = new JsonWriter(async (str) => {
console.log(str);
});
let parser = new JsonParser(async (event) => {
if(event.type === JsonEventType.PROPERTY_NAME && event.data === "name") {
event.data = "fixedName";
}
await writer.write(event);
})
await parser.parse(`{"person": {"name":"Fred"}}`);
await parser.flush(); // must be called at the end of parsing
await writer.flush(); // must be caleld at the end of writing
Output:
{"person":{"fixedName":"Fred"}}
Async streaming CSV parser.
CsvParser
can be used to process csv content as strings. It produces
event objects and sends them to a callback.
const p = new CsvParser(async (event) => {
console.log(event.type + " - " + event.data);
});
await p.parse('head')
await p.parse('er1,header2\nvalue1,value2');
await p.flush();
Output:
header - [ 'header1', 'header2' ]
values - [ 'value1', 'value2' ]
The following example illustrates how the stream-compatible helper classes can be used in case the input is in the form of ReadableStream.
import {StringToXmlTransformStream, XmlEventType} from "@quadient/evolve-data-transformations";
(async function () {
const response = await fetch("https://httpbin.org/xml");
const stream = response.body;
stream
.pipeThrough(new TextDecoderStream())
.pipeThrough(new StringToXmlTransformStream())
.pipeTo(new ConsoleLogWritableStream());
})()
class ConsoleLogWritableStream extends WritableStream {
constructor() {
super({
write(chunk) {
console.log(chunk);
}
})
}
}
FAQs
Library for data transformations.
We found that @quadient/evolve-data-transformations demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.