Created
May 12, 2014 14:19
-
-
Save darkowlzz/e97f9c9a6cd8a2df0f3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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