1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | exports.MaxLength = exports.maxLength = exports.MAX_LENGTH = void 0;
|
7 | const ValidateBy_1 = require("../common/ValidateBy");
|
8 | const isLength_1 = __importDefault(require("validator/lib/isLength"));
|
9 | exports.MAX_LENGTH = 'maxLength';
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function maxLength(value, max) {
|
15 | return typeof value === 'string' && (0, isLength_1.default)(value, { min: 0, max });
|
16 | }
|
17 | exports.maxLength = maxLength;
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function MaxLength(max, validationOptions) {
|
23 | return (0, ValidateBy_1.ValidateBy)({
|
24 | name: exports.MAX_LENGTH,
|
25 | constraints: [max],
|
26 | validator: {
|
27 | validate: (value, args) => maxLength(value, args.constraints[0]),
|
28 | defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + '$property must be shorter than or equal to $constraint1 characters', validationOptions),
|
29 | },
|
30 | }, validationOptions);
|
31 | }
|
32 | exports.MaxLength = MaxLength;
|
33 |
|
\ | No newline at end of file |