@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
54 lines (53 loc) • 2.97 kB
TypeScript
import { RxapElement } from '../element';
import { ParsedElement } from '../elements/parsed-element';
import { XmlParserService } from '../xml-parser.service';
import { XmlSerializerService } from '../xml-serializer.service';
import { ElementParser } from './element.parser';
import { ElementSerializer } from './element.serializer';
import { TextContentElementOptions, TextContentElementMixin } from './mixins/text-content-element.mixin';
export interface ElementTextContentParserOptions<Value> extends TextContentElementOptions<Value> {
}
export interface ElementTextContentParser<T extends ParsedElement, Value> extends TextContentElementMixin<Value> {
}
export declare class ElementTextContentParser<T extends ParsedElement, Value> implements ElementParser<T> {
readonly propertyKey: string;
readonly options: ElementTextContentParserOptions<Value>;
constructor(propertyKey: string, options: ElementTextContentParserOptions<Value>);
parse(xmlParser: XmlParserService, element: RxapElement, parsedElement: T): T;
}
export interface ElementTextContentSerializerOptions<Value> extends TextContentElementOptions<Value> {
}
export interface ElementTextContentSerializer<T extends ParsedElement, Value> extends TextContentElementMixin<Value> {
}
export declare class ElementTextContentSerializer<T extends ParsedElement, Value> implements ElementSerializer<T> {
readonly propertyKey: string;
readonly options: ElementTextContentParserOptions<Value>;
constructor(propertyKey: string, options: ElementTextContentParserOptions<Value>);
serialize(xmlParser: XmlSerializerService, element: RxapElement, parsedElement: T): void;
}
/**
* Decorator factory that creates a decorator to parse and inject text content from a DOM element into a class property.
*
* This decorator factory allows customization through `ElementTextContentOptions`. It merges user-provided options
* with metadata options (if any) associated with the property. The merged options are then used to create an instance
* of `ElementTextContentParser` which is responsible for the actual parsing and assignment of the text content to the
* class property.
*
* If the `required` option is set to true, the property is also decorated with a `RequiredProperty` decorator to enforce
* its presence.
*
* @param {ElementTextContentParserOptions<Value>} [options={}] - Optional configuration options for element text content parsing.
* @returns A class property decorator that configures text content parsing based on the provided options.
*
* @template Value - The expected type of the property's value.
*
* ### Usage
*
* ```typescript
* class MyComponent {
* @ElementTextContent({ selector: '#myElement', required: true })
* public textContent: string;
* }
* ```
*/
export declare function ElementTextContent<Value>(options?: ElementTextContentParserOptions<Value> & ElementTextContentSerializerOptions<Value>): (target: any, propertyKey: string) => void;