UNPKG

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