all files / modules/utils/ filterProperties.js

25% Statements 3/12
0% Branches 0/6
0% Functions 0/2
25% Lines 3/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26                                             
/**
 * Returns a shallow copy of the properties of the given object,
 * filtered by the functions in propertyTypes.
 */
 const {forEach, keys} = require("ramda");
 function filterProperties(object, propertyTypes) {
     const properties = {};
 
     let type, value;
     forEach(function (property) {
         type = propertyTypes[property];
 
         if (typeof type === "function" && object.hasOwnProperty(property)) {
             value = type(object[property]);
 
             if (value !== undefined) {
                 properties[property] = value;
             }
         }
     }, keys(object));
 
     return properties;
 }
 
 module.exports = filterProperties;