Created
November 25, 2016 05:40
-
-
Save akirattii/f23ae67359e93a16965af21e6da3f2f4 to your computer and use it in GitHub Desktop.
check if not empty: snippet to get var's name
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
| var foo, baz; | |
| notEmpty({ foo, baz }); // Error "'foo', 'baz', required" thrown | |
| function notEmpty(obj) { | |
| let names = ""; | |
| for (let key in obj) | |
| if (!obj[key]) names += `'${key}', `; | |
| if (names) | |
| throw Error(`${names}required`); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment