All files / mongoose/lib/helpers omitUndefined.js

8.33% Statements 1/12
0% Branches 0/10
0% Functions 0/1
9.09% Lines 1/11

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    1x                                    
'use strict';
 
module.exports = function omitUndefined(val) {
  if (val == null || typeof val !== 'object') {
    return val;
  }
  if (Array.isArray(val)) {
    for (let i = val.length - 1; i >= 0; --i) {
      if (val[i] === undefined) {
        val.splice(i, 1);
      }
    }
  }
  for (const key of Object.keys(val)) {
    if (val[key] === void 0) {
      delete val[key];
    }
  }
  return val;
};