Created
March 3, 2021 00:15
-
-
Save arantesxyz/ec4bfdb53ad2440d27e8eccf82ef4a7b to your computer and use it in GitHub Desktop.
Custom error creator for checking empty strings. Depends on 'validator'
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
| import isEmpty, { IsEmptyOptions } from 'validator/lib/isEmpty' | |
| const checkEmpty = ( | |
| error: (message: string) => unknown, | |
| options?: IsEmptyOptions | |
| ) => (value: string, fieldName: string): void => { | |
| if (isEmpty(value, options)) { | |
| throw error(`Field ${fieldName} cannot be empty!`) | |
| } | |
| } | |
| export default checkEmpty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment