UNPKG

@rxap/xml-parser

Version:

Provides a set of decorators and services for parsing and serializing XML documents into TypeScript classes. It simplifies the process of mapping XML elements and attributes to class properties, handling data validation, and serializing objects back into

46 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PathElementMixin = void 0; const tslib_1 = require("tslib"); const mixin_1 = require("@rxap/mixin"); const required_element_mixin_1 = require("./required-element.mixin"); let PathElementMixin = class PathElementMixin { constructor(options = {}) { this.options = options; } applyPath(element) { var _a; const root = element; if ((_a = this.options.path) === null || _a === void 0 ? void 0 : _a.length) { for (const fragment of this.options.path) { if (element.hasChild(fragment)) { element = element.getChild(fragment); } else if (this.required) { throw new Error(`The fragment '${fragment}' of path '${this.options.path}' could not resolve from element <${root.name}>!`); } } } return element; } coercePath(element) { var _a; if ((_a = this.options.path) === null || _a === void 0 ? void 0 : _a.length) { for (const fragment of this.options.path) { if (element.hasChild(fragment)) { element = element.getChild(fragment); } else { element = element.addChild(fragment); } } } return element; } }; exports.PathElementMixin = PathElementMixin; exports.PathElementMixin = PathElementMixin = tslib_1.__decorate([ (0, mixin_1.Mixin)(required_element_mixin_1.RequiredElementMixin), tslib_1.__metadata("design:paramtypes", [Object]) ], PathElementMixin); //# sourceMappingURL=path-element.mixin.js.map