Created
January 13, 2016 13:51
-
-
Save Noitidart/c4ab4ca10ff5861c720b to your computer and use it in GitHub Desktop.
_ff-addon-snippet-validateOptionsObj - What I use to validae options
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
function validateOptionsObj(aOptions, aOptionsDefaults) { | |
// ensures no invalid keys are found in aOptions, any key found in aOptions not having a key in aOptionsDefaults causes throw new Error as invalid option | |
for (var aOptKey in aOptions) { | |
if (!(aOptKey in aOptionsDefaults)) { | |
console.error('aOptKey of ' + aOptKey + ' is an invalid key, as it has no default value, aOptionsDefaults:', aOptionsDefaults, 'aOptions:', aOptions); | |
throw new Error('aOptKey of ' + aOptKey + ' is an invalid key, as it has no default value'); | |
} | |
} | |
// if a key is not found in aOptions, but is found in aOptionsDefaults, it sets the key in aOptions to the default value | |
for (var aOptKey in aOptionsDefaults) { | |
if (!(aOptKey in aOptions)) { | |
aOptions[aOptKey] = aOptionsDefaults[aOptKey]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
README
Rev1
I use it like this: