0.0.3 • Published 13 years ago
ohai v0.0.3
Ohai.js
OHAI.js is a NodeJS library whose aim is to provide a shared namespace between client and server in order to be able to call server-defined functions on the client and viceversa.
License: WTFPL (check LICENSE for further details)
Example:
The following code outputs "go!" in the console where the NodeJS server is running.
On the server:
ns = require('ohai');
ohai = ns.namespace();
ohai.go = function() {
console.log('go!');
}
On the client:
ohai.ready(function() {
ohai.go();
});
Filters:
You can declare filters on server's functions
ns = require('ohai');
ohai = ns.namespace();
ohai.puts = function(string) {
console.log(string);
}
ns.add_rule("puts",{
arguments : { 0 : /(\w+)/g }
});
"arguments" can also be a function that returns true or false
ns = require('ohai');
ohai = ns.namespace();
ohai.puts = function(string) {
console.log(string);
}
ns.add_rule("puts",{
arguments : function() {
if ( /(\w+)/.test(arguments[0]) ) {
return true;
}
else {
return false;
}
}
});