@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
30 lines • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RequiredProperty = RequiredProperty;
const metadata_keys_1 = require("./metadata-keys");
const reflect_metadata_1 = require("@rxap/reflect-metadata");
/**
* Decorator that marks a property of a class as required. It optionally allows for a custom message to be specified.
* If no message is provided, a default message indicating that the property is required will be used.
*
* @param message - Optional custom message to display if the property is not provided.
* @returns A decorator function that takes the target object and the property key as arguments.
*
* ### Usage
*
* ```typescript
* class MyComponent {
* @RequiredProperty('Custom message for missing property')
* importantProperty: string;
* }
* ```
*
* In this example, `importantProperty` is marked as required. If `importantProperty` is not provided,
* "Custom message for missing property" will be displayed as an error message.
*/
function RequiredProperty(message) {
return function (target, propertyKey) {
(0, reflect_metadata_1.mergeWithMetadata)(metadata_keys_1.ElementParserMetaData.REQUIRED_ELEMENT_PROPERTIES, { [propertyKey]: message || `Element property '${propertyKey}' is required.` }, target);
};
}
//# sourceMappingURL=required-property.js.map