jspurefix
Version:
pure node js fix engine
58 lines • 2.34 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XsdParser = void 0;
const fs = require("fs");
class XsdParser {
constructor(definitions) {
this.definitions = definitions;
this.data = [];
}
parse(file) {
return __awaiter(this, void 0, void 0, function* () {
return yield new Promise((resolve, reject) => {
const pass = fs.createReadStream(file);
const saxStream = require('sax').createStream(true, {});
const saxParser = saxStream._parser;
saxStream.on('opentag', (node) => {
this.open(saxParser.line, node);
});
saxStream.on('closetag', (name) => {
this.close(saxParser.line, name);
});
saxStream.on('ready', () => {
resolve(this.definitions);
});
saxStream.on('text', (t) => {
t = t.trim();
if (t.length > 0 && this.pending) {
this.value(saxParser.line, this.pending, t);
}
});
saxStream.on('error', (r) => {
reject(r);
});
pass.pipe(saxStream);
});
});
}
assign(node, target) {
if (!target) {
target = this.current;
}
const keys = Object.keys(node.attributes);
for (const k of keys) {
target[k] = node.attributes[k];
}
}
}
exports.XsdParser = XsdParser;
//# sourceMappingURL=xsd-parser.js.map