Coverage

100%
146
146
0

Connection.js

100%
77
77
0
LineHitsSource
11var net, events, ParserStream, SerializerStream, Connection, slice$ = [].slice, toString$ = {}.toString;
21net = require('net');
31events = require('events');
41ParserStream = require('./ParserStream');
51SerializerStream = require('./SerializerStream');
61module.exports = Connection = (function(superclass){
71 var prototype = extend$((import$(Connection, superclass).displayName = 'Connection', Connection), superclass).prototype, constructor = Connection;
81 function Connection(){
918 var this$ = this instanceof ctor$ ? this : new ctor$;
1018 this$.send = bind$(this$, 'send', prototype);
1118 this$.close = bind$(this$, 'close', prototype);
1218 this$.connect = bind$(this$, 'connect', prototype);
1318 this$.serializer = new SerializerStream;
1418 this$.parser = new ParserStream;
1518 this$.parser.on('readable', function(){
161 var message, results$ = [];
171 while ((message = this$.parser.read()) != null) {
181 results$.push(this$.emit('message', message));
19 }
201 return results$;
21 });
2218 return this$;
232 } function ctor$(){} ctor$.prototype = prototype;
241 prototype.connect = function(){
2516 var args, this$ = this;
2616 args = slice$.call(arguments);
2716 if (this.socket != null) {
281 throw new Error('Already connected');
29 }
3015 this.socket = net.createConnection.apply(net, args);
3115 this.serializer.pipe(this.socket);
3215 this.socket.pipe(this.parser, {
33 end: false
34 });
3515 this.socket.on('close', function(){
361 return this$.emit('close');
37 });
3815 this.socket.on('connect', function(){
391 return this$.emit('connect');
40 });
4115 return this.socket.on('error', function(error){
421 return this$.emit('error', error);
43 });
44 };
451 prototype.close = function(){
463 var ref$;
473 if (this.socket == null) {
481 throw new Error('Already disconnected');
49 }
502 this.serializer.unpipe(this.socket);
512 this.socket.unpipe(this.parser);
522 this.socket.end();
532 return ref$ = this.socket, delete this.socket, ref$;
54 };
551 prototype.send = function(){
567 var args, command, parameters, message;
577 args = slice$.call(arguments);
587 if (this.socket == null) {
591 throw new Error('Not connected');
60 }
616 command = args[0];
626 parameters = args.slice(1);
636 switch (toString$.call(command).slice(8, -1)) {
64 case 'Object':
652 if (command == null || typeof command.command !== 'string') {
661 throw new Error('Invalid command');
67 }
681 message = command;
691 break;
70 case 'String':
713 message = {
72 command: command
73 };
743 if (parameters.length > 0) {
752 message.parameters = parameters.map(toString);
76 }
773 break;
78 default:
791 throw new Error('Invalid command');
80 }
814 return this.serializer.write(message);
82 };
831 return Connection;
84}(events.EventEmitter));
851function toString(obj){
868 if (obj != null) {
878 obj = obj.toString();
88 }
898 return obj;
90}
911function bind$(obj, key, target){
9280 return function(){ return (target || obj)[key].apply(obj, arguments) };
93}
941function extend$(sub, sup){
952 function fun(){} fun.prototype = (sub.superclass = sup).prototype;
961 (sub.prototype = new fun).constructor = sub;
971 if (typeof sup.extended == 'function') sup.extended(sub);
981 return sub;
99}
1001function import$(obj, src){
1011 var own = {}.hasOwnProperty;
1023 for (var key in src) if (own.call(src, key)) obj[key] = src[key];
1031 return obj;
104}

ParserStream.js

100%
35
35
0
LineHitsSource
11var stream, ircp, ParserStream;
21stream = require('stream');
31ircp = require('ircp');
41module.exports = ParserStream = (function(superclass){
51 var prototype = extend$((import$(ParserStream, superclass).displayName = 'ParserStream', ParserStream), superclass).prototype, constructor = ParserStream;
61 function ParserStream(options){
73 var this$ = this instanceof ctor$ ? this : new ctor$;
83 options == null && (options = {});
93 options.objectMode = true;
103 ParserStream.superclass.call(this$, options);
113 this$.buffer = '';
123 return this$;
132 } function ctor$(){} ctor$.prototype = prototype;
141 prototype._transform = function(input, encoding, done){
155 var lines, i$, len$, line;
165 lines = this._split(input.toString());
175 for (i$ = 0, len$ = lines.length; i$ < len$; ++i$) {
185 line = lines[i$];
195 this.push(ircp.parse(line));
20 }
215 return done();
22 };
231 prototype._split = function(input){
245 var lines;
255 lines = (this.buffer += input).split(/\r\n/);
265 this.buffer = lines.pop();
275 return lines;
28 };
291 return ParserStream;
30}(stream.Transform));
311function extend$(sub, sup){
322 function fun(){} fun.prototype = (sub.superclass = sup).prototype;
331 (sub.prototype = new fun).constructor = sub;
341 if (typeof sup.extended == 'function') sup.extended(sub);
351 return sub;
36}
371function import$(obj, src){
381 var own = {}.hasOwnProperty;
393 for (var key in src) if (own.call(src, key)) obj[key] = src[key];
401 return obj;
41}

SerializerStream.js

100%
25
25
0
LineHitsSource
11var stream, ircp, SerializerStream;
21stream = require('stream');
31ircp = require('ircp');
41module.exports = SerializerStream = (function(superclass){
51 var prototype = extend$((import$(SerializerStream, superclass).displayName = 'SerializerStream', SerializerStream), superclass).prototype, constructor = SerializerStream;
61 function SerializerStream(options){
72 var this$ = this instanceof ctor$ ? this : new ctor$;
82 options == null && (options = {});
92 options.objectMode = true;
102 SerializerStream.superclass.call(this$, options);
112 return this$;
122 } function ctor$(){} ctor$.prototype = prototype;
131 prototype._transform = function(input, encoding, done){
144 this.push(ircp.serialize(input) + '\r\n');
154 return done();
16 };
171 return SerializerStream;
18}(stream.Transform));
191function extend$(sub, sup){
202 function fun(){} fun.prototype = (sub.superclass = sup).prototype;
211 (sub.prototype = new fun).constructor = sub;
221 if (typeof sup.extended == 'function') sup.extended(sub);
231 return sub;
24}
251function import$(obj, src){
261 var own = {}.hasOwnProperty;
273 for (var key in src) if (own.call(src, key)) obj[key] = src[key];
281 return obj;
29}

createConnection.js

100%
9
9
0
LineHitsSource
11var Connection, createConnection;
21Connection = require('./Connection');
31module.exports = createConnection = function(port, host, connectListener){
44 var connection;
54 connection = new Connection;
64 if (typeof connectListener === 'function') {
71 connection.on('connect', connectListener);
8 }
94 connection.connect(port, host);
104 return connection;
11};