UNPKG

979 BJavaScriptView Raw
1import { buildMessage, ValidateBy } from '../common/ValidateBy';
2export const ARRAY_MAX_SIZE = 'arrayMaxSize';
3/**
4 * Checks if the array's length is less or equal to the specified number.
5 * If null or undefined is given then this function returns false.
6 */
7export function arrayMaxSize(array, max) {
8 return Array.isArray(array) && array.length <= max;
9}
10/**
11 * Checks if the array's length is less or equal to the specified number.
12 * If null or undefined is given then this function returns false.
13 */
14export function ArrayMaxSize(max, validationOptions) {
15 return ValidateBy({
16 name: ARRAY_MAX_SIZE,
17 constraints: [max],
18 validator: {
19 validate: (value, args) => arrayMaxSize(value, args.constraints[0]),
20 defaultMessage: buildMessage(eachPrefix => eachPrefix + '$property must contain not more than $constraint1 elements', validationOptions),
21 },
22 }, validationOptions);
23}
24//# sourceMappingURL=ArrayMaxSize.js.map
\No newline at end of file