Last active
October 18, 2015 14:45
-
-
Save ildar-shaimordanov/df8de7b12fa0017d96ee to your computer and use it in GitHub Desktop.
CommonJS functions for WSH JScript
This file contains 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
/* this code is public domain */ | |
function require(path) | |
{ | |
var fso = WScript.CreateObject("Scripting.FileSystemObject"); | |
var file_path = path + ".js"; | |
var input_stream = fso.OpenTextFile(file_path, 1, false); | |
var module_code = input_stream.ReadAll(); | |
input_stream.Close(); | |
var eval_code = "(function(){" + | |
"var exports = {};" + | |
model_code + ";" + | |
"return exports;" + | |
"})()"; | |
return eval(eval_code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment