Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup of tests; Started on Chunked Message Parser
- Loading branch information
Showing
14 changed files
with
428 additions
and
428 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var util = require('util'); | ||
var events = require('events'); | ||
|
||
var ChunkedMessageParser = function (messageParser) { | ||
if (messageParser) { | ||
this.listen(messageParser); | ||
} | ||
}; | ||
|
||
ChunkedMessageParser.prototype = new events.EventEmitter(); | ||
|
||
ChunkedMessageParser.prototype.parse = function (message) { | ||
this.defaultAction(message); | ||
}; | ||
|
||
ChunkedMessageParser.prototype.listen = function (messageParser) { | ||
messageParser.on('_message', this.parse.bind(this)); | ||
}; | ||
|
||
ChunkedMessageParser.prototype.defaultAction = function (message) { | ||
this.emit(message.name, message); | ||
}; | ||
|
||
module.exports = ChunkedMessageParser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,33 @@ | ||
/** | ||
* A hostmask is the combination of a nickname, a username, and a host. Every IRC user | ||
* has one that can be obtained from the WHOIS message. | ||
* A hostmask is the combination of a nickname, a username, and a host. | ||
* Every IRC user has one that can be obtained from the USERHOST message. | ||
* | ||
* A hostmask's value properties (nick, user, and host) are guaranteed to be final. | ||
* This object is frozen upon creation. | ||
* | ||
* @author havvy | ||
* @param {String} asString String representation of a hostmask. nick!user@host | ||
* Constructor: Takes one argument, a hostmask. For example "nick!user@host"; | ||
*/ | ||
|
||
nullHostmask = { | ||
nick : '', | ||
user : '', | ||
host : '' | ||
}; | ||
/* | ||
*/ | ||
|
||
var Hostmask = function (asString) { | ||
if (!asString) { | ||
return nullHostmask; | ||
} | ||
|
||
var nickEnd = asString.indexOf("!"); | ||
var userEnd = asString.indexOf("@"); | ||
|
||
var nick = asString.slice(0, nickEnd); | ||
var user = asString.slice(nickEnd + 1, userEnd); | ||
var host = asString.slice(userEnd + 1); | ||
|
||
Object.defineProperties(this, { | ||
"nick" : { | ||
"get" : function () { return nick; } | ||
}, | ||
"user" : { | ||
"get" : function () { return user; } | ||
}, | ||
"host" : { | ||
"get" : function () { return host; } | ||
} | ||
}); | ||
var nickEnd = asString.indexOf("!"); | ||
var userEnd = asString.indexOf("@"); | ||
|
||
this.nick = asString.slice(0, nickEnd); | ||
this.user = asString.slice(nickEnd + 1, userEnd); | ||
this.host = asString.slice(userEnd + 1); | ||
|
||
Object.freeze(this); | ||
}; | ||
|
||
Hostmask.prototype.equals = function (that) { | ||
return this.nick === that.nick && this.user === that.user && | ||
this.host === that.host; | ||
}; | ||
|
||
Hostmask.prototype = { | ||
equals : function (other) { | ||
return this.nick === other.nick && this.user === other.user && | ||
this.host === other.host; | ||
}, | ||
|
||
toString : function () { | ||
return [this.nick, '!', this.user, '@', this.host].join(''); | ||
} | ||
Hostmask.prototype.toString = function () { | ||
return this.nick + '!' + this.user + '@' + this.host; | ||
}; | ||
|
||
nullHostmask.prototype = Hostmask; | ||
module.exports = Hostmask; |
Oops, something went wrong.