Skip to content

Commit 3708aef

Browse files
committed
Updated get options logic
1 parent 69f6864 commit 3708aef

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

lib/options.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -377,36 +377,39 @@ module.exports = {
377377
}
378378
];
379379

380-
// Filter options based on criteria
381-
if (_.isObject(criteria)) {
382-
const externalDefault = typeof criteria.external === 'boolean' ? criteria.external : true,
383-
usageDefault = ['CONVERSION'];
380+
optsArray = _.filter(optsArray, (option) => {
381+
if (option.disabled) { return false; }
384382

385-
typeof criteria.external === 'boolean' && (optsArray = _.filter(optsArray, { external: externalDefault }));
386-
(!_.isArray(criteria.usage) || _.isEmpty(criteria.usage)) && (criteria.usage = usageDefault);
383+
if (_.isObject(criteria)) {
384+
const externalDefault = typeof criteria.external === 'boolean' ? criteria.external : true,
385+
usageDefault = ['CONVERSION'];
387386

388-
if (_.isArray(criteria.usage)) {
389-
let tempOptsArray = [];
387+
(!_.isArray(criteria.usage) || _.isEmpty(criteria.usage)) && (criteria.usage = usageDefault);
390388

391-
_.forEach(criteria.usage, (usageCriteria) => {
392-
tempOptsArray = _.concat(tempOptsArray, _.filter(optsArray, (option) => {
393-
return _.includes(option.usage, usageCriteria);
394-
}));
395-
});
396-
optsArray = tempOptsArray;
397-
}
389+
if (option.external !== externalDefault) {
390+
return false;
391+
}
398392

399-
if (_.has(criteria, 'moduleVersion')) {
400-
optsArray = _.filter(optsArray, (option) => {
401-
return _.includes(option.supportedModuleVersion, criteria.moduleVersion);
402-
});
403-
}
404-
else {
405-
optsArray = _.filter(optsArray, (option) => {
406-
return _.includes(option.supportedModuleVersion, MODULE_VERSION.V1);
407-
});
393+
if (_.isArray(criteria.usage)) {
394+
/**
395+
* We return return a option if any of the criteria.usage value matches with what is
396+
* available in option.usage
397+
*/
398+
if (_.difference(criteria.usage, option.usage).length === criteria.usage.length) {
399+
return false;
400+
}
401+
}
402+
403+
// Setting default value
404+
criteria.moduleVersion = _.has(criteria, 'moduleVersion') ? criteria.moduleVersion : MODULE_VERSION.V1;
405+
406+
if (!_.includes(option.supportedModuleVersion, criteria.moduleVersion)) {
407+
return false;
408+
}
408409
}
409-
}
410+
411+
return true;
412+
});
410413

411414
if (mode === 'use') {
412415
// options to be used as default kv-pairs
@@ -425,10 +428,6 @@ module.exports = {
425428
return defOptions;
426429
}
427430

428-
// options to be used as documentation
429-
return _.filter(optsArray, (opt) => {
430-
// only return options that are not disabled
431-
return opt.disabled !== true;
432-
});
431+
return optsArray;
433432
}
434433
};

0 commit comments

Comments
 (0)