Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Header

JS - Maximum Tension

Maximum Tension™ . Teoman Deniz . maximum-tension.com

License: MIT . Created 2013/11/04

JS (JavaScript Framework) is a small utility framework for browsers, old Internet Explorer and the Windows Script Host: type checks, cloning, iteration, string templates, DOM helpers, AJAX and storage behind one uppercase API.

I made it because I was writing the same helpers on every project. Now I drop one file in and use the globals. The same code reads the same in a modern browser, in old Internet Explorer and in a cscript automation script.

  • No build step, no dependencies. Copy one file, add one <script> tag, done.
  • Three builds, one API. JS.js, IE.js and WSCRIPT.js share the same names, so you don't relearn anything when the environment changes.
  • One AJAX result everywhere. Every request gives {STATUS, DATA} and never throws, in all three builds.
  • Modern syntax on old IE. IE.js rewrites <script type="module"> blocks (let, const, arrow functions, template literals) so IE can run them.
Table of Contents

Builds

Build File Environment Language level AJAX style
Modern JS.js Modern browsers ES6+ (const/let, arrow fns, Promise, async) Asynchronous, returns a Promise
Legacy IE.js Internet Explorer and old browsers ES3 (var, function expressions) Synchronous, ActiveXObject then XMLHttpRequest
Shell WSCRIPT.js Windows Script Host (cscript/wscript) ES3 (var, function expressions) Synchronous, ActiveXObject

Each build puts its API on plain globals: JS, and depending on the build some of WINDOW, DOM, AJAX, WS and LOCAL_STORAGE.

You load exactly one build per program. They are not meant to be combined.

Which build should I use?

  • JS.js is the default for anything running in an up-to-date browser. AJAX returns promises, so you await it.
  • IE.js has the same API as JS.js, but it runs on Internet Explorer and other old engines. AJAX is synchronous (no await). It also polyfills Promise, JSON and Function.prototype.bind.
  • WSCRIPT.js is for automation scripts under the Windows Script Host. There is no browser there, so it drops every DOM and window helper and adds console I/O, file I/O and message boxes.

You can also find the Mini versions of these frameworks here.


Getting started

Browser

<!--[if IE]>
 <script type="text/javascript" src="IE.js"></script>
<![endif]-->
<!--[if !IE]>-->
 <script type="text/javascript" src="JS.js"></script>
<!--<![endif]-->
<script>
DOM.START(
	function()
	{
		WINDOW.TITLE("Ready");
		var BOX = DOM.GET.ID("app");
		DOM.CLASS.ADD(BOX, "loaded");
	}
);
</script>

IE.js is a drop-in replacement. Swap the src and the same code runs on old engines, with AJAX returning the result directly instead of a promise.

Modern syntax on IE

Write your page code in <script type="module">. Modern browsers run it natively. Old IE skips module scripts by itself, and IE.js picks them up, rewrites them with JS.TRANSPILE and runs them before your DOM.START callbacks.

<script type="module">
const NAMES = ["Ada", "Linus"];

JS.ITERATE(NAMES, NAME => DOM.GET.ID("list").innerHTML += `<li>Hello ${NAME}</li>`);
</script>

<script type="module" src="app.js"></script>

On IE, that first block runs as:

var NAMES = ["Ada", "Linus"];

JS.ITERATE(NAMES, function(NAME){return (DOM.GET.ID("list").innerHTML += ("<li>Hello " + (NAME) + "</li>"));});

Only let/const, arrow functions and template literals are rewritten.

Classes, destructuring, for...of, spread, default parameters, async/await and import/export are not. Built-in methods like Array.prototype.map are not polyfilled either. Full list in JS.md.

Windows Script Host

cscript //nologo yourscript.js
// yourscript.js
JS.ECHO("Building...\n");
var	RES = AJAX.GET("https://api.example.com/status");

if (AJAX.OK(RES))
	JS.INFO("Up: " + RES.DATA.state, "Status");
