Skip to content

Instantly share code, notes, and snippets.

@akirattii
Created November 25, 2016 05:40
Show Gist options
  • Save akirattii/f23ae67359e93a16965af21e6da3f2f4 to your computer and use it in GitHub Desktop.
Save akirattii/f23ae67359e93a16965af21e6da3f2f4 to your computer and use it in GitHub Desktop.
check if not empty: snippet to get var's name
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