UNPKG

@react-form-fields/core

Version:

Material UI Form Fields

33 lines 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var validator = require('validatorjs'); validator.setMessages('en', require('validatorjs/src/lang/en')); function validate(fieldName, value, rules, context, attributeNames, customMessages) { var _a, _b; if (context === void 0) { context = {}; } if (attributeNames === void 0) { attributeNames = {}; } if (customMessages === void 0) { customMessages = null; } if (!rules) return { valid: true }; fieldName = fieldName || 'value'; var result = new validator(tslib_1.__assign((_a = {}, _a[fieldName] = value, _a), context), (_b = {}, _b[fieldName] = rules, _b), customMessages); if (attributeNames) { result.setAttributeNames(attributeNames); } if (result.passes()) { return { valid: true }; } var allErrors = result.errors.all(); return { valid: false, message: allErrors[fieldName][0] }; } exports.validate = validate; function useLang(lang) { validator.useLang(lang); } exports.useLang = useLang; function addLang(lang, messages) { validator.setMessages(lang, messages); } exports.addLang = addLang; //# sourceMappingURL=index.js.map