Skip to content

Instantly share code, notes, and snippets.

@darkowlzz
Created May 12, 2014 14:19
Show Gist options
  • Save darkowlzz/e97f9c9a6cd8a2df0f3d to your computer and use it in GitHub Desktop.
Save darkowlzz/e97f9c9a6cd8a2df0f3d to your computer and use it in GitHub Desktop.
include: {
is: ['string', 'array', 'regexp', 'object'],
ok: (rule) => {
function checkURL(r) {
if (isRegExpOrString(r))
return true;
if (Array.isArray(r) && r.length > 0)
return r.every(isRegExpOrString);
return false;
}
function checkContentType(r) {
if (typeof r === 'string')
return true;
if (Array.isArray(r) && r.length > 0)
return r.every((v) => typeof v === 'string')
return false;
}
// If rule is an object check url and contentType
if (typeof rule === 'object') {
if (rule.url && rule.contentType) {
if (checkURL(rule.url) && checkContentType(rule.contentType)) {
return true;
}
return false;
}
return false;
}
else {
if (checkURL(rule))
return true;
return false;
}
},
msg: 'The `include` option must always contain atleast one rule as a string, regular expression, or an array of strings and regular expressions.'
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment