Folder Organization
jsh (base folder)
├─bin (libraries for specific platform)
├─cxx (used by script injection)
└─lib (folder for platform independent libraries, each library can be used alone)
Library Organization
Tartarus.js (load other libraries, print messages)
Prelude.js (fundamental algorithm, data structure and exception)
Intermezzo.js (utility for web browser and DOM)
URI.js (URI parsing and normalization)
AES.js (AES encryption and decryption)
Base64.js (Base64 encoding and decoding)
LZW.js (LZW compression and decompression)
UTF8.js (UTF8 encoding and decoding)
UTF16.js (UTF16 encoding and decoding, with BOM BE/LE support)
JSH Runtime
__builtins__
All JSH related data are kept in the __builtins__ global variable.
__builtins__.Engine string
__builtins__.Environment object
__builtins__.Terminate() function
_ (underscore)
When running in interactive mode, an additional global variable named _ (a single underscore) is maintained, which always holds the last successful evaluation result.
. commands
These are also known as meta commands, available when running interactively in browser and HTA.
.cls (clear output)
.history (show command history)
.wrap (toggle output wrapping)
Library API
Tartarus
chainload(...)
load scripts one by one in the given order, if the argument is a Function instead of script name String, execute the function instead.
Tartarus.chainload('http://localhost/script1.js', 'script2.js', '../script3.js');
Tartarus.chainload(
function(){Tartarus.print('Load the first script...');},
'http://localhost/sample.js',
function(){Tartarus.print('Load the second script...');},
'./script.js',
function(){Tartarus.print('Done');});load(...)
similar to Tartarus.chainload, but load the scripts concurrently.
if the last argument is a Function, this function will be executed only when all the scripts are loaded.
Tartarus.load(
'../lib/Prelude.js',
'../lib/Intermezzo.js',
'../lib/URI.js',
function(){
Tartarus.print(Prelude.dir(URI));,
});print(...)
output in a proper manner.
Tartarus.print('Hello, world!');
Tartarus.print(1, 2, 3, [4, 5, 6], undefined, null);
Tartarus.print(Tartarus);Prelude
Exception
add
aggr
alist
all
any
assert
chr
cmp
comp
concat
curry
dcomp
dict
dir
div
exception
filter
format
globals
idn
infect
list
map
max
mfilter
min
mmap
mul
one
ord
plain
props
proto
quote
range
reduce
reflect
repr
set
split
squote
str
sub
uniq
zero
zip
zlist
Intermezzo
AddEventListener
Intermezzo.AddEventListener(document.body, 'click', function(elem){
Tartarus.print(elem);
});AppendNode
Intermezzo.AppendNode(document.body,
['A', {href: 'http://code.google.com/p/jsh/'}, 'JavaScript Shell']);
Intermezzo.AppendNode(document.body,
['DIV', function(elem){
elem.style.fontWeight = 'bold';
}, 'Hello, world!']);
Intermezzo.AppendNode(document.body,
['H3', null, 'Unordered lists (UL), ordered lists (OL), and list items (LI)'],
['UL', null,
['LI', null, 'Level 1, number 1'],
['LI', null, 'Level 1, number 2'],
['LI', null, 'Level 1, number 3']],
['OL', null,
['LI', null, 'Level 1, number 1'],
['LI', null, 'Level 1, number 2'],
['LI', null, 'Level 1, number 3']],
['H3', null, 'Definition lists: DL, DT and DD'],
['DL', null,
['DT', null, 'Dweeb'],
['DD', null,
'young excitable person who may mature into a ',
['EM', null, 'Nerd'],
' or ',
['EM', null, 'Geek']],
['DT', null, 'Hacker'],
['DD', null, 'a clever programmer'],
['DT', null, 'Nerd'],
['DD', null, 'technically bright but socially inept person'],
['DT', null, 'Center'],
['DT', null, 'Centre'],
['DD', null, 'A point equidistant from all points on the surface of a sphere.']]
);DomTraveler
Intermezzo.DomTraveler(document, function(elem, level){
if(level && level < 4)
Tartarus.print(Prelude.format('%r %s', level, elem.tagName));
});GetComputedStyle
Intermezzo.GetComputedStyle(document.body).backgroundColor;
GetSelectedText
Hypertext
Intermezzo.Hypertext('<Hello, world!>');Navigate
Intermezzo.Navigate('about:blank');ParseXML
Intermezzo.ParseXML('<test>Hello, world!</test>').getElementsByTagName('test');RegisterGlobalExceptionHandler
RemoveEventListener
RemoveNode
Prelude.map(Intermezzo.RemoveNode, document.getElementsByTagName('SPAN'));XMLHttpRequest
URI
GetCurrentURI()
Tartarus.print(URI.GetCurrentURI());
NormalizeURI(String uri, [String base])
URI.NormalizeURI('HTTP://User:Password@WWW.TEST.ORG:00080#a');
URI.NormalizeURI('http://www.test.org/a/../b/../c');
URI.NormalizeURI('http://www.test.org/a/../b/../c');
URI.NormalizeURI('a.js', 'http://localhost');
URI.NormalizeURI('/a.htm', 'http://localhost/hello/world/');
URI.NormalizeURI('../a.htm', 'http://localhost/hello/world/');
URI.NormalizeURI('mailto:guy@gmail.com', 'http://localhost');
URI.NormalizeURI('a/b', 'file:///c/d');ParseURI(string)
URI.ParseURI(URI.GetCurrentURI())['scheme'];
AES
Encrypt(string, string password, [int bits])
AES.Encrypt('Hello, world!', 'qwerty');Decrypt(string, string password)
AES.Decrypt('j\xac\xf3\xb06\x01!0!!0!-,\x8e\xc5\xbc\x8eZ/>\xc0\x18\xb4X\xe5', 'qwerty');Base64
Encode(string)
Base64.Encode('Hello, world!');
Base64.Encode("abc");Decode(string)
Base64.Decode('SGVsbG8sIHdvcmxkIQ==');LZW
Compress(string)
LZW.Compress('Hello, woooooooooooooooooooooooooooooooooooooorld!');Decompress(string)
LZW.Decompress('H2\x9b\r\x86\xf1`\x80\xeeo\x84BaP\xb8d6\x1d\b9\x1b\x0c\x82\x10');UTF8
Encode(string)
UTF8.Encode('Frédéric Chopin');Decode(string)
UTF8.Decode('Fr\xc3\xa9d\xc3\xa9ric Chopin');UTF16
Encode(string, String pack, [Boolean bom])
pack can be "BE" (big endian) or "LE" (little endian)
bom can be true of false, if set to true, a BOM header will be included.
Prelude.list(UTF16.Encode('Frédéric Chopin', 'LE', true));Decode(string, pack)
UTF16.Decode(UTF16.Encode('Hello, world!', 'BE'), 'BE');