UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

23 lines (18 loc) 498 B
import { FormFieldType, ValidationFunction } from '../Field.interface'; import { validateEmail } from './validateEmail'; import { validateJSON } from './validateJson'; export function getValidationFun<T>( type: FormFieldType, validation?: (value?: T) => boolean ) { if (validation) { return validation; } if (type === 'email') { return validateEmail as ValidationFunction; } if (type === 'json') { return validateJSON as ValidationFunction; } return () => true; }