UNPKG

nowjs-core

Version:

NowCanDo Javascript Core [nowjs-core] is a library written by TypeScript code maintains under Apache 2.0 licence

32 lines (31 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("../index"); exports.VALIDATOR_NOTCONTAINS_METADATA_KEY = Symbol('validation:validator:isNotContains'); function isNotContains(value, errorMessage) { return (target, propertyKey, descriptor) => { const original = descriptor.value; Reflect.defineMetadata(exports.VALIDATOR_NOTCONTAINS_METADATA_KEY, null, target, propertyKey); Reflect.defineMetadata(index_1.VALIDATOR_METADATA_KEY, new NotContainsValidator(value, errorMessage), target, propertyKey); }; } exports.isNotContains = isNotContains; class NotContainsValidator extends index_1.ValidatorBase { constructor(value, errorMessage = 'The value of ${DisplayName} must greater than min: ${Min} .') { super('NotContains', errorMessage); this.value = value; } get Value() { return this.value; } validate(context) { if (context.Value === undefined || context.Value === null) { return Promise.resolve(true); } if (context.Value.search(this.value) > 0) { return Promise.reject(new index_1.ValidatorException(this.Name, context.Target, context.PropertyName, this.formatErrorMessage(context))); } return Promise.resolve(true); } } exports.NotContainsValidator = NotContainsValidator;