lib/parser.js
function (projection = '') {

      //prepare projections
      let fields = _.compact(projection.split(','));
      fields = _.map(fields, _.trim);
      fields = _.uniq(fields);
      const accumulator = {};

      _.forEach(fields, function (field) {

        //if exclude e.g -name
        if (field[0] === '-') {
          accumulator[field.substring(1)] = 0;
        }

        //if include i.e name
        else {
          accumulator[field] = 1;
        }

      });

      return accumulator;
    }
function (projection = '') {

      //prepare projections
      let fields = _.compact(projection.split(','));
      fields = _.map(fields, _.trim);
      fields = _.uniq(fields);
      const accumulator = {};

      _.forEach(fields, function (field) {

        //if exclude e.g -name
        if (field[0] === '-') {
          accumulator[field.substring(1)] = 0;
        }

        //if include i.e name
        else {
          accumulator[field] = 1;
        }

      });

      return accumulator;
    }
function ( projection = '' ) { //prepare projections let fields = _ . compact ( projection . split ( ',' ) ) ; fields = _ . map ( fields , _ . trim ) ; fields = _ . uniq ( fields ) ; const accumulator = { } ; _ . forEach ( fields , function ( field ) { //if exclude e.g -name if ( field [ 0 ] === '-' ) { accumulator [ field . substring ( 1 ) ] = 0 ; } //if include i.e name else { accumulator [ field ] = 1 ; } } ) ; return accumulator ; }
parse comma separated fields into mongodb awase projections
parse comma separated fields into mongodb awase projections