From 071ca7cb360e0607ca4d81e5cb17c0bbd6546df6 Mon Sep 17 00:00:00 2001 From: brandon Date: Sat, 22 Feb 2014 01:13:31 -0800 Subject: [PATCH] first commit --- README.md | 13 + example/local/basic/hello-client.js | 41 +++ example/local/basic/world-server.js | 30 ++ lib/client.js | 103 ++++++ lib/eventParser.js | 23 ++ lib/socketServer.js | 212 +++++++++++ node-ipc.js | 124 +++++++ node_modules/colors/MIT-LICENSE.txt | 22 ++ node_modules/colors/ReadMe.md | 77 ++++ node_modules/colors/colors.js | 342 ++++++++++++++++++ node_modules/colors/example.html | 76 ++++ node_modules/colors/example.js | 77 ++++ node_modules/colors/package.json | 29 ++ node_modules/colors/test.js | 70 ++++ node_modules/colors/themes/winston-dark.js | 12 + node_modules/colors/themes/winston-light.js | 12 + node_modules/event-pubsub/LICENSE | 24 ++ node_modules/event-pubsub/README.md | 61 ++++ .../event-pubsub/event-pubsub-browser.js | 109 ++++++ node_modules/event-pubsub/event-pubsub.js | 103 ++++++ .../event-pubsub/examples/browser/basic.html | 15 + .../event-pubsub/examples/browser/basic.js | 73 ++++ .../examples/browser/multipleScopes.html | 15 + .../examples/browser/multipleScopes.js | 103 ++++++ .../examples/browser/objectScope.html | 15 + .../examples/browser/objectScope.js | 73 ++++ .../event-pubsub/examples/node/basic.js | 60 +++ .../examples/node/multipleScopes.js | 90 +++++ .../event-pubsub/examples/node/objectScope.js | 56 +++ node_modules/event-pubsub/package.json | 35 ++ package.json | 33 ++ 31 files changed, 2128 insertions(+) create mode 100644 README.md create mode 100644 example/local/basic/hello-client.js create mode 100644 example/local/basic/world-server.js create mode 100644 lib/client.js create mode 100644 lib/eventParser.js create mode 100644 lib/socketServer.js create mode 100644 node-ipc.js create mode 100644 node_modules/colors/MIT-LICENSE.txt create mode 100644 node_modules/colors/ReadMe.md create mode 100644 node_modules/colors/colors.js create mode 100644 node_modules/colors/example.html create mode 100644 node_modules/colors/example.js create mode 100644 node_modules/colors/package.json create mode 100644 node_modules/colors/test.js create mode 100644 node_modules/colors/themes/winston-dark.js create mode 100644 node_modules/colors/themes/winston-light.js create mode 100644 node_modules/event-pubsub/LICENSE create mode 100644 node_modules/event-pubsub/README.md create mode 100644 node_modules/event-pubsub/event-pubsub-browser.js create mode 100644 node_modules/event-pubsub/event-pubsub.js create mode 100644 node_modules/event-pubsub/examples/browser/basic.html create mode 100644 node_modules/event-pubsub/examples/browser/basic.js create mode 100644 node_modules/event-pubsub/examples/browser/multipleScopes.html create mode 100644 node_modules/event-pubsub/examples/browser/multipleScopes.js create mode 100644 node_modules/event-pubsub/examples/browser/objectScope.html create mode 100644 node_modules/event-pubsub/examples/browser/objectScope.js create mode 100644 node_modules/event-pubsub/examples/node/basic.js create mode 100644 node_modules/event-pubsub/examples/node/multipleScopes.js create mode 100644 node_modules/event-pubsub/examples/node/objectScope.js create mode 100644 node_modules/event-pubsub/package.json create mode 100644 package.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..8ca39a2 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +#node-ipc +*a nodejs module for local and remote Inter Process Communication* + +---- +#### Documentation coming soon +---- + +#### Local IPC +Uses Unix Sockets to give lightning fast communication and avoid the network card to reduce overhead and latency. + +#### Remote IPC +Uses ``not yet defined`` Sockets to give fastest possible communication across the network with the minimum overhead and latency. + diff --git a/example/local/basic/hello-client.js b/example/local/basic/hello-client.js new file mode 100644 index 0000000..35640e8 --- /dev/null +++ b/example/local/basic/hello-client.js @@ -0,0 +1,41 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'hello'; +ipc.config.retry= 1500; + +ipc.connectTo( + 'world', + function(){ + ipc.of.world.on( + 'connect', + function(){ + ipc.log('## connected to world ##'.rainbow, ipc.config.delay); + ipc.of.world.emit( + 'message', + 'hello' + ) + } + ); + ipc.of.world.on( + 'disconnect', + function(){ + ipc.log('disconnected from world'.notice); + } + ); + ipc.of.world.on( + 'message', + function(data){ + ipc.log('got a message from world : '.debug, data); + } + ); + } +); + +console.log(ipc) \ No newline at end of file diff --git a/example/local/basic/world-server.js b/example/local/basic/world-server.js new file mode 100644 index 0000000..271b859 --- /dev/null +++ b/example/local/basic/world-server.js @@ -0,0 +1,30 @@ +var ipc=require('../../../node-ipc'); + +/***************************************\ + * + * You should start both hello and world + * then you will see them communicating. + * + * *************************************/ + +ipc.config.id = 'world'; +ipc.config.retry= 1500; + +ipc.serve( + function(){ + ipc.server.on( + 'message', + function(data,socket){ + ipc.log('got a message : '.debug, data); + socket.emit( + 'message', + data+' world!' + ); + } + ); + } +); + +ipc.server.start(); + +console.log(ipc) \ No newline at end of file diff --git a/lib/client.js b/lib/client.js new file mode 100644 index 0000000..1ea7fe0 --- /dev/null +++ b/lib/client.js @@ -0,0 +1,103 @@ +var net = require('net'), + eventParser = require('../lib/eventParser.js'), + pubsub = require('event-pubsub'); + +function init(config,log){ + var client={ + config : config, + socket : false, + connect : connect, + emit : emit, + log : log + } + new pubsub(client); + + return client; +} + +function emit(type,data){ + this.log('dispatching event to '.debug, this.id.variable, this.path.variable,' : ', type.data,',', data); + if(!data) + data=false; + this.socket.write( + eventParser.format( + { + type:type, + data:data + } + ) + ); +}; + +function connect(){ + //init client object for scope persistance especially inside of socket events. + var client=this; + + client.log('requested connection to '.debug, client.id.variable, client.path.variable); + if(!this.path){ + client.log('\n\n######\nerror: '.error, client.id .info,' client has not specified socket path it wishes to connect to.'.error); + return; + } + + client.socket = net.connect( + { + path:client.path + } + ); + + client.socket.setEncoding(this.config.encoding); + + client.socket.on( + 'error', + function(err){ + client.log('\n\n######\nerror: '.error, err); + } + ); + + client.socket.on( + 'connect', + function(){ + client.trigger('connect'); + } + ); + + client.socket.on( + 'close', + function(){ + client.log('connection closed'.notice ,client.id.variable , client.path.variable); + setTimeout( + ( + function(client){ + return function(){ + client.connect(); + } + } + )(client), + client.config.retry + ); + + client.trigger('disconnect'); + } + ); + + client.socket.on( + 'data', + function(data) { + client.log('## recieved events ##'.rainbow); + var events = eventParser.parse(data); + var eCount = events.length; + for(var i=0; i0){ + var e=JSON.parse(data.shift()); + server.log('recieved event of : '.debug,e.type.data,e.data); + + server.sockets.push(socket); + + server.trigger( + e.type, + e.data, + socket + ); + } + } + ); + + server.trigger( + 'connect', + socket + ); + + server.trigger( + 'get.events.broadcasting', + socket + ); + + server.trigger( + 'get.events.listening', + socket + ); + } + ); + + + server.server.listen( + server.path, + ( + function(server){ + return function(socket){ + server.onStart(socket) + } + } + )(server) + ); + + server.server.maxConnections=server.maxConnections; + + } + } + )(this) + ); + } + }; + + new pubsub(server); + + server.on( + 'get.events.broadcasting', + function(socket){ + server.emit( + socket, + 'events.broadcasting', + { + id : server.config.id, + events : server.define.broadcast + } + ); + } + ); + + server.on( + 'get.events.listening', + function(socket){ + server.emit( + socket, + 'events.listening', + { + id : server.config.id, + events : server.define.listen, + } + ); + } + ) + + server.on( + 'close', + function(){ + for(var i=0, count=server.sockets.length; i + + +## Installation + + npm install colors + +## colors and styles! + +- bold +- italic +- underline +- inverse +- yellow +- cyan +- white +- magenta +- green +- red +- grey +- blue +- rainbow +- zebra +- random + +## Usage + +``` js +var colors = require('./colors'); + +console.log('hello'.green); // outputs green text +console.log('i like cake and pies'.underline.red) // outputs red underlined text +console.log('inverse the color'.inverse); // inverses the color +console.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces) +``` + +# Creating Custom themes + +```js + +var colors = require('colors'); + +colors.setTheme({ + silly: 'rainbow', + input: 'grey', + verbose: 'cyan', + prompt: 'grey', + info: 'green', + data: 'grey', + help: 'cyan', + warn: 'yellow', + debug: 'blue', + error: 'red' +}); + +// outputs red text +console.log("this is an error".error); + +// outputs yellow text +console.log("this is a warning".warn); +``` + + +### Contributors + +Marak (Marak Squires) +Alexis Sellier (cloudhead) +mmalecki (Maciej Małecki) +nicoreed (Nico Reed) +morganrallen (Morgan Allen) +JustinCampbell (Justin Campbell) +ded (Dustin Diaz) + + +#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded) diff --git a/node_modules/colors/colors.js b/node_modules/colors/colors.js new file mode 100644 index 0000000..7a537d8 --- /dev/null +++ b/node_modules/colors/colors.js @@ -0,0 +1,342 @@ +/* +colors.js + +Copyright (c) 2010 + +Marak Squires +Alexis Sellier (cloudhead) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +*/ + +var isHeadless = false; + +if (typeof module !== 'undefined') { + isHeadless = true; +} + +if (!isHeadless) { + var exports = {}; + var module = {}; + var colors = exports; + exports.mode = "browser"; +} else { + exports.mode = "console"; +} + +// +// Prototypes the string object to have additional method calls that add terminal colors +// +var addProperty = function (color, func) { + exports[color] = function (str) { + return func.apply(str); + }; + String.prototype.__defineGetter__(color, func); +}; + +function stylize(str, style) { + + var styles; + + if (exports.mode === 'console') { + styles = { + //styles + 'bold' : ['\x1B[1m', '\x1B[22m'], + 'italic' : ['\x1B[3m', '\x1B[23m'], + 'underline' : ['\x1B[4m', '\x1B[24m'], + 'inverse' : ['\x1B[7m', '\x1B[27m'], + 'strikethrough' : ['\x1B[9m', '\x1B[29m'], + //text colors + //grayscale + 'white' : ['\x1B[37m', '\x1B[39m'], + 'grey' : ['\x1B[90m', '\x1B[39m'], + 'black' : ['\x1B[30m', '\x1B[39m'], + //colors + 'blue' : ['\x1B[34m', '\x1B[39m'], + 'cyan' : ['\x1B[36m', '\x1B[39m'], + 'green' : ['\x1B[32m', '\x1B[39m'], + 'magenta' : ['\x1B[35m', '\x1B[39m'], + 'red' : ['\x1B[31m', '\x1B[39m'], + 'yellow' : ['\x1B[33m', '\x1B[39m'], + //background colors + //grayscale + 'whiteBG' : ['\x1B[47m', '\x1B[49m'], + 'greyBG' : ['\x1B[49;5;8m', '\x1B[49m'], + 'blackBG' : ['\x1B[40m', '\x1B[49m'], + //colors + 'blueBG' : ['\x1B[44m', '\x1B[49m'], + 'cyanBG' : ['\x1B[46m', '\x1B[49m'], + 'greenBG' : ['\x1B[42m', '\x1B[49m'], + 'magentaBG' : ['\x1B[45m', '\x1B[49m'], + 'redBG' : ['\x1B[41m', '\x1B[49m'], + 'yellowBG' : ['\x1B[43m', '\x1B[49m'] + }; + } else if (exports.mode === 'browser') { + styles = { + //styles + 'bold' : ['', ''], + 'italic' : ['', ''], + 'underline' : ['', ''], + 'inverse' : ['', ''], + 'strikethrough' : ['', ''], + //text colors + //grayscale + 'white' : ['', ''], + 'grey' : ['', ''], + 'black' : ['', ''], + //colors + 'blue' : ['', ''], + 'cyan' : ['', ''], + 'green' : ['', ''], + 'magenta' : ['', ''], + 'red' : ['', ''], + 'yellow' : ['', ''], + //background colors + //grayscale + 'whiteBG' : ['', ''], + 'greyBG' : ['', ''], + 'blackBG' : ['', ''], + //colors + 'blueBG' : ['', ''], + 'cyanBG' : ['', ''], + 'greenBG' : ['', ''], + 'magentaBG' : ['', ''], + 'redBG' : ['', ''], + 'yellowBG' : ['', ''] + }; + } else if (exports.mode === 'none') { + return str + ''; + } else { + console.log('unsupported mode, try "browser", "console" or "none"'); + } + return styles[style][0] + str + styles[style][1]; +} + +function applyTheme(theme) { + + // + // Remark: This is a list of methods that exist + // on String that you should not overwrite. + // + var stringPrototypeBlacklist = [ + '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', + 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt', + 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring', + 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight' + ]; + + Object.keys(theme).forEach(function (prop) { + if (stringPrototypeBlacklist.indexOf(prop) !== -1) { + console.log('warn: '.red + ('String.prototype' + prop).magenta + ' is probably something you don\'t want to override. Ignoring style name'); + } + else { + if (typeof(theme[prop]) === 'string') { + addProperty(prop, function () { + return exports[theme[prop]](this); + }); + } + else { + addProperty(prop, function () { + var ret = this; + for (var t = 0; t < theme[prop].length; t++) { + ret = exports[theme[prop][t]](ret); + } + return ret; + }); + } + } + }); +} + + +// +// Iterate through all default styles and colors +// +var x = ['bold', 'underline', 'strikethrough', 'italic', 'inverse', 'grey', 'black', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta', 'greyBG', 'blackBG', 'yellowBG', 'redBG', 'greenBG', 'blueBG', 'whiteBG', 'cyanBG', 'magentaBG']; +x.forEach(function (style) { + + // __defineGetter__ at the least works in more browsers + // http://robertnyman.com/javascript/javascript-getters-setters.html + // Object.defineProperty only works in Chrome + addProperty(style, function () { + return stylize(this, style); + }); +}); + +function sequencer(map) { + return function () { + if (!isHeadless) { + return this.replace(/( )/, '$1'); + } + var exploded = this.split(""), i = 0; + exploded = exploded.map(map); + return exploded.join(""); + }; +} + +var rainbowMap = (function () { + var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta']; //RoY G BiV + return function (letter, i, exploded) { + if (letter === " ") { + return letter; + } else { + return stylize(letter, rainbowColors[i++ % rainbowColors.length]); + } + }; +})(); + +exports.themes = {}; + +exports.addSequencer = function (name, map) { + addProperty(name, sequencer(map)); +}; + +exports.addSequencer('rainbow', rainbowMap); +exports.addSequencer('zebra', function (letter, i, exploded) { + return i % 2 === 0 ? letter : letter.inverse; +}); + +exports.setTheme = function (theme) { + if (typeof theme === 'string') { + try { + exports.themes[theme] = require(theme); + applyTheme(exports.themes[theme]); + return exports.themes[theme]; + } catch (err) { + console.log(err); + return err; + } + } else { + applyTheme(theme); + } +}; + + +addProperty('stripColors', function () { + return ("" + this).replace(/\x1B\[\d+m/g, ''); +}); + +// please no +function zalgo(text, options) { + var soul = { + "up" : [ + '̍', '̎', '̄', '̅', + '̿', '̑', '̆', '̐', + '͒', '͗', '͑', '̇', + '̈', '̊', '͂', '̓', + '̈', '͊', '͋', '͌', + '̃', '̂', '̌', '͐', + '̀', '́', '̋', '̏', + '̒', '̓', '̔', '̽', + '̉', 'ͣ', 'ͤ', 'ͥ', + 'ͦ', 'ͧ', 'ͨ', 'ͩ', + 'ͪ', 'ͫ', 'ͬ', 'ͭ', + 'ͮ', 'ͯ', '̾', '͛', + '͆', '̚' + ], + "down" : [ + '̖', '̗', '̘', '̙', + '̜', '̝', '̞', '̟', + '̠', '̤', '̥', '̦', + '̩', '̪', '̫', '̬', + '̭', '̮', '̯', '̰', + '̱', '̲', '̳', '̹', + '̺', '̻', '̼', 'ͅ', + '͇', '͈', '͉', '͍', + '͎', '͓', '͔', '͕', + '͖', '͙', '͚', '̣' + ], + "mid" : [ + '̕', '̛', '̀', '́', + '͘', '̡', '̢', '̧', + '̨', '̴', '̵', '̶', + '͜', '͝', '͞', + '͟', '͠', '͢', '̸', + '̷', '͡', ' ҉' + ] + }, + all = [].concat(soul.up, soul.down, soul.mid), + zalgo = {}; + + function randomNumber(range) { + var r = Math.floor(Math.random() * range); + return r; + } + + function is_char(character) { + var bool = false; + all.filter(function (i) { + bool = (i === character); + }); + return bool; + } + + function heComes(text, options) { + var result = '', counts, l; + options = options || {}; + options["up"] = options["up"] || true; + options["mid"] = options["mid"] || true; + options["down"] = options["down"] || true; + options["size"] = options["size"] || "maxi"; + text = text.split(''); + for (l in text) { + if (is_char(l)) { + continue; + } + result = result + text[l]; + counts = {"up" : 0, "down" : 0, "mid" : 0}; + switch (options.size) { + case 'mini': + counts.up = randomNumber(8); + counts.min = randomNumber(2); + counts.down = randomNumber(8); + break; + case 'maxi': + counts.up = randomNumber(16) + 3; + counts.min = randomNumber(4) + 1; + counts.down = randomNumber(64) + 3; + break; + default: + counts.up = randomNumber(8) + 1; + counts.mid = randomNumber(6) / 2; + counts.down = randomNumber(8) + 1; + break; + } + + var arr = ["up", "mid", "down"]; + for (var d in arr) { + var index = arr[d]; + for (var i = 0 ; i <= counts[index]; i++) { + if (options[index]) { + result = result + soul[index][randomNumber(soul[index].length)]; + } + } + } + } + return result; + } + return heComes(text); +} + + +// don't summon zalgo +addProperty('zalgo', function () { + return zalgo(this); +}); diff --git a/node_modules/colors/example.html b/node_modules/colors/example.html new file mode 100644 index 0000000..7a2ae60 --- /dev/null +++ b/node_modules/colors/example.html @@ -0,0 +1,76 @@ + + + + + Colors Example + + + + + + \ No newline at end of file diff --git a/node_modules/colors/example.js b/node_modules/colors/example.js new file mode 100644 index 0000000..b1e03a4 --- /dev/null +++ b/node_modules/colors/example.js @@ -0,0 +1,77 @@ +var colors = require('./colors'); + +//colors.mode = "browser"; + +var test = colors.red("hopefully colorless output"); +console.log('Rainbows are fun!'.rainbow); +console.log('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported +console.log('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported +//console.log('zalgo time!'.zalgo); +console.log(test.stripColors); +console.log("a".grey + " b".black); +console.log("Zebras are so fun!".zebra); +console.log('background color attack!'.black.whiteBG) + +// +// Remark: .strikethrough may not work with Mac OS Terminal App +// +console.log("This is " + "not".strikethrough + " fun."); +console.log(colors.rainbow('Rainbows are fun!')); +console.log(colors.italic('So ') + colors.underline('are') + colors.bold(' styles! ') + colors.inverse('inverse')); // styles not widely supported +console.log(colors.bold(colors.italic(colors.underline(colors.red('Chains are also cool.'))))); // styles not widely supported +//console.log(colors.zalgo('zalgo time!')); +console.log(colors.stripColors(test)); +console.log(colors.grey("a") + colors.black(" b")); + +colors.addSequencer("america", function(letter, i, exploded) { + if(letter === " ") return letter; + switch(i%3) { + case 0: return letter.red; + case 1: return letter.white; + case 2: return letter.blue; + } +}); + +colors.addSequencer("random", (function() { + var available = ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta']; + + return function(letter, i, exploded) { + return letter === " " ? letter : letter[available[Math.round(Math.random() * (available.length - 1))]]; + }; +})()); + +console.log("AMERICA! F--K YEAH!".america); +console.log("So apparently I've been to Mars, with all the little green men. But you know, I don't recall.".random); + +// +// Custom themes +// + +// Load theme with JSON literal +colors.setTheme({ + silly: 'rainbow', + input: 'grey', + verbose: 'cyan', + prompt: 'grey', + info: 'green', + data: 'grey', + help: 'cyan', + warn: 'yellow', + debug: 'blue', + error: 'red' +}); + +// outputs red text +console.log("this is an error".error); + +// outputs yellow text +console.log("this is a warning".warn); + +// outputs grey text +console.log("this is an input".input); + +// Load a theme from file +colors.setTheme('./themes/winston-dark.js'); + +console.log("this is an input".input); + diff --git a/node_modules/colors/package.json b/node_modules/colors/package.json new file mode 100644 index 0000000..b36ae46 --- /dev/null +++ b/node_modules/colors/package.json @@ -0,0 +1,29 @@ +{ + "name": "colors", + "description": "get colors in your node.js console like what", + "version": "0.6.2", + "author": { + "name": "Marak Squires" + }, + "homepage": "https://github.com/Marak/colors.js", + "bugs": { + "url": "https://github.com/Marak/colors.js/issues" + }, + "keywords": [ + "ansi", + "terminal", + "colors" + ], + "repository": { + "type": "git", + "url": "http://github.com/Marak/colors.js.git" + }, + "engines": { + "node": ">=0.1.90" + }, + "main": "colors", + "readme": "# colors.js - get color and style in your node.js console ( and browser ) like what\n\n\n\n\n## Installation\n\n npm install colors\n\n## colors and styles!\n\n- bold\n- italic\n- underline\n- inverse\n- yellow\n- cyan\n- white\n- magenta\n- green\n- red\n- grey\n- blue\n- rainbow\n- zebra\n- random\n\n## Usage\n\n``` js\nvar colors = require('./colors');\n\nconsole.log('hello'.green); // outputs green text\nconsole.log('i like cake and pies'.underline.red) // outputs red underlined text\nconsole.log('inverse the color'.inverse); // inverses the color\nconsole.log('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)\n```\n\n# Creating Custom themes\n\n```js\n\nvar colors = require('colors');\n\ncolors.setTheme({\n silly: 'rainbow',\n input: 'grey',\n verbose: 'cyan',\n prompt: 'grey',\n info: 'green',\n data: 'grey',\n help: 'cyan',\n warn: 'yellow',\n debug: 'blue',\n error: 'red'\n});\n\n// outputs red text\nconsole.log(\"this is an error\".error);\n\n// outputs yellow text\nconsole.log(\"this is a warning\".warn);\n```\n\n\n### Contributors \n\nMarak (Marak Squires)\nAlexis Sellier (cloudhead)\nmmalecki (Maciej Małecki)\nnicoreed (Nico Reed)\nmorganrallen (Morgan Allen)\nJustinCampbell (Justin Campbell)\nded (Dustin Diaz)\n\n\n#### , Marak Squires , Justin Campbell, Dustin Diaz (@ded)\n", + "readmeFilename": "ReadMe.md", + "_id": "colors@0.6.2", + "_from": "colors@" +} diff --git a/node_modules/colors/test.js b/node_modules/colors/test.js new file mode 100644 index 0000000..c32417d --- /dev/null +++ b/node_modules/colors/test.js @@ -0,0 +1,70 @@ +var assert = require('assert'), + colors = require('./colors'); + +var s = 'string'; + +function a(s, code) { + return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m'; +} + +function aE(s, color, code) { + assert.equal(s[color], a(s, code)); + assert.equal(colors[color](s), a(s, code)); + assert.equal(s[color], colors[color](s)); + assert.equal(s[color].stripColors, s); + assert.equal(s[color].stripColors, colors.stripColors(s)); +} + +function h(s, color) { + return '' + s + ''; +} + +var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow']; +var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']); + +colors.mode = 'console'; +assert.equal(s.bold, '\x1B[1m' + s + '\x1B[22m'); +assert.equal(s.italic, '\x1B[3m' + s + '\x1B[23m'); +assert.equal(s.underline, '\x1B[4m' + s + '\x1B[24m'); +assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m'); +assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m'); +assert.ok(s.rainbow); +aE(s, 'white', 37); +aE(s, 'grey', 90); +aE(s, 'black', 30); +aE(s, 'blue', 34); +aE(s, 'cyan', 36); +aE(s, 'green', 32); +aE(s, 'magenta', 35); +aE(s, 'red', 31); +aE(s, 'yellow', 33); +assert.equal(s, 'string'); + +colors.setTheme({error:'red'}); + +assert.equal(typeof("astring".red),'string'); +assert.equal(typeof("astring".error),'string'); + +colors.mode = 'browser'; +assert.equal(s.bold, '' + s + ''); +assert.equal(s.italic, '' + s + ''); +assert.equal(s.underline, '' + s + ''); +assert.equal(s.strikethrough, '' + s + ''); +assert.equal(s.inverse, '' + s + ''); +assert.ok(s.rainbow); +stylesColors.forEach(function (color) { + assert.equal(s[color], h(s, color)); + assert.equal(colors[color](s), h(s, color)); +}); + +assert.equal(typeof("astring".red),'string'); +assert.equal(typeof("astring".error),'string'); + +colors.mode = 'none'; +stylesAll.forEach(function (style) { + assert.equal(s[style], s); + assert.equal(colors[style](s), s); +}); + +assert.equal(typeof("astring".red),'string'); +assert.equal(typeof("astring".error),'string'); diff --git a/node_modules/colors/themes/winston-dark.js b/node_modules/colors/themes/winston-dark.js new file mode 100644 index 0000000..49a905b --- /dev/null +++ b/node_modules/colors/themes/winston-dark.js @@ -0,0 +1,12 @@ +module['exports'] = { + silly: 'rainbow', + input: 'black', + verbose: 'cyan', + prompt: 'grey', + info: 'green', + data: 'grey', + help: 'cyan', + warn: 'yellow', + debug: 'blue', + error: 'red' +}; \ No newline at end of file diff --git a/node_modules/colors/themes/winston-light.js b/node_modules/colors/themes/winston-light.js new file mode 100644 index 0000000..571972c --- /dev/null +++ b/node_modules/colors/themes/winston-light.js @@ -0,0 +1,12 @@ +module['exports'] = { + silly: 'rainbow', + input: 'grey', + verbose: 'cyan', + prompt: 'grey', + info: 'green', + data: 'grey', + help: 'cyan', + warn: 'yellow', + debug: 'blue', + error: 'red' +}; \ No newline at end of file diff --git a/node_modules/event-pubsub/LICENSE b/node_modules/event-pubsub/LICENSE new file mode 100644 index 0000000..cf1ab25 --- /dev/null +++ b/node_modules/event-pubsub/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/node_modules/event-pubsub/README.md b/node_modules/event-pubsub/README.md new file mode 100644 index 0000000..b51ba1a --- /dev/null +++ b/node_modules/event-pubsub/README.md @@ -0,0 +1,61 @@ +Event PubSub +============ + +Pubsub events for Node and the browser allowing event scoping and multiple scopes. +Easy for any developer level. No frills, just high speed pubsub events! + +--- +### Basic Examples +--- +#### Node + + var events = new require('../../event-pubsub.js')(); + + events.on( + 'hello', + function(data){ + console.log('hello event recieved ', data); + } + ); + + events.on( + '*', + function(type){ + console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } + ); + + /************************************\ + * trigger events for testing + * **********************************/ + events.trigger( + 'hello', + 'world' + ); + +#### Browser +##### HTML + + var events = new require('../../event-pubsub.js')(); + + events.on( + 'hello', + function(data){ + console.log('hello event recieved ', data); + } + ); + + events.on( + '*', + function(type){ + console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } + ); + + /************************************\ + * trigger events for testing + * **********************************/ + events.trigger( + 'hello', + 'world' + ); diff --git a/node_modules/event-pubsub/event-pubsub-browser.js b/node_modules/event-pubsub/event-pubsub-browser.js new file mode 100644 index 0000000..9a02d9f --- /dev/null +++ b/node_modules/event-pubsub/event-pubsub-browser.js @@ -0,0 +1,109 @@ +window.pubsub=( + function(){ + + function sub(type,handler){ + checkScope.apply(this); + + if(!this._events_[type]) + this._events_[type]=[]; + + this._events_[type].push(handler); + } + + function unsub(type,handler){ + checkScope.apply(this); + + if(!this._events_[type]) + return; + + if(!handler){ + delete this._events_[type]; + return; + } + + for(var i=0, + count=this._events_[type].length; + i + + + Basic PubSub Example + + + +
    +
  • +

    PubSub Basic Events Example

    +
  • +
