1 | import { buildMessage, ValidateBy } from '../common/ValidateBy';
|
2 | import isLengthValidator from 'validator/lib/isLength';
|
3 | export const MIN_LENGTH = 'minLength';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export function minLength(value, min) {
|
9 | return typeof value === 'string' && isLengthValidator(value, { min });
|
10 | }
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export function MinLength(min, validationOptions) {
|
16 | return ValidateBy({
|
17 | name: MIN_LENGTH,
|
18 | constraints: [min],
|
19 | validator: {
|
20 | validate: (value, args) => minLength(value, args.constraints[0]),
|
21 | defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must be longer than or equal to $constraint1 characters', validationOptions),
|
22 | },
|
23 | }, validationOptions);
|
24 | }
|
25 |
|
\ | No newline at end of file |