Skip to content

Instantly share code, notes, and snippets.

@JaeYeopHan
Created February 26, 2018 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaeYeopHan/ef6b3243559ae51b532b36f14eaa4acc to your computer and use it in GitHub Desktop.
Save JaeYeopHan/ef6b3243559ae51b532b36f14eaa4acc to your computer and use it in GitHub Desktop.
JavaScript code snippets - Required parameter function
export 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
}
// Use
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