UNPKG

1.48 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.IsByteLength = exports.isByteLength = exports.IS_BYTE_LENGTH = void 0;
7const ValidateBy_1 = require("../common/ValidateBy");
8const isByteLength_1 = __importDefault(require("validator/lib/isByteLength"));
9exports.IS_BYTE_LENGTH = 'isByteLength';
10/**
11 * Checks if the string's length (in bytes) falls in a range.
12 * If given value is not a string, then it returns false.
13 */
14function isByteLength(value, min, max) {
15 return typeof value === 'string' && (0, isByteLength_1.default)(value, { min, max });
16}
17exports.isByteLength = isByteLength;
18/**
19 * Checks if the string's length (in bytes) falls in a range.
20 * If given value is not a string, then it returns false.
21 */
22function IsByteLength(min, max, validationOptions) {
23 return (0, ValidateBy_1.ValidateBy)({
24 name: exports.IS_BYTE_LENGTH,
25 constraints: [min, max],
26 validator: {
27 validate: (value, args) => isByteLength(value, args.constraints[0], args.constraints[1]),
28 defaultMessage: (0, ValidateBy_1.buildMessage)(eachPrefix => eachPrefix + "$property's byte length must fall into ($constraint1, $constraint2) range", validationOptions),
29 },
30 }, validationOptions);
31}
32exports.IsByteLength = IsByteLength;
33//# sourceMappingURL=IsByteLength.js.map
\No newline at end of file