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

60 lines 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChildrenElementMixin = void 0; const tslib_1 = require("tslib"); const mixin_1 = require("@rxap/mixin"); const required_element_mixin_1 = require("./required-element.mixin"); const utilities_1 = require("@rxap/utilities"); let ChildrenElementMixin = class ChildrenElementMixin { constructor(options = {}) { this.options = options; } get min() { return (0, utilities_1.hasIndexSignature)(this.options) && this.options['min'] ? this.options.min : null; } get max() { return (0, utilities_1.hasIndexSignature)(this.options) && this.options['max'] ? this.options.max : null; } getChildren(element) { let elementChildren; if (this.options.group) { const groupElement = element.getChild(this.options.group); if (!groupElement && this.required) { return null; } if (groupElement) { elementChildren = groupElement.getAllChildNodes(); } else { elementChildren = []; } } else { elementChildren = element.getAllChildNodes(); } return elementChildren; } coerceGroup(element) { if (this.options.group) { if (element.hasChild(this.options.group)) { element = element.getChild(this.options.group); } else { element = element.addChild(this.options.group); } } return element; } setChildren(element, children, xmlParser) { element = this.coerceGroup(element); for (const child of children) { xmlParser.serialize(child, element); } } }; exports.ChildrenElementMixin = ChildrenElementMixin; exports.ChildrenElementMixin = ChildrenElementMixin = tslib_1.__decorate([ (0, mixin_1.Mixin)(required_element_mixin_1.RequiredElementMixin), tslib_1.__metadata("design:paramtypes", [Object]) ], ChildrenElementMixin); //# sourceMappingURL=children-element.mixin.js.map