garrows / browser-serialport

Robots in the browser. Just like node-serialport but for browser/chrome apps.
MIT License
205 stars 73 forks source link

(bad patch) .. } else if (typeof fc === 'string'){ #51

Open Red-Owl opened 4 years ago

Red-Owl commented 4 years ago

options.rtscts = _options.rtscts;

if (options.flowControl || options.flowcontrol) { var fc = options.flowControl || options.flowcontrol;

if (typeof fc === 'boolean') {
  options.rtscts = true;
} else if (typeof fc === 'string'){
    var fcup = fc.toUpperCase();
    var idx = FLOWCONTROLS.indexOf(fcup);
    if (idx < 0) {
      var err = new Error('Invalid "flowControl": ' + fcup + '. Valid options: ' + FLOWCONTROLS.join(', '));
      callback(err);
      return false;
    } else {

      // "XON", "XOFF", "XANY", "DTRDTS", "RTSCTS"
      switch (idx) {
        case 0: 
            options.rtscts = true; 
        break;
      }
      return true;
    }
}else{

    var clean = fc.every(function (flowControl) {
    var fcup = flowControl.toUpperCase();
    var idx = FLOWCONTROLS.indexOf(fcup);
    if (idx < 0) {
      var err = new Error('Invalid "flowControl": ' + fcup + '. Valid options: ' + FLOWCONTROLS.join(', '));
      callback(err);
      return false;
    } else {

      // "XON", "XOFF", "XANY", "DTRDTS", "RTSCTS"
      switch (idx) {
        case 0: 
            options.rtscts = true; 
        break;
      }
      return true;
    }
  });
  if(!clean){
    return;
  }
}

}