filer/src/webpack-plugin/utils.js

27 lines
647 B
JavaScript
Raw Normal View History

2021-04-04 00:22:28 +00:00
var { validate } = require('schema-utils');
function validateOptions(options, schema) {
validate(schema, options);
2021-04-04 00:22:28 +00:00
}
function processOptions(options, processors) {
const processedOptions = {};
2021-04-04 00:22:28 +00:00
for (const [property, processor] of Object.entries(processors)) {
processedOptions[property] = options[property];
if (processedOptions[property] === undefined) {
processedOptions[property] = processor.default;
2021-04-04 00:22:28 +00:00
}
if (processor.process) {
processedOptions[property] = processor.process(processedOptions[property]);
}
}
2021-04-04 00:22:28 +00:00
return processedOptions;
2021-04-04 00:22:28 +00:00
}
module.exports = {
validateOptions,
processOptions,
2021-04-04 00:22:28 +00:00
};