wiseService/wiseSource.js
/**
   * Util function to parse CSV formatted data
   * @param {string} body - the raw CSV data
   * @param {function} setCb - the function to call for each row found
   * @param {function} endCB - all done parsing
   */
Util function to parse CSV formatted data
@param {string} body - the raw CSV data
@param {function} setCb - the function to call for each row found
@param {function} endCB - all done parsing
Util function to parse CSV formatted data @param { string } body - the raw CSV data @param { function } setCb - the function to call for each row found @param { function } endCB - all done parsing
parseCSV (body, setCb, endCb) {
    csv.parse(body, { skip_empty_lines: true, comment: '#', relax_column_count: true }, (err, data) => {
      if (err) {
        return endCb(err);
      }
      for (let i = 0; i < data.length; i++) {
        const args = [];
        for (const k in this.shortcuts) {
          if (data[i][k] !== undefined && data[i][k] !== '') {
            args.push(this.shortcuts[k].pos);
            if (this.shortcuts[k].mod === 1) {
              args.push(data[i][k].toLowerCase());
            } else if (this.shortcuts[k].mod === 2) {
              args.push(data[i][k].toUpperCase());
            } else {
              args.push(data[i][k]);
            }
          }
        }
        if (args.length === 0) {
          setCb(data[i][this.column], WISESource.emptyResult);
        } else {
          setCb(data[i][this.column], WISESource.encodeResult.apply(null, args));
        }
      }
      endCb(err);
    });
  }
parseCSV ( body , setCb , endCb ) { csv . parse ( body , { skip_empty_lines : true , comment : '#' , relax_column_count : true } , ( err , data ) => { if ( err ) { return endCb ( err ) ; } for ( let i = 0 ; i < data . length ; i ++ ) { const args = [ ] ; for ( const k in this . shortcuts ) { if ( data [ i ] [ k ] !== undefined && data [ i ] [ k ] !== '' ) { args . push ( this . shortcuts [ k ] . pos ) ; if ( this . shortcuts [ k ] . mod === 1 ) { args . push ( data [ i ] [ k ] . toLowerCase ( ) ) ; } else if ( this . shortcuts [ k ] . mod === 2 ) { args . push ( data [ i ] [ k ] . toUpperCase ( ) ) ; } else { args . push ( data [ i ] [ k ] ) ; } } } if ( args . length === 0 ) { setCb ( data [ i ] [ this . column ] , WISESource . emptyResult ) ; } else { setCb ( data [ i ] [ this . column ] , WISESource . encodeResult . apply ( null , args ) ) ; } } endCb ( err ) ; } ) ; }
Util function to parse CSV formatted data
 @param {string} body - the raw CSV data
 @param {function} setCb - the function to call for each row found
 @param {function} endCB - all done parsing
Util function to parse CSV formatted data @param { string } body - the raw CSV data @param { function } setCb - the function to call for each row found @param { function } endCB - all done parsing