UNPKG

@wider/utils_where-am-i

Version:

Determine where your code is running

29 lines (21 loc) 781 B
'use strict'; // this will only work under Wscript or classicASP /* jshint -W061 */ /* jshint -W089 */ /* jshint -W117 */ var fso = new ActiveXObject("Scripting.FileSystemObject"); function saveFile(strFullPath, strContent) { var file = fso.CreateTextFile(strFullPath, true); file.Write(strContent); file.Close(); file = null; } var whereAmIFile = "./index.js"; // replace this with a fully resolved path eval(fso.OpenTextFile(whereAmIFile).ReadAll()); // or otherwise obtain the script var whereObj = whereAmI(); // example use to write the results to a json file var result = []; for (var entry in whereObj) { result.push('"' + entry + '": "' + whereObj[entry] + '"'); } saveFile("./textWindowsResult.json", "{" + result.join(",") + "}");