46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.UNECEPageParser = void 0;
|
|
const htmlparser2_1 = require("htmlparser2");
|
|
const uneceDomHandler_1 = require("./uneceDomHandler");
|
|
const tsm_1 = require("@initics/tsm");
|
|
const util_1 = require("../util");
|
|
class UNECEPageParser {
|
|
constructor(smdef) {
|
|
this.sm = new tsm_1.StateMachine(smdef);
|
|
}
|
|
get spec() {
|
|
if (!this._spec) {
|
|
throw new Error(`EdifactMessageSpecification not defined`);
|
|
}
|
|
return this._spec;
|
|
}
|
|
parse(page) {
|
|
const parser = new htmlparser2_1.Parser(this.setupHandler());
|
|
parser.write(page);
|
|
parser.end();
|
|
}
|
|
setupHandler() {
|
|
return new class extends uneceDomHandler_1.UNECEDomHandler {
|
|
onOpenTag() {
|
|
}
|
|
onText() {
|
|
}
|
|
}();
|
|
}
|
|
extractTextValue(text, regex, index = 0) {
|
|
const arr = regex.exec(text);
|
|
if ((0, util_1.isDefined)(arr)) {
|
|
return arr[index];
|
|
}
|
|
return "";
|
|
}
|
|
throwInvalidParserState(state) {
|
|
throw new Error(`Invalid parser state: ${state}`);
|
|
}
|
|
throwCouldNotParsePage() {
|
|
throw new Error('Could not parse page');
|
|
}
|
|
}
|
|
exports.UNECEPageParser = UNECEPageParser;
|
|
//# sourceMappingURL=unecePageParser.js.map
|