All files / mongoose/lib/helpers/projection parseProjection.js

5.55% Statements 1/18
0% Branches 0/14
0% Functions 0/1
5.88% Lines 1/17

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 33 34              1x                                                    
'use strict';
 
/**
 * Convert a string or array into a projection object, retaining all
 * `-` and `+` paths.
 */
 
module.exports = function parseProjection(v, retainMinusPaths) {
  const type = typeof v;
 
  if (type === 'string') {
    v = v.split(/\s+/);
  }
  if (!Array.isArray(v) && Object.prototype.toString.call(v) !== '[object Arguments]') {
    return v;
  }
 
  const len = v.length;
  const ret = {};
  for (let i = 0; i < len; ++i) {
    let field = v[i];
    if (!field) {
      continue;
    }
    const include = '-' == field[0] ? 0 : 1;
    if (!retainMinusPaths && include === 0) {
      field = field.substring(1);
    }
    ret[field] = include;
  }
 
  return ret;
};