Skip to content

Commit

Permalink
added renderNamespace() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Apr 7, 2011
1 parent 1a1a29e commit 7dad7a3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/express-expose.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,31 @@ HTTPSServer.prototype.renderExposedJavaScript = function(name){
}).join('\n\n');
};

/**
* Render a namespace from the given `str`.
*
* Examples:
*
* renderNamespace('foo.bar.baz');
*
* var foo = foo || {};
* foo.bar = foo.bar || {};
* foo.bar.baz = foo.bar.baz || {};
*
* @param {String} str
* @return {String}
* @api private
*/

function renderNamespace(str){
var parts = [];
return str.split('.').map(function(part, i){
parts.push(part);
part = parts.join('.');
return (i ? '' : 'var ') + part + ' = ' + part + ' || {};';
}).join('\n');
};

/**
* Return a string representation of `obj`.
*
Expand Down

0 comments on commit 7dad7a3

Please sign in to comment.