node-ipc/entities/EventParser.js

35 lines
567 B
JavaScript
Raw Normal View History

2016-01-10 23:18:14 +11:00
2021-07-03 07:35:02 +10:00
import Defaults from './Defaults.js';
2017-04-16 14:13:15 +10:00
class Parser{
constructor(config){
if(!config){
config=new Defaults;
}
this.delimiter=config.delimiter;
2017-04-16 14:13:15 +10:00
}
format(message){
2016-03-16 20:46:10 +11:00
if(!message.data && message.data!==false && message.data!==0){
message.data={};
}
if(message.data['_maxListeners']){
message.data={};
}
message=message.JSON+this.delimiter;
return message;
2017-04-16 14:13:15 +10:00
}
2014-02-22 20:13:31 +11: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
};