import { validate as builtValidate } from '../../utils/string'; export type Validate = ((value: string) => boolean) | keyof typeof builtValidate; export function getState(params: { value: string; validate?: Validate; required?: boolean }) { const { value, validate, required } = params; if (value) { if (validate) { if (typeof validate === 'string') { return builtValidate[validate](value) ? 'complete' : 'fail'; } else { return validate(value) ? 'complete' : 'fail'; } } else { return 'complete'; } } else { return required ? 'empty' : 'undefined'; } }