@apizr-io/class-utils
Version:
Package containing all class-validator function with all custom apizr class validation functions
33 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StartsWith = void 0;
const class_validator_1 = require("class-validator");
function StartsWith(startValue, validationOptions) {
return (object, propertyName) => {
const startValues = Array.isArray(startValue) ? startValue : [startValue];
(0, class_validator_1.registerDecorator)({
name: 'startsWith',
target: object.constructor,
propertyName,
constraints: startValues,
options: {
message: (value) => {
return `String ${value.property} must start with one of [${startValues.join(',')}] string`;
},
...validationOptions,
},
validator: {
validate(value) {
if (typeof value !== 'string') {
return false;
}
return startValues.reduce((acc, el) => {
return acc || value.startsWith(el);
}, false);
},
},
});
};
}
exports.StartsWith = StartsWith;
//# sourceMappingURL=string.decorator.js.map