+ + + \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/browser/basic.js b/node_modules/event-pubsub/examples/browser/basic.js new file mode 100644 index 0000000..5cf64e2 --- /dev/null +++ b/node_modules/event-pubsub/examples/browser/basic.js @@ -0,0 +1,73 @@ +var events = new window.pubsub(); + +/************************************\ + * + * The events var was instantiated + * as it's own scope + * + * **********************************/ + +events.on( + 'hello', + function(data){ + eventLog.log('hello event recieved ', data); + } +); + +events.on( + 'hello', + function(data){ + eventLog.log('Second handler listening to hello event got',data); + events.trigger( + 'world', + { + type:'myObject', + data:{ + x:'YAY, Objects!' + } + } + ) + } +); + +events.on( + 'world', + function(data){ + eventLog.log('World event got',data); + } +); + +/**********************************\ + * + * Demonstrate * event (on all events) + * remove this for less verbose + * example + * + * ********************************/ +events.on( + '*', + function(type){ + eventLog.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } +); + +/*******************************\ + * + * Prep HTML for logging + * + * *****************************/ +var eventLog=document.getElementById('events'); +//not using console.log incase it doesn't work in some browser. *TLDT (Too lazy didn't test)* +eventLog.log=_log_; +function _log_ (){ + var events=Array.prototype.slice.call(arguments), + newEvent=document.createElement('li'); + + newEvent.innerHTML=events.join(' '); + this.appendChild(newEvent); +} + +events.trigger( + 'hello', + 'world' +); \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/browser/multipleScopes.html b/node_modules/event-pubsub/examples/browser/multipleScopes.html new file mode 100644 index 0000000..e6eb395 --- /dev/null +++ b/node_modules/event-pubsub/examples/browser/multipleScopes.html @@ -0,0 +1,15 @@ + + + + Basic PubSub Example + + + +
    +
  • +

    PubSub Multiple Event Scopes Example

    +
  • +
