/** * Parse error messages for a specific input. * * @param inputName string * @param allErrors Record> * @return string */ export function parseValidationErrors( allErrors: Record> = {} ): string | null { const errorList = Object.values(allErrors); if (!errorList.length) { return null; } return errorList .flat() .reduce( (oldInputString: string | null, inputString: string) => (oldInputString ? `${oldInputString}, ` : "") + inputString, null ); } /** * Parse error messages for a specific input. * * @param inputName string * @param allErrors Record> * @return string */ export function parseValidationInput( inputName: string, allErrors: Record> = {} ): string | null { let errorList = [] as Array; for (const value of Object.keys(allErrors)) { if (value == inputName) { errorList = allErrors[inputName]; } } return errorList.length ? errorList.reduce((oldString: string | null, string) => { return (oldString ? `${oldString}, ` : "") + string; }, null) : null; }