-
-
Save AllGistsEqual/1abc53088800970614628bbe927e84e2 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
// 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