+ + + \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/browser/multipleScopes.js b/node_modules/event-pubsub/examples/browser/multipleScopes.js new file mode 100644 index 0000000..11170af --- /dev/null +++ b/node_modules/event-pubsub/examples/browser/multipleScopes.js @@ -0,0 +1,103 @@ +/************************************\ + * instantiating myEvents scope + * **********************************/ +var myEvents=new window.pubsub(); + +/************************************\ + * instantiating myEvents2 scope + * **********************************/ +var myEvents2=new window.pubsub(); + + +/************************************\ + * binding myEvents events + * **********************************/ +myEvents.on( + 'hello', + function(data){ + eventLog.log('myEvents hello event recieved ', data); + } +); + +myEvents.on( + 'hello', + function(data){ + eventLog.log('Second handler listening to myEvents hello event got',data); + myEvents.trigger( + 'world', + { + type:'myObject', + data:{ + x:'YAY, Objects!' + } + } + ) + } +); + +myEvents.on( + 'world', + function(data){ + eventLog.log('myEvents World event got',data); + } +); + +/**********************************\ + * + * Demonstrate * event (on all events) + * remove this for less verbose + * example + * + * ********************************/ +myEvents.on( + '*', + function(type){ + eventLog.log('myEvents Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } +); + +/************************************\ + * binding myEvents2 events + * **********************************/ +myEvents2.on( + 'hello', + function(data){ + eventLog.log('myEvents2 Hello event should never be called ', data); + } +); + +myEvents2.on( + 'world', + function(data){ + eventLog.log('myEvents2 World event ',data); + } +); + +/*******************************\ + * + * Prep HTML for logging + * + * *****************************/ +var eventLog=document.getElementById('events'); +//not using console.log incase it doesn't work in some browser. *TLDT (Too lazy didn't test)* +eventLog.log=_log_; +function _log_ (){ + var events=Array.prototype.slice.call(arguments), + newEvent=document.createElement('li'); + + newEvent.innerHTML=events.join(' '); + this.appendChild(newEvent); +} + +/************************************\ + * trigger events for testing + * **********************************/ +myEvents.trigger( + 'hello', + 'world' +); + +myEvents2.trigger( + 'world', + 'is round' +); \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/browser/objectScope.html b/node_modules/event-pubsub/examples/browser/objectScope.html new file mode 100644 index 0000000..e01814b --- /dev/null +++ b/node_modules/event-pubsub/examples/browser/objectScope.html @@ -0,0 +1,15 @@ + + + + Basic PubSub Example + + + +
    +
  • +

    PubSub Events inside of and using an Object as the scope Example

    +
  • +
+ + + \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/browser/objectScope.js b/node_modules/event-pubsub/examples/browser/objectScope.js new file mode 100644 index 0000000..e9e131a --- /dev/null +++ b/node_modules/event-pubsub/examples/browser/objectScope.js @@ -0,0 +1,73 @@ +/************************************\ + * + * The events var was instantiated + * as it's own scope + * + * **********************************/ + +var thing={ + id:'my thing' +} +/******************************\ + * + * Create events in the scope + * of the "thing" object + * + * ****************************/ +new window.pubsub(thing); + +thing.on( + 'getID', + function(){ + eventLog.log('things id is : ',this.id); + } +); + +thing.on( + 'setID', + function(id){ + eventLog.log('setting id to : ',id); + this.id=id; + this.trigger('getID'); + } +); + +/**********************************\ + * + * Demonstrate * event (on all events) + * remove this for less verbose + * example + * + * ********************************/ +thing.on( + '*', + function(type){ + eventLog.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } +); + +/*******************************\ + * + * Prep HTML for logging + * + * *****************************/ +var eventLog=document.getElementById('events'); +//not using console.log incase it doesn't work in some browser. *TLDT (Too lazy didn't test)* +eventLog.log=_log_; +function _log_ (){ + var events=Array.prototype.slice.call(arguments), + newEvent=document.createElement('li'); + + newEvent.innerHTML=events.join(' '); + this.appendChild(newEvent); +} + +/************************************\ + * trigger events for testing + * **********************************/ +thing.trigger('getID'); + +thing.trigger( + 'setID', + 'your thing' +) \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/node/basic.js b/node_modules/event-pubsub/examples/node/basic.js new file mode 100644 index 0000000..4069826 --- /dev/null +++ b/node_modules/event-pubsub/examples/node/basic.js @@ -0,0 +1,60 @@ +var events = new require('../../event-pubsub.js')(); + +/************************************\ + * + * The events var was instantiated + * as it's own scope + * + * **********************************/ + +events.on( + 'hello', + function(data){ + console.log('hello event recieved ', data); + } +); + +events.on( + 'hello', + function(data){ + console.log('Second handler listening to hello event got',data); + events.trigger( + 'world', + { + type:'myObject', + data:{ + x:'YAY, Objects!' + } + } + ) + } +); + +events.on( + 'world', + function(data){ + console.log('World event got',data); + } +); + +/**********************************\ + * + * Demonstrate * event (on all events) + * remove this for less verbose + * example + * + * ********************************/ +events.on( + '*', + function(type){ + console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } +); + +/************************************\ + * trigger events for testing + * **********************************/ +events.trigger( + 'hello', + 'world' +); \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/node/multipleScopes.js b/node_modules/event-pubsub/examples/node/multipleScopes.js new file mode 100644 index 0000000..a91e100 --- /dev/null +++ b/node_modules/event-pubsub/examples/node/multipleScopes.js @@ -0,0 +1,90 @@ +var pubsub = require('../../event-pubsub.js'); + +/************************************\ + * instantiating myEvents scope + * **********************************/ +var myEvents=new pubsub(); + +/************************************\ + * instantiating myEvents2 scope + * **********************************/ +var myEvents2=new pubsub(); + + +/************************************\ + * binding myEvents events + * **********************************/ +myEvents.on( + 'hello', + function(data){ + console.log('myEvents hello event recieved ', data); + } +); + +myEvents.on( + 'hello', + function(data){ + console.log('Second handler listening to myEvents hello event got',data); + myEvents.trigger( + 'world', + { + type:'myObject', + data:{ + x:'YAY, Objects!' + } + } + ) + } +); + +myEvents.on( + 'world', + function(data){ + console.log('myEvents World event got',data); + } +); + +/**********************************\ + * + * Demonstrate * event (on all events) + * remove this for less verbose + * example + * + * ********************************/ +myEvents.on( + '*', + function(type){ + console.log('myEvents Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } +); + +/************************************\ + * binding myEvents2 events + * **********************************/ +myEvents2.on( + 'hello', + function(data){ + console.log('myEvents2 Hello event should never be called ', data); + } +); + +myEvents2.on( + 'world', + function(data){ + console.log('myEvents2 World event ',data); + } +); + + +/************************************\ + * trigger events for testing + * **********************************/ +myEvents.trigger( + 'hello', + 'world' +); + +myEvents2.trigger( + 'world', + 'is round' +); \ No newline at end of file diff --git a/node_modules/event-pubsub/examples/node/objectScope.js b/node_modules/event-pubsub/examples/node/objectScope.js new file mode 100644 index 0000000..7df02e3 --- /dev/null +++ b/node_modules/event-pubsub/examples/node/objectScope.js @@ -0,0 +1,56 @@ +var pubsub = require('../../event-pubsub.js'); + +/************************************\ + * + * The events var was instantiated + * as it's own scope + * + * **********************************/ + +var thing={ + id:'my thing' +} +/******************************\ + * + * Create events in the scope + * of the "thing" object + * + * ****************************/ +new pubsub(thing); + +thing.on( + 'getID', + function(){ + console.log('things id is : ',this.id); + } +); + +thing.on( + 'setID', + function(id){ + console.log('setting id to : ',id); + this.id=id; + this.trigger('getID'); + } +); + +/**********************************\ + * + * Demonstrate * event (on all events) + * remove this for less verbose + * example + * + * ********************************/ +thing.on( + '*', + function(type){ + console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments); + } +); + +thing.trigger('getID'); + +thing.trigger( + 'setID', + 'your thing' +) \ No newline at end of file diff --git a/node_modules/event-pubsub/package.json b/node_modules/event-pubsub/package.json new file mode 100644 index 0000000..9351915 --- /dev/null +++ b/node_modules/event-pubsub/package.json @@ -0,0 +1,35 @@ +{ + "name": "event-pubsub", + "version": "1.0.2", + "description": "Pubsub events for Node and the browser allowing event scoping and multiple scopes. Easy for any developer level. No frills, just high speed pubsub events!", + "main": "event-pubsub.js", + "directories": { + "example": "examples" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/RIAEvangelist/event-pubsub.git" + }, + "keywords": [ + "event", + "events", + "pubsub", + "node", + "browser" + ], + "author": { + "name": "Brandon Nozaki Miller" + }, + "license": "Unlicense", + "bugs": { + "url": "https://github.com/RIAEvangelist/event-pubsub/issues" + }, + "homepage": "https://github.com/RIAEvangelist/event-pubsub", + "readme": "Event PubSub\n============\n\nPubsub events for Node and the browser allowing event scoping and multiple scopes. \nEasy for any developer level. No frills, just high speed pubsub events!\n\n---\n### Basic Examples\n---\n#### Node\n\n var events = new require('../../event-pubsub.js')();\n\n events.on(\n 'hello',\n function(data){\n console.log('hello event recieved ', data);\n }\n );\n \n events.on(\n '*',\n function(type){\n console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);\n }\n );\n \n /************************************\\\n * trigger events for testing\n * **********************************/\n events.trigger(\n 'hello',\n 'world'\n );\n\n#### Browser\n##### HTML\n\n var events = new require('../../event-pubsub.js')();\n\n events.on(\n 'hello',\n function(data){\n console.log('hello event recieved ', data);\n }\n );\n \n events.on(\n '*',\n function(type){\n console.log('Catch all detected event type of : ',type, '. List of all the sent arguments ',arguments);\n }\n );\n \n /************************************\\\n * trigger events for testing\n * **********************************/\n events.trigger(\n 'hello',\n 'world'\n );\n", + "readmeFilename": "README.md", + "_id": "event-pubsub@1.0.2", + "_from": "event-pubsub@" +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..5868a67 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "node-ipc", + "version": "0.0.2", + "description": "A nodejs module for local and remote Inter Process Communication (IPC) uses Unix Sockets for local communication avoiding the network card for lower overhead and latency. ## Solid but, ### Still under development and lacking documentation, but useable.", + "main": "node-ipc.js", + "directories": { + "example": "example" + }, + "dependencies": { + "event-pubsub": "~1.0.2", + "colors": "~0.6.2" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "IPC", + "inter", + "process", + "communication", + "unix", + "sockets", + "threaded", + "communication", + "multi", + "process", + "shared", + "memory" + ], + "author": "Brandon Nozaki Miller", + "license": "Unlicenced" +}