3 const logger
= require('gitter-web-env').logger
;
6 * createOptionsValidator creates a function that will accept options and
7 * log out all unexpected key-value pairs in those options
9 * @param {String} validatorName unique name for identifying log messages
10 * @param {Map<String,Boolean>} expectedOptionNames allowed options as keys with true as value,
11 * all other options are going to be warnings in logs
14 * createOptionsValidator(
15 * 'restful.serializeChatsForTroupe',
19 const createOptionsValidator
= (validatorName
, expectedOptionNames
) => options
=> {
20 const allOptionNames
= Object
.keys(options
);
21 const unexpectedOptionNames
= allOptionNames
.filter(
22 optionName
=> !expectedOptionNames
[optionName
]
25 if (unexpectedOptionNames
.length
=== 0) {
29 const unexpectedOptions
= unexpectedOptionNames
.reduce(
30 (partialOptions
, optionName
) => ({
32 [optionName
]: options
[optionName
]
36 logger
.warn(`unexpected options - ${validatorName} - ${JSON.stringify(unexpectedOptions)}`);
39 module
.exports
= { createOptionsValidator
};