Skip to content

Commit

Permalink
Implements basic api
Browse files Browse the repository at this point in the history
  • Loading branch information
niksrc committed Apr 17, 2016
1 parent cbe640f commit 6676115
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 26 deletions.
51 changes: 46 additions & 5 deletions index.js
@@ -1,10 +1,51 @@
'use strict';
module.exports = function (str, opts) {
if (typeof str !== 'string') {
var net = require('net');
var socket = new net.Socket();

module.exports = {
init: init,
get: get,
close: close
};

function init(opts) {
if (typeof opts.host !== 'string') {
throw new TypeError('Expected a string');
}

opts = opts || {};
socket.connect(opts.port, opts.host);
}

return str + ' & ' + (opts.postfix || 'rainbows');
};
function close() {
socket.destroy();
}

function get(text, callback) {
socket.on('connect', function () {
socket.on('data', function (response) {
var re = /<([A-Z]+?)>(.+?)<\/\1>/g;
var str = response.toString();
var m;
var result = {
LOCATION: [],
ORGANIZATION: [],
DATE: [],
MONEY: [],
PERSON: [],
PERCENT: [],
TIME: []
};

while ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
result[m[1]].push(m[2]);
}

callback(result);
});

socket.write(text + '\n');
});
}

0 comments on commit 6676115

Please sign in to comment.