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

node-opcua-xml2json

Package Overview
Dependencies
Maintainers
0
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-opcua-xml2json - npm Package Compare versions

Comparing version 2.142.0 to 2.143.0

dist/source/thirdparties/escape.d.ts

3

dist/source/nodejs/xml2json_fs.d.ts

@@ -1,2 +0,2 @@

import { Callback, SimpleCallback, Xml2Json } from "../xml2json";
import { Xml2Json } from "../xml2json";
export declare class Xml2JsonFs extends Xml2Json {

@@ -7,3 +7,2 @@ /**

parse(xmlFile: string): Promise<any>;
parse(xmlFile: string, callback: Callback<any> | SimpleCallback): void;
}

@@ -10,34 +10,16 @@ "use strict";

class Xml2JsonFs extends xml2json_1.Xml2Json {
parse(xmlFile, callback) {
if (!callback) {
throw new Error("internal error");
/**
* @param xmlFile - the name of the xml file to parse.
*/
async parse(xmlFile) {
// slightly faster but require more memory ..
let data = await fs_1.default.promises.readFile(xmlFile);
if (data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
data = data.subarray(3);
}
const readWholeFile = true;
if (readWholeFile) {
// slightly faster but require more memory ..
fs_1.default.readFile(xmlFile, (err, data) => {
if (err) {
return callback(err);
}
if (data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
data = data.subarray(3);
}
const dataAsString = data.toString();
const parser = this._prepareParser(callback);
parser.write(dataAsString);
parser.end();
});
}
else {
const Bomstrip = require("bomstrip");
const parser = this._prepareParser(callback);
fs_1.default.createReadStream(xmlFile, { autoClose: true, encoding: "utf8" }).pipe(new Bomstrip()).pipe(parser);
}
const dataAsString = data.toString();
return this.__parseInternal(dataAsString);
}
}
exports.Xml2JsonFs = Xml2JsonFs;
// tslint:disable:no-var-requires
const thenify_ex_1 = require("thenify-ex");
const opts = { multiArgs: false };
Xml2JsonFs.prototype.parse = (0, thenify_ex_1.withCallback)(Xml2JsonFs.prototype.parse, opts);
//# sourceMappingURL=xml2json_fs.js.map

@@ -5,13 +5,4 @@ /**

*/
declare const LtxParser: any;
export type SimpleCallback = (err?: Error) => void;
export type Callback<T> = (err?: Error | null, result?: T) => void;
declare interface LtxParser {
write(str: string): void;
end(): void;
on(eventName: "startElement", eventHandler: (name: string, attrs: XmlAttributes) => void): void;
on(eventName: "endElement", eventHandler: (name: string) => void): void;
on(eventName: "text", eventHandler: (name: string) => void): void;
on(eventName: "close", eventHandler: () => void): void;
}
export interface Parser {

@@ -137,9 +128,4 @@ [key: string]: ReaderState;

constructor(options: ReaderStateParser);
parseStringSync(xml_text: string): Record<string, unknown>;
parseString(xml_text: string): Record<string, unknown>;
/**
* @deprecated
*/
parseString(xml_text: string): Promise<any>;
parseString(xml_text: string, callback: Callback<any> | SimpleCallback): void;
/**
* @private

@@ -158,4 +144,3 @@ * @internal

*/
protected _prepareParser(callback: Callback<any> | SimpleCallback): LtxParser;
protected __parseInternal(data: string): Record<string, unknown>;
}
export {};

@@ -8,7 +8,4 @@ "use strict";

