From 986892244928a3984bb2c20de07d398f1d8fcc0d Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Fri, 1 Nov 2013 23:34:22 -0400 Subject: [PATCH] add ability to use a custom tokenizer --- lib/index.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index b15da40..48d504d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -25,6 +25,11 @@ var cmdsrv = function(options){ this.caseSensitive = options["caseSensitive"] || false; this.delimiter = options["delimiter"] || " "; + var self = this; + this.tokenize = options["tokenizer"] || function(line){ + return line.split(self.delimiter); + }; + var self = this; this.server = net.createServer(function(connection){ self.handle(connection); @@ -41,7 +46,7 @@ cmdsrv.prototype.handle = function(connection){ connection.on("line", function(line){ line = line.trim(); self.emit("line", connection, line) - var parts = line.split(self.delimiter); + var parts = self.tokenize(line); if(!parts.length){ return;