else
	JS.ERROR("Down (" + RES.STATUS + ")", "Status");

Documentation

Every object and function is documented here:

  • JS.md for the browser builds, JS.js and IE.js.
  • WSCRIPT.md for the Windows Script Host build, WSCRIPT.js.

Namespace coverage

Not every namespace exists in every build. The browser-only ones are not in the shell build, on purpose.

Namespace Purpose JS.js IE.js WSCRIPT.js
JS (core utils) Type checks, clone, merge, iterate, template OK OK OK
JS.TRANSPILE Rewrites modern syntax for old engines - OK -
JS (I/O + dialogs) Console/file I/O, message boxes - - OK
WINDOW Title, favicon, popups, URL/navigation OK OK -
DOM Element create/query/class/attribute helpers OK OK -
AJAX HTTP GET, POST, DATA, DELETE, REQUEST Async Sync Sync
WS WebSocket helpers OK OK -
LOCAL_STORAGE Typed localStorage wrapper OK OK -

AJAX

All three builds share one result shape. A request never throws and never rejects:

{STATUS: <number>, DATA: <object|string>}
Field Meaning
STATUS The HTTP status code. It is 0 when no HTTP response came back (network error, no XHR).
DATA The parsed JSON body when it is valid JSON, the raw text when it is not, or "" when empty.
Call Sends
AJAX.GET(URL) Nothing
AJAX.POST(URL, BODY) BODY as JSON, always ({} when left out)
AJAX.DATA(URL, DATA) A string, FormData or Blob as it is, anything else as JSON
AJAX.DELETE(URL, BODY) Same rules as DATA, the body is optional
AJAX.REQUEST(METHOD, URL, BODY) Any method (PUT, PATCH, ...), same body rules as DATA
AJAX.OK(RESULT) Nothing, it returns true for any 2xx status
// JS.js
var	RES = await AJAX.DELETE("/api/users/5");

// IE.js and WSCRIPT.js
var	RES = AJAX.DELETE("/api/users/5");

if (AJAX.OK(RES))
	console.log("Deleted");
else
	console.log("Failed: " + RES.STATUS);

I changed this in 2026/11. Before, every build had its own failure shape: GET gave undefined, POST added STATUS into the server's JSON, DATA rejected in JS.js and gave {AJAX_STATUS, AJAX_MESSAGE} in IE.js. Only 200 counted as success. If you have old code that reads those, switch it to RES.STATUS / RES.DATA and AJAX.OK(RES).

AJAX.DATA stays because it is the upload call: it is the only one that sends FormData, Blob, File or a raw string. POST is the simple "send this object as JSON" call.


Coding conventions

The framework follows one house style, and contributions should match it:

  • Uppercase identifiers for the public API and local variables (JS.IS_NULL, VALUE, TARGET).
  • Tabs for indentation.
  • Parenthesized returns: return (VALUE);.
  • JSDoc on every public function (@param / @return).

Notes and caveats

  • Synchronous AJAX blocks. IE.js and WSCRIPT.js send blocking requests. That's fine for shell scripts but it freezes a browser page while it waits. Use JS.js where responsiveness matters.
  • JSON under WSH. Classic JScript has no native JSON object. WSCRIPT.js uses JSON.parse/JSON.stringify, so run it under an engine that has them, or include a JSON polyfill.
  • Module scripts on IE run synchronously. External <script type="module" src="..."> files are loaded with a blocking AJAX.GET, so they must be on the same origin.
  • IE.js and IE10/11. Conditional comments (<!--[if IE]>) only work up to IE9. IE10 and IE11 ignore them and get JS.js.

Extras

Issues

If something is broken or missing, open an issue here. Tell me which build (JS.js, IE.js or WSCRIPT.js), which browser or Windows version, and a few lines that show the problem.

License

MIT © Teoman Deniz - maximum-tension.com. See the LICENSE file.

Releases

Packages

Contributors

Languages