Skip to content

Instantly share code, notes, and snippets.

@jossmac
Last active April 18, 2018 01:24
Show Gist options
  • Save jossmac/cf792fca4a73a3cd6d0056d3a136d51d to your computer and use it in GitHub Desktop.
Save jossmac/cf792fca4a73a3cd6d0056d3a136d51d to your computer and use it in GitHub Desktop.
Helper function for required parameters, from http://tinyurl.com/ychkf5oq
function requiredParam (param) {
const requiredParamError = new Error(
`Required parameter, "${param}" is missing.`
)
// preserve original stack trace
if (typeof Error.captureStackTrace === ‘function’) {
Error.captureStackTrace(
requiredParamError,
requiredParam
)
}
throw requiredParamError
}
/*
function findUsersByRole ({
role = requiredParam('role'),
withContactInfo,
includeInactive
} = {}) {...}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment