Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-red-contrib-prib-functions

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-red-contrib-prib-functions - npm Package Compare versions

Comparing version 0.11.1 to 0.12.0

test/transformXML.js

6

package.json
{
"name": "node-red-contrib-prib-functions",
"version": "0.11.1",
"version": "0.12.0",
"description": "Node-RED added node functions.",

@@ -8,3 +8,3 @@ "dependencies": {

"avsc": "*",
"snappy": "*"
"fast-xml-parser": "*"
},

@@ -91,2 +91,4 @@ "devDependencies": {

"WMA",
"xml",
"XML",
"Z-score"

@@ -93,0 +95,0 @@ ],

@@ -77,3 +77,3 @@ # [node-red-contrib-prib-functions][2]

* Array to Messages
* AVRO to JSON
* AVRO to JSON (uses [avsc][6])
* CSV to Array

@@ -89,6 +89,7 @@ * CSV to HTML

* JSON to CSV
* JSON to AVRO
* JSON to AVRO (uses [avsc][6])
* JSON to ISO8385
* JSON to Messages
* JSON to String
* JSON to XML (uses [fast-xml-parser][4])
* String to JSON

@@ -104,5 +105,8 @@ * path to Basename

* path to Resolve
* snappy compress
* snappy uncompress
* snappy compress (uses [snappy][5], must install separately)
* snappy uncompress (uses [snappy][5], must install separately)
* XML to JSON (uses [fast-xml-parser][4])
Note, snappy needs to be installed separately as can have issues with auto install as build binaries.
Example AVRO with schema

@@ -235,2 +239,3 @@

0.12.0 added xml to json and json to xml. Make snappy installed separately as can cause install issues

@@ -293,1 +298,7 @@ 0.11.1 Fix spelling of AVRO.

[3]: https://github.com/peterprib "base github"
[4]: https://github.com/NaturalIntelligence/fast-xml-parser "fast-xml-parser"
[5]: https://www.npmjs.com/package/snappy "snappy"
[6]: https://www.npmjs.com/package/avsc "avsc"

@@ -8,7 +8,23 @@ const logger = new (require("node-red-contrib-logger"))("transform");

process=require('process');
const avsc = require('avsc');
const snappy = require('snappy');
let avsc,snappy,xmlParser,json2xmlParser;
const {ISO8583BitMapId,ISO8583BitMapName}=require("./ISO8583BitMap");
let ISO8583,ISO8583message;
const XMLoptions = {
// attributeNamePrefix : "@_",
// attrNodeName: "attr", //default is 'false'
// textNodeName : "#text",
ignoreAttributes : false,
ignoreNameSpace : false,
allowBooleanAttributes : true,
parseNodeValue : true,
parseAttributeValue : false,
// cdataTagName: "__cdata", //default is 'false'
// cdataPositionChar: "\\c",
// parseTrueNumberOnly: false,
// arrayMode: false, //"strict"
// attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true}),//default is a=>a
// tagValueProcessor : (val, tagName) => he.decode(val), //default is a=>a
// stopNodes: ["parse-me-as-string"]
trimValues: false
};
function error(node,ex,shortMessage){

@@ -194,2 +210,3 @@ if(logger.active) logger.send({label:"transformNode catch",shortMessage:shortMessage,error:ex.message,stack:ex.stack});

JSONToString: (RED,node,msg,data)=>JSON.stringify(data),
JSONToXML: (RED,node,msg,data)=>json2xmlParser.parse(data),
StringToJSON: (RED,node,msg,data)=>JSON.parse(data),

@@ -229,2 +246,3 @@ pathToBasename: (RED,node,msg,data)=>path.basename(data),

},
XMLToJSON: (RED,node,msg,data)=>xmlParser.parse(data,XMLoptions,true),
invalidArray:(v=>!Array.isArray(v))

@@ -240,2 +258,5 @@ };

}
function is(node,value){
return node.actionSource==value||node.actionTarget==value;
}
module.exports = function (RED) {

@@ -246,2 +267,14 @@ function transformNode(n) {

let node=Object.assign(this,{maxMessages:1000,SendArray:SendArray},n,{RED:RED});
if(is(node,"AVRO")) {
if(avsc==null) avsc=require('avsc');
} else if(is(node,"snappy")) {
if(snappy==null) snappy=require('snappy');
} else if(is(node,"XML")) {
if(xmlParser==null) xmlParser=require('fast-xml-parser');
if(json2xmlParser==null) {
const j2xParser=xmlParser.j2xParser;
json2xmlParser=new j2xParser(XMLoptions);
}
if(logger.active) logger.send({label:"load xml",xmlParserKeys:Object.keys(xmlParser),json2xmlParser:Object.keys(json2xmlParser)});
}
node.sendInFunction=["snappy"].includes(node.actionSource)||["Messages"].includes(node.actionTarget);

@@ -285,3 +318,3 @@ node.hasNewTopic=![null,""].includes(node.topicProperty);

node.transform=functions[node.actionSource+"To"+node.actionTarget];
if(!node.transform) throw Error("transform routine not found");
if(!node.transform) throw Error("transform routine not found for "+node.actionSource+" to "+node.actionTarget);
} catch (ex) {

@@ -288,0 +321,0 @@ error(node,ex,node.actionSource+"\nto "+node.actionTarget + " not implemented")

Sorry, the diff of this file is not supported yet

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