All files / style9/src/utils helpers.js

100% Statements 11/11
100% Branches 2/2
100% Functions 6/6
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 27 28 29 30 31 32  463x       360x       65x       122x     122x 160x 95x       122x     8x            
function mapObject(object, cb) {
  return Object.fromEntries(Object.entries(object).map(cb));
}
 
function mapObjectValues(object, cb) {
  return mapObject(object, ([key, value]) => [key, cb(value)]);
}
 
function removeDuplicates(list) {
  return list.filter((prop, index, array) => array.indexOf(prop) === index);
}
 
function filterObjectKeys(obj, keys) {
  const newObj = {};
 
  // Iterate in existing order
  for (const key in obj) {
    if (keys.includes(key)) {
      newObj[key] = obj[key];
    }
  }
 
  return newObj;
}
 
module.exports = {
  mapObject,
  mapObjectValues,
  removeDuplicates,
  filterObjectKeys
};