@nish1896/rhf-mui-components
Version:
A suite of 20+ reusable Material UI components for React Hook Form to minimize your time and effort in creating and styling forms
20 lines (19 loc) • 682 B
JavaScript
import { generateLabelValueErrMsg } from '../utils';
function isStrNumArray(arr) {
return arr.every(el => typeof el === 'number' || typeof el === 'string');
}
export function validateArray(formElementName, options, labelKey, valueKey) {
const isScalarArr = isStrNumArray(options);
if (!isScalarArr && (!labelKey || !valueKey)) {
throw new Error(generateLabelValueErrMsg(formElementName));
}
}
export function isKeyValueOption(option, labelKey, valueKey) {
if (typeof option !== 'object' || option === null) {
return false;
}
if (!labelKey || !valueKey) {
return false;
}
return labelKey in option && valueKey in option;
}