2016-01-10 23:18:14 +11:00
|
|
|
|
2021-07-03 07:35:02 +10:00
|
|
|
import Defaults from './Defaults.js';
|
2017-04-16 15:17:25 +10:00
|
|
|
|
2017-04-16 14:13:15 +10:00
|
|
|
class Parser{
|
|
|
|
constructor(config){
|
2017-04-16 15:17:25 +10:00
|
|
|
if(!config){
|
|
|
|
config=new Defaults;
|
|
|
|
}
|
|
|
|
this.delimiter=config.delimiter;
|
2017-04-16 14:13:15 +10:00
|
|
|
}
|
2015-09-27 20:32:14 +10:00
|
|
|
|
2017-04-16 15:17:25 +10:00
|
|
|
format(message){
|
2016-03-16 20:46:10 +11:00
|
|
|
if(!message.data && message.data!==false && message.data!==0){
|
2015-09-27 20:32:14 +10:00
|
|
|
message.data={};
|
|
|
|
}
|
|
|
|
if(message.data['_maxListeners']){
|
|
|
|
message.data={};
|
|
|
|
}
|
|
|
|
|
2017-04-16 15:17:25 +10:00
|
|
|
message=message.JSON+this.delimiter;
|
2015-09-27 20:32:14 +10:00
|
|
|
return message;
|
2017-04-16 14:13:15 +10:00
|
|
|
}
|
2014-02-22 20:13:31 +11:00
|
|
|
|
2017-04-16 15:17:25 +10:00
|
|
|
parse(data){
|
|
|
|
let events=data.split(this.delimiter);
|
2014-02-22 20:13:31 +11:00
|
|
|
events.pop();
|
|
|
|
return events;
|
2017-04-16 14:13:15 +10:00
|
|
|
}
|
2014-02-22 20:13:31 +11:00
|
|
|
}
|
|
|
|
|
2021-07-03 07:35:02 +10:00
|
|
|
export {
|
|
|
|
Parser as default,
|
|
|
|
Parser
|
|
|
|
};
|