UNPKG

@allgemein/schema-api

Version:
32 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MinLength = MinLength; const lodash_1 = require("lodash"); const AnnotationsHelper_1 = require("../../lib/AnnotationsHelper"); const DefaultValidator_1 = require("../../lib/validation/DefaultValidator"); function MinLength(value, options) { return function (source, propertyName) { const opts = { minLength: value }; if (options) { (0, lodash_1.assign)(opts, { validateOptions: { minLength: {} } }); (0, lodash_1.assign)(opts.validateOptions.minLength, options); } AnnotationsHelper_1.AnnotationsHelper.forPropertyOn(source.constructor, propertyName, opts, 'merge'); }; } DefaultValidator_1.DefaultValidator.define({ name: 'minLength', fn: (value, opts, instance) => { if ((0, lodash_1.isString)(value)) { return value.length >= opts.minLength; } return false; }, defaultOptions: { message: 'Length of property "%propertyName" must be greeter then %options.minLength.' }, involveOnOptionKey: 'minLength' }); //# sourceMappingURL=MinLength.js.map