Skip to content

Instantly share code, notes, and snippets.

@mudssrali
Last active March 23, 2021 06:38
Show Gist options
  • Save mudssrali/f1be8be48d6d8933a88db412510c9edf to your computer and use it in GitHub Desktop.
Save mudssrali/f1be8be48d6d8933a88db412510c9edf to your computer and use it in GitHub Desktop.
check compulsory fields in an object
// @param obj: for which the given properties exist
// @param fields[]: is an array of given object properties
// @return false if every field is not blank
// @return an array of labels that are blank

const checkCompulsoryFields = (obj: any, fields: string[]): boolean | string[] => {
	const list = fields.filter(field => field in obj && obj[field].trim() === "")
	return list.length === 0 ? false : list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment