WSHModule is a JavaScript virtual machine built in WSH/JScript.
It is a subset of the JavaScript interpreter that supports to compatible with the ECMAScript 5 standard in WSH/JScript.
WSHModule's script run at module scope (CommonJS/UMD) that means it can use require
, exports
and module
objects.
WSHModule can assist to upgrade JScript in Windows Script Host as much as possible to approach the ECMA-262 standard.
Possibly, better to use Node.js it would be quickly. However, JScript has been bundled with Windows. Improves a local environment when run a batch script with extension "js" by the passage to WSHModule.
- Windows (32bit/64bit)
WSHModule will work with WSH version 5.6 or later.
Currently, WSHModule does not use file type association and Windows environment (eg., PATH).
WSHModule supports the following features:
- Supports ECMAScript5 standard syntax.
- Supports CommonJS Universal Module Definition (UMD).
- Working with UTF-8 encoding.
- Supports standard DOM functions: alert/confirm/prompt, setTimeout/clearTimeout and setInterval/clearInterval.
- Supports a console window.
- Fixed JScript bug: try-finally statements, String.prototype.substr, Array.indexOf and Array.prototype.splice functions to standard ECMA-262.
Runs script with WSHModule:
WSHModule.exe "C:/path/to/myscript.js"
or
Execute (drag-drop) C:/path/to/myscript.js
to WSHModule.exe
- Create a shortcut of WSHModule.exe to desktop.
- Execute script by drag-drop to shortcut.
Runs test script:
cd WSHModule
"bin/WSHModule.exe" "scripts/test.js"
Getter
andSetter
support."use strict"
syntax support.
bin/src/WSHModule
is built on Lazarus (Free Pascal)
- Copy
bin/wshmodule.wsf
andbin\wshmshell.js
tobin/src/WSHModule
folder - Download Lazarus IDE and Install
- Project -> Open Project -> Open
bin/src/WSHModule/WSHModule.lpr
(ChangeAll files (*.*)
) - Confirm dialog
The file "WSHModule.lpr" is not a Lazarus project. Create a new project for this "program"?
->Create project
- Select
Application
- Run (Menu
Run -> Run
) or Build (MenuRun -> Build
)
You can get a WSHModule.exe
by build, and also run JavaScript with WSHModule console, for example, typing 1+1
and press enter key in the console window, you can get result 2
.
- __filename : Current filename
- __dirname : Current dirname
Example
console.log(__filename); // C:\path\to\your_script.js
console.log(__dirname); // C:\path\to
Example
var clip = require('clip');
clip.set('test');
Available format: 'text' or 'html'
- get ([format = 'text']) : Get clipboard text as [format]
- set (data, [format = 'text']) : Set data to clipboard as [format]
- empty() : Empty clipboard data
- hasFormat(format) : Check whether clipboard has a format
- getAsText() : A shortcut of
get('text')
- getAsHTML() : A shortcut of
get('html')
- setAsText(data) : A shortcut of
set(data, 'text')
- setAsHTML(data) : A shortcut of
set(data, 'html')
- copy() : Emulate copy command of the keyboard
- paste() : Emulate paste command of the keyboard
- cut() : Emulate cut command of the keyboard
- getSelectedText() : Get selected text to clipboard (shortcut of
copy()
andget()
) - print(text) : Print clipboard text (shortcut of
set(text)
andpaste()
)
Local file system utility
var fs = require('fs');
console.log(fs.readFileSync('./test.txt'));
- renameSync(oldPath, newPath) : Rename file
oldPath
tonewPath
- statSync(path) : Get file stat
- unlinkSync(path, force = false) : Remove file
- existsSync(path) : Check whether a file exists
- readFileSync(filename, encoding = 'utf-8') : Read content from
filename
- writeFileSync(filename, data, encoding = 'utf-8') : Write content
data
tofilename
- copySync(src, dst, overwrite = false) : Copy file
src
todst
- moveSync(src, dst) : Move file from
src
todst
MIT
This project is using on the following excellent free yet copyrighted open source softwares. We follow the policies of those software packages.
- superobject (MPL1.1)