Last active
September 12, 2022 21:16
-
-
Save michael-lynch/b6d2ab23a02ecc3556c85ec6d6a404f5 to your computer and use it in GitHub Desktop.
Validate type of input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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