public
Last active

Fakenode is a hack that can be used along with resolverjs (search on NPM) to allow a Javascript file running under NodeJS or in the browser

  • Download Gist
fakenode.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// sluu99 (C) 2013
// Released under WTFPL
// Fakenode version 0.0.1
window.require = function(x) {
if (x === 'resolverjs') {
return {
get: function(x, defaultVal) { return defaultVal; }
};
}
 
return undefined;
}
 
/** Usage:
* This file is meant to be used in the browser with a <script> tag.
* Combine this with the resolvejs package (https://npmjs.org/package/resolverjs) to use modules that
* can work on both NodeJS and the browser:
*
* Example:
*
* var resolver = require('resolverjs'); *
* // If we are in the browser, then MyValidator should already be present from a <script> tag
* var klass = (typeof(MyValidator) === 'undefined')? null : MyValidator;
* var validator = resolver.get('libs/validator', klass);
*
*/

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.