lib/express-expose.js
function expose(obj, namespace, name) {

  var app = this.app || this;
  var req = this.req;

  app._exposed = app._exposed || {};

  // support second arg as name
  // when a string or function is given
  if ('string' === typeof obj || 'function' === typeof obj) {
    name = namespace || _name;
  } else {
    name = name || _name;
    namespace = namespace || _namespace;
  }

  // buffer string
  if ('string' === typeof obj) {
    this.js = this.js || {};
    var buf = this.js[name] = this.js[name] || [];
    buf.push(obj);
  // buffer function
  } else if ('function' === typeof obj && obj.name) {
    this.expose(obj.toString(), name);
  // buffer self-calling function
  } else if ('function' === typeof obj) {
    this.expose(';(' + obj + ')();', name);
  // buffer object
  } else {
    this.expose(renderNamespace(namespace), name);
    this.expose(renderObject(obj, namespace), name);
    this.expose('\n');
  }

  // locals
  function locals(req, res) {

    var appjs = app.exposed(name);
    var resjs = res.exposed(name);
    var js = '';

    if (appjs || resjs) {
      js += '// app: \n' + appjs;
      js += '// res: \n' + resjs;
    }

    res.locals[name] = js;

  }


  // app level locals
  if (!req && !app._exposed[name]) {
    app._exposed[name] = true;
    app.use(function(req, res, next){
      locals(req, res);
      next();
    });
  // request level locals
  } else if (req) {
    locals(req, this);
  }

  return this;
}
function expose(obj, namespace, name) {

  var app = this.app || this;
  var req = this.req;

  app._exposed = app._exposed || {};

  // support second arg as name
  // when a string or function is given
  if ('string' === typeof obj || 'function' === typeof obj) {
    name = namespace || _name;
  } else {
    name = name || _name;
    namespace = namespace || _namespace;
  }

  // buffer string
  if ('string' === typeof obj) {
    this.js = this.js || {};
    var buf = this.js[name] = this.js[name] || [];
    buf.push(obj);
  // buffer function
  } else if ('function' === typeof obj && obj.name) {
    this.expose(obj.toString(), name);
  // buffer self-calling function
  } else if ('function' === typeof obj) {
    this.expose(';(' + obj + ')();', name);
  // buffer object
  } else {
    this.expose(renderNamespace(namespace), name);
    this.expose(renderObject(obj, namespace), name);
    this.expose('\n');
  }

  // locals
  function locals(req, res) {

    var appjs = app.exposed(name);
    var resjs = res.exposed(name);
    var js = '';

    if (appjs || resjs) {
      js += '// app: \n' + appjs;
      js += '// res: \n' + resjs;
    }

    res.locals[name] = js;

  }


  // app level locals
  if (!req && !app._exposed[name]) {
    app._exposed[name] = true;
    app.use(function(req, res, next){
      locals(req, res);
      next();
    });
  // request level locals
  } else if (req) {
    locals(req, this);
  }

  return this;
}
function expose ( obj , namespace , name ) { var app = this . app || this ; var req = this . req ; app . _exposed = app . _exposed || { } ; // support second arg as name // when a string or function is given if ( 'string' === typeof obj || 'function' === typeof obj ) { name = namespace || _name ; } else { name = name || _name ; namespace = namespace || _namespace ; } // buffer string if ( 'string' === typeof obj ) { this . js = this . js || { } ; var buf = this . js [ name ] = this . js [ name ] || [ ] ; buf . push ( obj ) ; // buffer function } else if ( 'function' === typeof obj && obj . name ) { this . expose ( obj . toString ( ) , name ) ; // buffer self-calling function } else if ( 'function' === typeof obj ) { this . expose ( ';(' + obj + ')();' , name ) ; // buffer object } else { this . expose ( renderNamespace ( namespace ) , name ) ; this . expose ( renderObject ( obj , namespace ) , name ) ; this . expose ( '\n' ) ; } // locals function locals ( req , res ) { var appjs = app . exposed ( name ) ; var resjs = res . exposed ( name ) ; var js = '' ; if ( appjs || resjs ) { js += '// app: \n' + appjs ; js += '// res: \n' + resjs ; } res . locals [ name ] = js ; } // app level locals if ( ! req && ! app . _exposed [ name ] ) { app . _exposed [ name ] = true ; app . use ( function ( req , res , next ) { locals ( req , res ) ; next ( ) ; } ) ; // request level locals } else if ( req ) { locals ( req , this ) ; } return this ; }
Expose the given `obj` to the client-side, with
an optional `namespace` defaulting to "express".

@param {Object|String|Function} obj
@param {String} namespace
@param {String} name
@return {HTTPServer} for chaining
@api public
Expose the given obj to the client - side with an optional namespace defaulting to express .