The modern WSH (Windows Script Host) JScript library that mode like Node.js.
WshModeJs - This repository
└─ WshZLIB
└─ WshNet
└─ WshChildProcess
└─ WshProcess
└─ WshFileSystem
└─ WshOS
└─ WshPath
└─ WshUtil
└─ WshPolyfill
The upper layer module can use all the functions of the lower layer module.
Works on JScript in Windows.
(1) Create a directory of your WSH project.
D:\> mkdir MyWshProject
D:\> cd MyWshProject
(2) Download this ZIP and unzip or Use the following git
command.
> git clone https://github.com/tuckn/WshModeJs.git ./WshModules/WshModeJs
or
> git submodule add https://github.com/tuckn/WshModeJs.git ./WshModules/WshModeJs
(3) Create your JScript (.js) file. For Example,
D:\MyWshProject\
├─ MyScript.js <- Your JScript code will be written in this.
└─ WshModules\
└─ WshModeJs\
└─ dist\
└─ bundle.js
I recommend JScript (.js) file encoding to be UTF-8 [BOM, CRLF].
(4) Create your WSF packaging scripts file (.wsf).
D:\MyWshProject\
├─ Run.wsf <- WSH entry file
├─ MyScript.js
└─ WshModules\
└─ WshModeJs\
└─ dist\
└─ bundle.js
And you should include .../dist/bundle.js into the WSF file. For Example, The content of the above Run.wsf is
<package>
<job id = "run">
<script language="JScript" src="./WshModules/WshModeJs/dist/bundle.js"></script>
<script language="JScript" src="./MyScript.js"></script>
</job>
</package>
I recommend this WSH file (.wsf) encoding to be UTF-8 [BOM, CRLF].
Awesome! This WSH configuration allows you to use the following functions in JScript (.\MyScript.js).
Now you can use the following many helpful functions in .\MyScript.js (JScript).
- tuckn/WshPolyfill
- tuckn/WshUtil
- tuckn/WshPath
- tuckn/WshOS
- tuckn/WshFileSystem
- tuckn/WshProcess
- tuckn/WshChildProcess
- tuckn/WshNet
- tuckn/WshZLIB
And also, use the following functions. For Example,
var rl = Wsh.Readline; // Shorthand
var answer = rl.questionSync('Are you an engineer?/y or Not');
if (answer.toUpperCase() !== 'Y') return false;
// Now only `questionSync` works...
Buffer object is defined globally.
var buf = Buffer.from('012345XYZ');
console.log(buf.toString('utf8')); // 012345XYZ
console.log(buf.toString('base64')); // MDEyMzQ1WFla
console.log(buf.toString('hex')); // 30313233343558595a
console.log(buf.values()); // <Buffer 30 31 32 32 ....>
// Now only `from` works...
var http = Wsh.Http; // Shorthand
// Ex 1. Auto JSON parsing
http.request('https://httpbin.org/ip');
// Returns: { origin: '111.222.333.444' }
// Ex 2. Basic Auth
http.request('https://httpbin.org/basic-auth', { auth: 'myUser:myPasswd' });
// Ex 3. Using proxy
http.request('https://httpbin.org/headers', {
proxy: {
host: '192.168.12.34',
port: 8087,
proxyAuth: 'proxyUser:proxyPassword'
});
// Returns:
// { headers: {
// Accept: "\*\/*",
// Accept-Language: "ja",
// Host: "httpbin.org",
// User-Agent: "Mozilla/4.0 (compatible; Win32; WinHttp.WinHttpRequest.5)",
// X-Amzn-Trace-Id: "Root=1-1234abcd-12345678abcdefg123456789"
// }
// }
// Ex 4. POST data
http.request('https://httpbin.org/post?argA=valA', {
method: 'POST',
dataToSend: 'formB=' + encodeURIComponent('value B')
});
// Returns:
// { args: { argA: "valA" },
// data: "",
// files: {},
// form: { formB: "valB" },
// headers: { ... },
// json: null,
// origin: "111.222.333.444",
// url: "https://httpbin.org/post?%3FargA=valA" }
// Now only `request` works...
- Buffer, Http, Readline.
See all specifications here and also below.
Please also refer to the more convenient upper-layer modules that use WshModeJs.
In addition, WshBasicApps can use all the above modules.
MIT
Copyright (c) 2020 Tuckn