jarb-redux-form
Version:
Validating forms through JaRB.
99 lines (98 loc) • 2.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function required(label) {
return (value) => {
if (value == null || value === '') {
return {
type: 'ERROR_REQUIRED',
label,
value,
reasons: {
required: 'required'
}
};
}
return undefined;
};
}
exports.required = required;
function minimumLength(label, minimumLength) {
return (value) => {
if (value != null && value.length < minimumLength) {
return {
type: 'ERROR_MINIMUM_LENGTH',
label,
value,
reasons: {
minimumLength
}
};
}
return undefined;
};
}
exports.minimumLength = minimumLength;
function maximumLength(label, maximumLength) {
return (value) => {
if (value != null && value.length > maximumLength) {
return {
type: 'ERROR_MAXIMUM_LENGTH',
label,
value,
reasons: {
maximumLength
}
};
}
return undefined;
};
}
exports.maximumLength = maximumLength;
function minValue(label, minValue) {
return (value) => {
if (value != null && value < minValue) {
return {
type: 'ERROR_MIN_VALUE',
label,
value,
reasons: {
minValue
}
};
}
return undefined;
};
}
exports.minValue = minValue;
function maxValue(label, maxValue) {
return (value) => {
if (value != null && value > maxValue) {
return {
type: 'ERROR_MAX_VALUE',
label,
value,
reasons: {
maxValue
}
};
}
return undefined;
};
}
exports.maxValue = maxValue;
function pattern(label, regex) {
return (value) => {
if (value != null && regex.test(`${value}`) === false) {
return {
type: 'ERROR_PATTERN',
label,
value,
reasons: {
regex
}
};
}
return undefined;
};
}
exports.pattern = pattern;