Last active
December 19, 2015 04:38
-
-
Save luuhq/5898350 to your computer and use it in GitHub Desktop.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
* | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment