UNPKG

datatypes-validation

Version:

![](https://img.shields.io/npm/v/datatypes-validation.svg) ![](https://img.shields.io/npm/dm/datatypes-validation.svg) ![](coverage/badge-lines.svg) ![](coverage/badge-functions.svg) ![](coverage/badge-statements.svg) ![](coverage/badge-branches.svg)

27 lines 1.37 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); function minLength(min, options = {}) { return (field) => __awaiter(this, void 0, void 0, function* () { const isNull = field.value === undefined || field.value === null; if (!field.error && !isNull) { if ((typeof field.value === 'string' || Array.isArray(field.value))) { if (field.value.length < min) { field.applyError('minLength', Object.assign({}, options, { context: { min } })); } } else { throw new Error('The minLength works only with string or array'); } } }); } exports.minLength = minLength; //# sourceMappingURL=minLength.js.map