domotz-remote-pawn
Version:
Domotz Agent
41 lines (35 loc) • 1.26 kB
JavaScript
function ServiceFilter(resourceLocator) {
var myConsole = resourceLocator.log.decorateLogs();
var lodash = resourceLocator.lodash;
function isServiceIgnored(ignoredServices, service) {
return ignoredServices.indexOf(service.service) !== -1;
}
function cleanupObject(obj) {
/* cleans an object removing empty values {}, null, undefined */
lodash.forIn(obj, function (value, key) {
if (lodash.isObject(value)) {
if (Object.keys(value).length === 0) {
delete obj[key];
} else {
cleanupObject(value);
}
} else if (value === undefined || value === null) {
delete obj[key];
}
});
}
function ignorePaths(pathsToIgnore, service) {
pathsToIgnore.forEach(function (path) {
if (lodash.get(service, path)) {
myConsole.debug('removing value for path %s', path);
lodash.set(service, path, null);
}
});
}
return {
isServiceIgnored: isServiceIgnored,
ignorePaths: ignorePaths,
cleanupObject: cleanupObject,
};
}
module.exports.service_filter = ServiceFilter;