Skip to content

Instantly share code, notes, and snippets.

@ildar-shaimordanov
Last active October 18, 2015 14:45
Show Gist options
  • Save ildar-shaimordanov/df8de7b12fa0017d96ee to your computer and use it in GitHub Desktop.
Save ildar-shaimordanov/df8de7b12fa0017d96ee to your computer and use it in GitHub Desktop.
CommonJS functions for WSH JScript
/* 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