exports.Xml2Json = exports.ReaderState = exports.ReaderStateBase = void 0;
// tslint:disable:max-classes-per-file
// tslint:disable:no-var-requires
// tslint:disable:unified-signatures
const node_opcua_assert_1 = require("node-opcua-assert");
const LtxParser = require("ltx/lib/parsers/ltx.js");
const lts_1 = require("./thirdparties/parser/lts");
/**

@@ -196,14 +193,5 @@ * @static

}
parseStringSync(xml_text) {
let retValue = {};
const parser = this._prepareParser((err, r) => (retValue = r));
parser.write(xml_text);
parser.end();
return retValue;
parseString(xml_text) {
return this.__parseInternal(xml_text);
}
parseString(xml_text, callback) {
const parser = this._prepareParser(callback);
parser.write(xml_text);
parser.end();
}
/**

@@ -239,5 +227,4 @@ * @private

*/
_prepareParser(callback) {
(0, node_opcua_assert_1.assert)(typeof callback === "function");
const parser = new LtxParser();
__parseInternal(data) {
const parser = new lts_1.SaxLtx();
this.currentLevel = 0;

@@ -270,15 +257,16 @@ parser.on("startElement", (name, attrs) => {

});
parser.once("close", () => {
if (callback) {
callback(null, this.current_state._pojo);
}
});
return parser;
parser.write(data);
parser.end("");
return this.current_state._pojo;
/*
return await new Promise((resolve) => {
parser.once("close", () => {
resolve((this.current_state! as any)._pojo);
});
//parser.write(data);
parser.end(data);
})*/
}
}
exports.Xml2Json = Xml2Json;
// tslint:disable:no-var-requires
const thenify_ex_1 = require("thenify-ex");
const opts = { multiArgs: false };
Xml2Json.prototype.parseString = (0, thenify_ex_1.withCallback)(Xml2Json.prototype.parseString, opts);
//# sourceMappingURL=xml2json.js.map
{
"name": "node-opcua-xml2json",
"version": "2.142.0",
"version": "2.143.0",
"description": "pure nodejs OPCUA SDK - module xml2json",

@@ -15,6 +15,4 @@ "main": "dist/source/index.js",

"dependencies": {
"ltx": "^3.1.2",
"node-opcua-assert": "2.139.0",
"node-opcua-utils": "2.139.0",
"thenify-ex": "4.2.0",
"xml-writer": "^1.7.0"

@@ -41,3 +39,3 @@ },

"homepage": "http://node-opcua.github.io/",
"gitHead": "50cfa07779d4c07b299176ac9c27527fcd97d079",
"gitHead": "3bd85d4036f219f6f7e401d54e60afb3592ff1ba",
"files": [

@@ -44,0 +42,0 @@ "dist",

@@ -8,35 +8,11 @@ import fs from "fs";

*/
public async parse(xmlFile: string): Promise<any>;
public parse(xmlFile: string, callback: Callback<any> | SimpleCallback): void;
public parse(xmlFile: string, callback?: Callback<any> | SimpleCallback): any {
if (!callback) {
throw new Error("internal error");
public async parse(xmlFile: string): Promise<any> {
// slightly faster but require more memory ..
let data = await fs.promises.readFile(xmlFile);
if (data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
data = data.subarray(3);
}
const readWholeFile = true;
if (readWholeFile) {
// slightly faster but require more memory ..
fs.readFile(xmlFile, (err: Error | null, data: Buffer) => {
if (err) {
return callback(err);
}
if (data[0] === 0xef && data[1] === 0xbb && data[2] === 0xbf) {
data = data.subarray(3);
}
const dataAsString = data.toString();
const parser = this._prepareParser(callback);
parser.write(dataAsString);
parser.end();
});
} else {
const Bomstrip = require("bomstrip");
const parser = this._prepareParser(callback);
fs.createReadStream(xmlFile, { autoClose: true, encoding: "utf8" }).pipe(new Bomstrip()).pipe(parser);
}
const dataAsString = data.toString();
return this.__parseInternal(dataAsString);
}
}
// tslint:disable:no-var-requires
import { withCallback } from "thenify-ex";
const opts = { multiArgs: false };
Xml2JsonFs.prototype.parse = withCallback(Xml2JsonFs.prototype.parse, opts);

@@ -6,8 +6,5 @@ /**

// tslint:disable:max-classes-per-file
// tslint:disable:no-var-requires
// tslint:disable:unified-signatures
import { assert } from "node-opcua-assert";
const LtxParser = require("ltx/lib/parsers/ltx.js");
import { SaxLtx } from "./thirdparties/parser/lts";

@@ -17,16 +14,3 @@ export type SimpleCallback = (err?: Error) => void;

declare interface LtxParser {
write(str: string): void;
end(): void;
on(eventName: "startElement", eventHandler: (name: string, attrs: XmlAttributes) => void): void;
on(eventName: "endElement", eventHandler: (name: string) => void): void;
on(eventName: "text", eventHandler: (name: string) => void): void;
on(eventName: "close", eventHandler: () => void): void;
}
export interface Parser {

@@ -93,4 +77,4 @@ [key: string]: ReaderState;

export class ReaderStateBase {}
export interface ReaderStateBase extends IReaderState {}
export class ReaderStateBase { }
export interface ReaderStateBase extends IReaderState { }
/**

@@ -287,20 +271,6 @@ * @private

public parseStringSync(xml_text: string): Record<string, unknown> {
let retValue: Record<string, unknown> = {};
const parser = this._prepareParser((err: Error | null | undefined, r: Record<string, unknown>) => (retValue = r));
parser.write(xml_text);
parser.end();
return retValue;
public parseString(xml_text: string): Record<string, unknown> {
return this.__parseInternal(xml_text);
}
/**
* @deprecated
*/
public parseString(xml_text: string): Promise<any>;
public parseString(xml_text: string, callback: Callback<any> | SimpleCallback): void;
public parseString(xml_text: string, callback?: Callback<any> | SimpleCallback): any {
const parser = this._prepareParser(callback!);
parser.write(xml_text);
parser.end();
}
/**
* @private

@@ -338,5 +308,4 @@ * @internal

*/
protected _prepareParser(callback: Callback<any> | SimpleCallback): LtxParser {
assert(typeof callback === "function");
const parser = new LtxParser();
protected __parseInternal(data: string): Record<string, unknown> {
const parser = new SaxLtx();
this.currentLevel = 0;

@@ -369,14 +338,14 @@ parser.on("startElement", (name: string, attrs: XmlAttributes) => {

});
parser.once("close", () => {
if (callback) {
(callback as any)(null, (this.current_state! as any)._pojo);
}
});
return parser;
parser.write(data);
parser.end("");
return (this.current_state! as any)._pojo;
/*
return await new Promise((resolve) => {
parser.once("close", () => {
resolve((this.current_state! as any)._pojo);
});
//parser.write(data);
parser.end(data);
})*/
}
}
// tslint:disable:no-var-requires
import { withCallback } from "thenify-ex";
const opts = { multiArgs: false };
Xml2Json.prototype.parseString = withCallback(Xml2Json.prototype.parseString, opts);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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