UNPKG

bonsai-analyzer

Version:
42 lines (33 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = filterModules; function makeRecordLikeRegExpFilter(field, re) { return function (eModule) { if (re && !re.test(eModule[field])) { return false; } return true; }; } function toNumber(value) { return value === '' ? '' : Number(value); } function makeRecordRangeFilter(field, min, max) { return function (eModule) { if (min !== '' && max !== '') { return eModule[field] >= min && eModule[field] <= max; } if (min !== '') { return eModule[field] >= min; } if (max !== '') { return eModule[field] <= max; } return true; }; } function filterModules(extendedModules, filters) { return extendedModules.filter(makeRecordLikeRegExpFilter('name', new RegExp(filters.moduleName))).filter(makeRecordRangeFilter('cumulativeSize', toNumber(filters.cumulativeSizeMin), toNumber(filters.cumulativeSizeMax))).filter(makeRecordRangeFilter('requiredByCount', toNumber(filters.requiredByCountMin), toNumber(filters.requiredByCountMax))).filter(makeRecordRangeFilter('requirementsCount', toNumber(filters.requirementsCountMin), toNumber(filters.requirementsCountMax))); }