UNPKG

1.11 kBJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2import isLengthValidator from 'validator/lib/isLength';
3export const MIN_LENGTH = 'minLength';
4/**
5 * Checks if the string's length is not less than given number. Note: this function takes into account surrogate pairs.
6 * If given value is not a string, then it returns false.
7 */
8export function minLength(value, min) {
9 return typeof value === 'string' && isLengthValidator(value, { min });
10}
11/**
12 * Checks if the string's length is not less than given number. Note: this function takes into account surrogate pairs.
13 * If given value is not a string, then it returns false.
14 */
15export 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//# sourceMappingURL=MinLength.js.map
\No newline at end of file