Coder Social home page Coder Social logo

tuckn / wshmodejs Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 330 KB

The modern WSH (Windows Script Host) JScript library that mode of like Node.js.

Home Page: https://tuckn.net/docs/WshModeJs/

License: MIT License

JavaScript 63.49% CSS 36.36% Batchfile 0.15%
wsh jscript windows module wsf

wshmodejs's Introduction

WshModeJs

The modern WSH (Windows Script Host) JScript library that mode like Node.js.

Presentation PDF

tuckn/Wsh series dependency

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.

Operating environment

Works on JScript in Windows.

Installation

(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).

Usage

Now you can use the following many helpful functions in .\MyScript.js (JScript).

And also, use the following functions. For Example,

Readline

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 (W.I.P)

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...

Http

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...

TODO

  • Buffer, Http, Readline.

Documentation

See all specifications here and also below.

Upper Layer Modules

Please also refer to the more convenient upper-layer modules that use WshModeJs.

In addition, WshBasicApps can use all the above modules.

License

MIT

Copyright (c) 2020 Tuckn

wshmodejs's People

Contributors

tuckn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.