UNPKG

@allgemein/schema-api

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