ohai

0.0.3 • Public • Published

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;
    }
  }
});

Readme

Keywords

none

Package Sidebar

Install

npm i ohai

Weekly Downloads

1

Version

0.0.3

License

none

Last publish

Collaborators

  • yawn