New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@quadient/evolve-data-transformations

Package Overview
Dependencies
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@quadient/evolve-data-transformations

Library for data transformations.

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
50
increased by13.64%
Maintainers
5
Weekly downloads
 
Created
Source

Data Transformations Package

Table of Contents

  • XML
  • JSON

Overview

The Data Transformations package contains helper utilities to work with JSON, XML and CSV data formats.

XML

Async streaming XML Parser and Writer.

XmlParser receives strings with parts of the XML content in the "write" method and the callback given to parser constructor receives events of type XmlEvent.

XmlWriter is the opposite component. It receives XmlEvent objects in the write method and the callback given to constructor receives a string with the XML content.

There are also predefined TransformStream classes StringToXmlTransformStream and XmlToStringTransformStream for convenient use with streams.

XML Example

let writer = new XmlWriter(async (str) => {
    console.log(str);
});

let 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>

JSON

Async streaming JSON Parser and Writer.

JsonParser receives strings with parts of the JSON content in the write method and 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.

JSON Example

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"}}

FAQs

Package last updated on 03 Aug 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc