Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Created February 15, 2021 12:40
Show Gist options
  • Save AllGistsEqual/1abc53088800970614628bbe927e84e2 to your computer and use it in GitHub Desktop.
Save AllGistsEqual/1abc53088800970614628bbe927e84e2 to your computer and use it in GitHub Desktop.
// File: src/index.js
// Recursively iterate over the config to check types and reset properties to default if they are the wrong type
bot.configIterator = function configIterator(startPoint, startPointInSchema) {
Object.keys(startPointInSchema).forEach(property => {
if (!has(startPoint, property)) {
if (startPointInSchema[property].type !== 'object') {
startPoint[property] = startPointInSchema[property].default
} else {
startPoint[property] = {}
}
}
if (startPointInSchema[property].type === 'object') {
configIterator(startPoint[property], startPointInSchema[property].default)
}
if (
!Array.isArray(startPoint[property]) &&
typeof startPoint[property] !== startPointInSchema[property].type
) {
startPoint[property] = startPointInSchema[property].default
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment