renovate/lib/config/massage.js
2017-08-18 19:24:27 +02:00

39 lines
978 B
JavaScript

const options = require('./definitions').getOptions();
const allowedStrings = [];
options.forEach(option => {
if (option.allowString) {
allowedStrings.push(option.name);
}
});
module.exports = {
massageConfig,
};
// Returns a massaged config
function massageConfig(config) {
const massagedConfig = { ...config };
for (const key of Object.keys(config)) {
const val = config[key];
if (allowedStrings.includes(key) && typeof val === 'string') {
massagedConfig[key] = [val];
} else if (isObject(val)) {
massagedConfig[key] = massageConfig(val);
} else if (Array.isArray(val)) {
massagedConfig[key] = [];
val.forEach(item => {
if (isObject(item)) {
massagedConfig[key].push(massageConfig(item));
} else {
massagedConfig[key].push(item);
}
});
}
}
return massagedConfig;
}
function isObject(obj) {
return Object.prototype.toString.call(obj) === '[object Object]';
}