isRequired.js 409 B

12345678910111213141516
  1. /**
  2. * A function which can be used as a function parameter default which throws an error
  3. * if the parameter is undefined
  4. *
  5. * @param {string} [varname] - name of the variable for the output
  6. * @throws {Error}
  7. */
  8. function isRequired (varname) {
  9. const message = varname
  10. ? `missing parameter '${varname}'`
  11. : 'missing parameter';
  12. throw Error(message);
  13. }
  14. module.exports = isRequired;