Skip to content

Instantly share code, notes, and snippets.

@michael-lynch
Last active September 12, 2022 21:16
Show Gist options
  • Select an option

  • Save michael-lynch/b6d2ab23a02ecc3556c85ec6d6a404f5 to your computer and use it in GitHub Desktop.

Select an option

Save michael-lynch/b6d2ab23a02ecc3556c85ec6d6a404f5 to your computer and use it in GitHub Desktop.
Validate type of input
export const isDate = date => {
const dateTest = new Date(date);
return (
dateTest && Object.prototype.toString.call(dateTest) === '[object Date]' && !isNaN(dateTest)
);
};
export const isNumber = value => {
return typeof value === 'number' && !Number.isNaN(value);
};
export const isEmpty = value => {
return (
value == null ||
(typeof value === 'object' && Object.keys(value).length === 0) ||
(typeof value === 'string' && value.trim().length === 0)
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment