Updated: 2026-04-24

The ucode language is a tiny general purpose scripting language featuring a syntax closely resembling ECMAScript. It comes in OpenWrt installation bundle, and can also be installed separately.

Ucode Quick Guide

marks expandable cells: click the cell to see more. Click again to close.

This help sheet contains mainly commands from ucode core module. Look https://ucode.mein.io/ for more information. Another source for information: https://github.com/TjeuKayim/ucode

Contents

How to find out the path/name of the executing script: SCRIPT_NAME
How to pass command line arguments to a script: ARGV
How to execute an external command: system(command, timeout)
How to execute an external command and read output: popen(command, mode)
Comment
Variable
Control
Array
String
Function
Object
Bool
Time
Int
Regexp
Double
System
File

comment

// comment   Single-line comment: from '//' to the end of the line arr = [ 'A', 'B']; // The text between '//' and the end of the line is ignored
 
/* comment 1/2 */   Multi-line comment between '/*' and '*/' /* The following two lines are ignored
print('Not ');
print('displayed');
*/
/* comment 2/2 */   Inline comment between '/*' and '*/' obj = { /* 1st letter */ 'A': 'a', /* 2nd letter */ 'B': 'b' };
print(obj); // { "A": "a", "B": "b" }

variable

variable =   Define global variable var1 = 12.34;
var2 = [ 1, 'B', 3, 'D' ];
let variable =   Define local variable let var1 = false;
let var2 = { 'A': 1, 'b':, 2, 'C': 3 };
const constant =   Define local constant const var1 = 1234;
const var2 = 0.221;

control

if (else if) (else)   Controls execution flow let a = 6;
if (a < 3) {
print('Do not print this);
} else if (a < 5) {
print('Do not print this either);
} else {
print('Please, print this);
}
while   Loop as long as the condition is true i = 0;
arr = [1, 2, 3];
while (i < length(arr)) {
print(arr[i], ' ');
i++;
}
for   Two styles of for loop // execute for each item in arr / obj
arr = [1, 2, 3];
for (n in arr) {
print(n, ' ');
}
obj = { Alice: 32, Bob: 54 };
for (person in obj) {
print(person, ' is ', obj[person], ' years old. ');
}

for (j = 0; j < length(arr); j++) {
print(arr[j], ' ');
}
switch   Select code blocks based on an expression switch (var) {
case 32:
print('thirtytwo');
break;
case 11:
print('eleven');
break;
case 6:
case 2:
print('six or two');
break;
default:
print('something else');
}
break   Terminates the current loop or switch statement i = 0;
arr = [1, 2, 3];
while (i < length(arr)) {
if (i == 2) {
break; // Leave the while loop when i == 2
}
print(arr[i], ' ');
i++;
}
continue   Terminates the current iteration of the loop and continues with the next iteration i = 0;
arr = [1, 2, 3, 4];
while (i < length(arr)) {
if (i == 2) {
continue; // Do not print arr[2]
}
print(arr[i], ' ');
i++;
}
assert(cond, message)   Raise an exception with the given message parameter when the value in cond is not truish assert(true, 'This is true'); // No exception is raised
assert(false); // Exception is raised with the default message 'Assertion failed'
call(fn, ctx, scope, …arg)   Calls the given function value with a modified environment // Override this context
call(function() { printf('%J', this) }, { x: 1 }); // { 'x': 1 }
call(function() { printf('%J', this) }, { x: 2 }); // { 'x': 2 }

// Run with default scope
global.a = 1;
call(function() { printf('%J', a) }); // 1

// Override scope, inherit from current global scope (implicit)
call(function() { printf('%J', a) }, null, { a: 2 }); // 2

// Override scope, inherit from current global scope (explicit)
call(function() { printf('%J', a) }, null,
proto({ a: 2 }, global)); // 2

// Override scope, don't inherit (pass `printf()` but not `a`)
call(function() { printf('%J', a) }, null,
proto({}, { printf })); // null

// Forward arguments
x = call((x, y, z) => x * y * z, null, null, 2, 3, 4); // x = 24
die(msg)   Raise an exception with the given message and abort execution die(msg);
 
exit(n)   Terminate the interpreter with the given exit code exit();
exit(5);
gc(operation, argument)   Interacts with the mark and sweep garbage collector of the running ucode virtual machine gc(); // true
gc('start'); // true
gc('count'); // 42
include(path, scope)   Execute included ucode file include('./foo.uc'); // Load and execute 'foo.uc' immediately

// Execute the 'supplemental.uc' in an extended scope and make the 'foo'
// and 'bar' properties available as global variables
include('./supplemental.uc', {
foo: true,
bar: 123
});

// Execute the 'untrusted.ucode' in a sandboxed scope and make the 'foo' and
// 'bar' variables as well as the 'print' function available to it
// By assigning an empty prototype object to the scope, included code has no
// access to other global values anymore
include('./untrusted.uc', proto({
foo: true,
bar: 123,
print: print
}, {}));
render(path_or_func, scope_or_fnarg1, …fnargN)   Execute included ucode file, or a function, and capture output // Renders template file with given scope and captures the output as a string
output = render('./template.uc', { foo: 'bar' });

// Calls a function, captures the output, and returns it as a string
result = render(function(name) {
printf('Hello, %s! ', name);
}, 'Alice');
require(name)   Load and evaluate ucode scripts or shared library extensions // Require the `example/acme.uc` or `example/acme.so` module
acme = require('example.acme');
signal(signal, handler)   Set or query process signal handler function signal('INT', 'ignore'); // Ignore signal

signal('INT', 'default'); // Restore signal default behavior

// Set custom handler function
function intexit(signo) {printf('I received signal number %d ', signo); exit(1);}
sleep(milliseconds)   Pause execution for the given amount of milliseconds // Sleep for 1 second
bool1 = sleep(1000); // bool: true
trace(level)   Enables or disables VM opcode tracing trace(1); // Enables opcode tracing
trace(0); // Disables opcode tracing

array

ARGV   Command line arguments are passed to the script in array ARGV print(ARGV); // [ "arg1", "arg2", "arg3" ]
 
arrtoip(arr)   Convert the given input array of byte values to an IP address string arr1 = [ 192, 168, 1, 1 ]; // array: [ 192, 168, 1, 1 ]
str1 = arrtoip(arr1); // string: "192.168.1.1"

arr2 = [ 254, 128, 0, 0, 0, 0, 0, 0, 252, 84, 0, 255, 254, 130, 171, 189 ]; // array: [ 254, 128, 0, 0, 0, 0, 0, 0, 252, 84, 0, 255, 254, 130, 171, 189 ]
str2 = arrtoip(arr2); // string: "fe80::fc54:ff:fe82:abbd"
clock(monotonic)   Reads the current second and microsecond value of the system clock arr1 = clock(); // array: [ 1774602416, 938236454 ]
arr2 = clock(true); // array: [ 23724, 811128256 ]
filter(arr, fn)   Filter the array passed as the first argument by invoking the function specified in the second argument for each array item arr1 = ['foo', '', 'bar', '', 'baz']; // array: [ "foo", "", "bar", "", "baz" ]
arr2 = filter(arr1, length); // array: [ "foo", "bar", "baz" ]

arr3 = ['foo', 1, true, null, 2.2]; // array: [ "foo", 1, true, null, 2.2 ]
arr4 = filter(arr3, function(v) {return (type(v) == 'int' || type(v) == 'double');}); // array: [ 1, 2.2 ]
index(arr_or_str, needle)   Finds the given value passed as the second argument within the array or string specified in the first argument str1 = 'Hello hello hello'; // string: "Hello hello hello"
int1 = index(str1, 'll'); // int: 2

arr2 = [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]; // array: [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
int2 = index(arr2, 2); // int: 1

arr3 = ['Red', 'Blue', 'Green']; // array: [ "Red", "Blue", "Green" ]
int3 = index(arr3, 'Brown'); // int: -1
iptoarr(address)   Convert the given IP address string to an array of byte values str1 = '192.168.1.1'; // string: "192.168.1.1"
arr1 = iptoarr(str1); // array: [ 192, 168, 1, 1 ]

str2 = 'fe80::fc54:ff:fe82:abbd'; // string: "fe80::fc54:ff:fe82:abbd"
arr2 = iptoarr(str2); // array: [ 254, 128, 0, 0, 0, 0, 0, 0, 252, 84, 0, 255, 254, 130, 171, 189 ]
join(sep, arr)   Joins the array passed as the second argument into a string, using the separator passed in the first argument as glue arr1 = [ 'aa', 'BB', 'cc' ]; // array: [ "aa", "BB", "cc" ]
str1 = join(':', arr1); // string: "aa:BB:cc"
json(str_or_resource)   Parse the given string or resource as JSON and return the resulting value str1 = '{ "a":true, "b":123 }';
obj1 = json(str1);

import { open } from 'fs';
fd = open('example.json', 'r');
// will keep invoking fd.read() until EOF and incrementally parse each read chunk
obj2 = json(fd);

arr3 = proto(['{"foo":', 'true, ', '"bar":', 'false}'], {read: function() {return shift(this)}});
obj3 = json(arr3);
keys(obj)   Enumerates all object key names obj1 = { 'one': 1, 'two': 2, 'six': 6 }; // object: { "one": 1, "two": 2, "six": 6 }
arr1 = keys(obj1); // array: [ "one", "two", "six" ]
length(x)   Determine the length of the given object, array or string str1 = 'test'; // string: "test"
int1 = length(str1); // int: 4

arr2 = [true, false, null, 123, 'test']; // array: [ true, false, null, 123, "test" ]
int2 = length(arr2); // int: 5

obj3 = {foo: true, bar: 123, baz: 'test'}; // object: { "foo": true, "bar": 123, "baz": "test" }
int3 = length(obj3); // int: 3
map(arr, fn)   Transform the array passed as the first argument by invoking the function specified in the second argument for each array item arr1 = ['Apple', 'Banana', 'Bean'];
arr2 = map(arr1, length);

arr3 = ['foo', 1, true, null, 2.2];
arr4 = map(arr3, type);

arr5 = ['22', '1010', '0001', '0101'];
arr6 = map(arr5, (x) => int(x, 2));
match(str, pattern)   Match the given string against the regular expression pattern specified as the second argument rex1 = regexp('b.(.)'); // regexp: /b.(.)/
str1 = 'foobarbaz'; // string: "foobarbaz"
arr1 = match(str1, rex1); // array: [ "bar", "r" ]

arr2 = match('foobarbaz', /b.(.)/g); // array: [ [ "bar", "r" ], [ "baz", "z" ] ]
pop(arr)   Pops the last item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = pop(arr1); // int: 3
print(arr1); // [ 1, 2 ]

arr2 = [ 1, 2, 'three', 4.09, false, [ 6, 7 ], { 'last': 7 } ]; // array: [ 1, 2, "three", 4.09, false, [ 6, 7 ], { "last": 7 } ]
obj3 = pop(arr2); // object: { "last": 7 }
arr3 = pop(arr2); // array: [ 6, 7 ]
bool3 = pop(arr2); // bool: false
dbl3 = pop(arr2); // double: 4.09
str3 = pop(arr2); // string: "three"
int3 = pop(arr2); // int: 2
print(arr2); // [ 1 ]
print(…values)   Print any of the given values to stdout str1 = 'Hello'; // string: "Hello"
print(str1, ' world!'); // Hello world!

arr2 = [ 1, 'B', 3 ]; // array: [ 1, "B", 3 ]
print(arr2); // [ 1, "B", 3 ]

obj3 = { hello: true, world: 123 }; // object: { "hello": true, "world": 123 }
print(obj3); // { "hello": true, "world": 123 }

print(10 / 3.0); // 3.3333333333333
print(1 != 2); // true
print(0xff); // 255

print(proto({foo: 'bar'}, {tostring: () => 'MyObj'})); // MyObj
printf(fmt, …Arguments)   Formats the given arguments according to the given format string and outputs the result to stdout str1 = 'Hello'; // string: "Hello"
printf('%s world', str1); // Hello world

int2 = 123; // int: 123
printf('%08x', int2); // 0000007b

printf('%g', 10 / 3.0); // 3.33333
printf('%2$d %1$d', 12, 34); // 34 12

printf('%J', [1,2,3]); // [ 1, 2, 3 ]
printf('%.2J', [1,2,3]); // [ 1, 2, 3 ]

printf('%J', {'c': 1, 'b': 2, 'a': 3}); // { "c": 1, "b": 2, "a": 3 }
printf('%s', 32 < 10); // false
proto(val, proto)   Get or set the prototype of the array or object value val arr1 = [1, 2, 3];
obj1 = proto(arr1);
arr2 = proto(arr1, { foo: true });
obj2 = proto(arr1);
obj3 = proto(arr2);
push(arr, …values)   Pushes the given argument(s) to the given array arr1 = [ 1, 2 ]; // array: [ 1, 2 ]
str2 = push(arr1, 'three', 'four'); // string: "four"
dbl2 = push(arr1, 5.09, 6.1); // double: 6.1
bool2 = push(arr1, false); // bool: false
arr2 = push(arr1, [ 8 ]); // array: [ 8 ]
int2 = push(arr1, 9); // int: 9
obj2 = push(arr1, { 'last': 10 }); // object: { "last": 10 }
print(arr1); // [ 1, 2, "three", "four", 5.09, 6.1, false, [ 8 ], 9, { "last": 10 } ]
reverse(arr_or_str)   Reverse the order of the given input array or string arr1 = [1, 2, 3]; // array: [ 1, 2, 3 ]
arr2 = reverse(arr1); // array: [ 3, 2, 1 ]
str1 = 'Abc'; // string: "Abc"
str2 = reverse(str1); // string: "cbA"
rindex(arr_or_str, needle)   Finds the given value passed as the second argument within the array or string specified in the first argument str1 = 'Hello hello hello'; // string: "Hello hello hello"
str2 = 'll'; // string: "ll"
rindex(str1, str2);

arr3 = [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]; // array: [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
int3 = 2; // int: 2
rindex(arr3, int3);
shift(arr)   Pops the first item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = shift(arr1); // int: 1
print(arr1); // [ 2, 3 ]

arr2 = [ 1, 'two', 3.09, false, [ 5, 6 ], { 'last': 7 } ]; // array: [ 1, "two", 3.09, false, [ 5, 6 ], { "last": 7 } ]
int2 = shift(arr2); // int: 1
str2 = shift(arr2); // string: "two"
dbl3 = shift(arr2); // double: 3.09
bool3 = shift(arr2); // bool: false
arr3 = shift(arr2); // array: [ 5, 6 ]
obj3 = shift(arr2); // object: { "last": 7 }
print(arr2); // [ ]
slice(arr, off, end)   Performs a shallow copy of a portion of the array, as specified by the off and end. The original array is not modified arr1 = [1, 2, 3]; // array: [ 1, 2, 3 ]
arr2 = slice(arr1, 1); // array: [ 2, 3 ]

print(slice([1, 2, 3], -3, -1)); // [ 1, 2 ]
sort(arr, fn)   Sort the array according to the sort function. If no function is provided, a default ascending sort order is applied arr1 = [8, 1, 5, 9]; // array: [ 8, 1, 5, 9 ]
arr2 = sort(arr1); // array: [ 1, 5, 8, 9 ]

print(sort(['Bean', 'Orange', 'Apple'], function(a, b) {return length(a) - length(b);})); // [ "Bean", "Apple", "Orange" ]
splice(arr, off, len, …elements)   Replaces the array elements specified by off & len with the additional arguments passed, if any arr1 = [ 1, 2, 3, 4 ]; // array: [ 1, 2, 3, 4 ]
arr2 = splice(arr1, 1, 2, 'a', 'b', 'c'); // array: [ 1, "a", "b", "c", 4 ]
split(str, sep, limit)   Split the string using the separator and return an array containing the resulting pieces str1 = 'foo,bar,baz'; // string: "foo,bar,baz"
arr1 = split(str1, ','); // array: [ "foo", "bar", "baz" ]

print(split('foobar', '')); // [ "f", "o", "o", "b", "a", "r" ]

rex2 = regexp('[ao]'); // regexp: /[ao]/
arr2 = split('foo,bar,baz', rex2); // array: [ "f", "", ",b", "r,b", "z" ]

print(split('foo=bar=baz', '=', 2)); // [ "foo", "bar=baz" ]
sprintf(fmt, …Arguments)   Formats the given arguments according to the given format string str1 = 'world'; // string: "world"
str2 = sprintf('Hello %s', str1); // string: "Hello world"

str3 = sprintf('%08x', 123); // string: "0000007b"
str4 = sprintf('%g', 10 / 3.0); // string: "3.33333"
str5 = sprintf('%2$d %1$d', 12, 34); // string: "34 12"
str6 = sprintf('%.2J', [ 1, 2, 3 ]); // string: "[ 1, 2, 3 ]"
str7 = sprintf('%.2J', { 'A': 1, 'B': 2, 'C': 3 }); // string: "{ "A": 1, "B": 2, "C": 3 }"
str8 = sprintf(33 > 22); // string: ""
uniq(array)   Returns a new array containing all unique values of the given input array arr1 = [1, true, 'foo', 2, true, 'bar', 'foo']; // array: [ 1, true, "foo", 2, true, "bar", "foo" ]
arr2 = uniq(arr1); // array: [ 1, true, "foo", 2, "bar" ]
unshift(arr, …Values)   Add the given values to the beginning of the array passed via first argument arr1 = [ 3, 4, 5 ]; // array: [ 3, 4, 5 ]
print(unshift(arr1, 1, 2)); // 2
print(arr1); // [ 1, 2, 3, 4, 5 ]

arr2 = [ 9, 10 ]; // array: [ 9, 10 ]
str3 = unshift(arr2, 'seven', 'eight'); // string: "eight"
dbl3 = unshift(arr2, 5.09, 6.1); // double: 6.1
bool3 = unshift(arr2, false); // bool: false
arr3 = unshift(arr2, [ 3 ]); // array: [ 3 ]
int3 = unshift(arr2, 2); // int: 2
obj3 = unshift(arr2, { 'first': 1 }); // object: { "first": 1 }
print(arr2); // [ { "first": 1 }, 2, [ 3 ], false, 5.09, 6.1, "seven", "eight", 9, 10 ]
values(obj)   Returns an array containing all values of the given object obj1 = { foo: true, bar: false }; // object: { "foo": true, "bar": false }
arr1 = values(obj1); // array: [ true, false ]

string

SCRIPT_NAME   The script path and name is passed in string SCRIPT_NAME, and also returned by sourcepath() print(SCRIPT_NAME); // './test_script'
print(sourcepath()); // '/root/test_script'
print(sourcepath(0)); // '/root/test_script'
print(sourcepath(0, false)); // '/root/test_script'
print(sourcepath(0, true)); // '/root'
arrtoip(arr)   Convert the given input array of byte values to an IP address string arr1 = [ 192, 168, 1, 1 ]; // array: [ 192, 168, 1, 1 ]
str1 = arrtoip(arr1); // string: "192.168.1.1"

arr2 = [ 254, 128, 0, 0, 0, 0, 0, 0, 252, 84, 0, 255, 254, 130, 171, 189 ]; // array: [ 254, 128, 0, 0, 0, 0, 0, 0, 252, 84, 0, 255, 254, 130, 171, 189 ]
str2 = arrtoip(arr2); // string: "fe80::fc54:ff:fe82:abbd"
assert(cond, message)   Raise an exception with the given message parameter when the value in cond is not truish assert(true, 'This is true'); // No exception is raised
assert(false); // Exception is raised with the default message 'Assertion failed'
b64dec(str)   Decodes the given base64 encoded string and returns the decoded result str1 = 'VGhpcyBpcyBhIHRlc3Q='; // string: "VGhpcyBpcyBhIHRlc3Q="
srt2 = b64dec(str1); // string: "This is a test"
b64enc(str)   Encodes the given string into base64 and returns the resulting string str1 = 'This is a test'; // string: "This is a test"
str2 = b64enc(str1); // string: "VGhpcyBpcyBhIHRlc3Q="
chr(…n1)   Converts each given numeric value to a byte and return the resulting string. If value < 0 => \0, f value > 255 => 255 str1 = chr(65, 98, 99); // string: "Abc"
 
getenv(name)   Query an environment variable or then entire environment obj1 = getenv(); // object: { "USER": "root", "SSH_CLIENT": "192.168.1.172 50802 22", "SHLVL": "2", "HOME": "/root", "OLDPWD": "/root", "SSH_TTY": "/dev/pts/0", "PS1": "\\[\\e]0;\\u@\\h: \\w\\a\\]\\u@\\h:\\w\\$ ", "ENV": "/etc/shinit", "LOGNAME": "root", "TERM": "xterm-256color", "PATH": "/usr/sbin:/usr/bin:/sbin:/bin", "SHELL": "/bin/ash", "PWD": "/root/ucode", "SSH_CONNECTION": "192.168.1.172 50802 192.168.1.1 22" }
str1 = keys(obj1)[0]; // string: "USER"
str2 = getenv(str1); // string: "root"
hex(x)   Converts the given hexadecimal string into a number str1 = 'FE38'; // string: "FE38"
int = hex(str1); // int: 65080
hexdec(hexstring, skipchars)   Decodes the given hexadecimal digit string into a byte string, optionally skipping specified characters str1 = '48656c6c6f20776f726c6421'; // string: "48656c6c6f20776f726c6421"
str2 = hexdec(str1); // string: "Hello world!"

str3 = '44:55:66:77:33:44'; // string: "44:55:66:77:33:44"
str4 = hexdec(str3, ':'); // string: "DUfw3D"
hexenc(val)   Encodes the given byte string into a hexadecimal digit string, converting the input value to a string if needed str1 = 'Hello world!'; // string: "Hello world!"
str2 = hexenc(str1); // string: "48656c6c6f20776f726c6421"
index(arr_or_str, needle)   Finds the given value passed as the second argument within the array or string specified in the first argument str1 = 'Hello hello hello'; // string: "Hello hello hello"
int1 = index(str1, 'll'); // int: 2

arr2 = [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]; // array: [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
int2 = index(arr2, 2); // int: 1

arr3 = ['Red', 'Blue', 'Green']; // array: [ "Red", "Blue", "Green" ]
int3 = index(arr3, 'Brown'); // int: -1
int(x, base)   Converts the given value to an integer, using an optional base str1 = '123'; // string: "123"
int1 = int(str1); // int: 123

int2 = int('10 or more'); // int: 10
int3 = int('12.9'); // int: 12
int4 = int(987.654); // int: 987
str5 = '101010'; // string: "101010"
int5 = int(str5, 2); // int: 42
iptoarr(address)   Convert the given IP address string to an array of byte values str1 = '192.168.1.1'; // string: "192.168.1.1"
arr1 = iptoarr(str1); // array: [ 192, 168, 1, 1 ]

str2 = 'fe80::fc54:ff:fe82:abbd'; // string: "fe80::fc54:ff:fe82:abbd"
arr2 = iptoarr(str2); // array: [ 254, 128, 0, 0, 0, 0, 0, 0, 252, 84, 0, 255, 254, 130, 171, 189 ]
join(sep, arr)   Joins the array passed as the second argument into a string, using the separator passed in the first argument as glue arr1 = [ 'aa', 'BB', 'cc' ]; // array: [ "aa", "BB", "cc" ]
str1 = join(':', arr1); // string: "aa:BB:cc"
json(str_or_resource)   Parse the given string or resource as JSON and return the resulting value str1 = '{ "a":true, "b":123 }';
obj1 = json(str1);

import { open } from 'fs';
fd = open('example.json', 'r');
// will keep invoking fd.read() until EOF and incrementally parse each read chunk
obj2 = json(fd);

arr3 = proto(['{"foo":', 'true, ', '"bar":', 'false}'], {read: function() {return shift(this)}});
obj3 = json(arr3);
lc(s)   Convert the given string to lowercase and return the resulting string str1 = 'HeLLo WoRLd!'; // string: "HeLLo WoRLd!"
str2 = lc(srt1); // string: "null"
length(x)   Determine the length of the given object, array or string str1 = 'test'; // string: "test"
int1 = length(str1); // int: 4

arr2 = [true, false, null, 123, 'test']; // array: [ true, false, null, 123, "test" ]
int2 = length(arr2); // int: 5

obj3 = {foo: true, bar: 123, baz: 'test'}; // object: { "foo": true, "bar": 123, "baz": "test" }
int3 = length(obj3); // int: 3
loadfile(path, options)   Compiles the given file into a ucode program and returns the resulting program entry function loadfile('./templates/example.uc'); // function main() { ... }
 
loadstring(code, options)   Compiles the given code string into a ucode program and returns the resulting program entry function fn1 = loadstring('Hello, {{ name }}', { raw_mode: false });

global.name = 'Alice';
fn1(); // prints `Hello, Alice`

fn2 = loadstring('return 1 + 2;', { raw_mode: true });
fn2(); // 3
ltrim(s, c)   Trim any of the specified characters from the start of the string. If the 2nd argument is omitted, trims ' ', '\t', '\r', '\n' str1 = ' foo '; // string: " foo "
str2 = ltrim(str1); // string: "foo "

str3 = '--bar--'; // string: "--bar--"
str4 = ltrim(str3, '-'); // string: "bar--"
match(str, pattern)   Match the given string against the regular expression pattern specified as the second argument rex1 = regexp('b.(.)'); // regexp: /b.(.)/
str1 = 'foobarbaz'; // string: "foobarbaz"
arr1 = match(str1, rex1); // array: [ "bar", "r" ]

arr2 = match('foobarbaz', /b.(.)/g); // array: [ [ "bar", "r" ], [ "baz", "z" ] ]
max(…val)   Return the largest value among all parameters passed to the function int1 = max(5, 2.1, 6.3, 0.3); // double: 6.3
int2 = max(1, 'abc'); // int: 1
str3 = max('def', 'abc', 'ghi'); // string: "ghi"
min(…val)   Return the smallest value among all parameters passed to the function int1 = min(5, 2.1, 6.3, 0.3); // double: 0.3
int2 = min(1, 'abc'); // int: 1
str3 = min('def', 'abc', 'ghi'); // string: "abc"
ord(s, offset)   Returns the byte value of a character in the given string str1 = 'Abc'; // string: "Abc"
int1 = ord(str1); // int: 65

int2 = ord(str1, 2); // int: 99
pop(arr)   Pops the last item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = pop(arr1); // int: 3
print(arr1); // [ 1, 2 ]

arr2 = [ 1, 2, 'three', 4.09, false, [ 6, 7 ], { 'last': 7 } ]; // array: [ 1, 2, "three", 4.09, false, [ 6, 7 ], { "last": 7 } ]
obj3 = pop(arr2); // object: { "last": 7 }
arr3 = pop(arr2); // array: [ 6, 7 ]
bool3 = pop(arr2); // bool: false
dbl3 = pop(arr2); // double: 4.09
str3 = pop(arr2); // string: "three"
int3 = pop(arr2); // int: 2
print(arr2); // [ 1 ]
print(…values)   Print any of the given values to stdout str1 = 'Hello'; // string: "Hello"
print(str1, ' world!'); // Hello world!

arr2 = [ 1, 'B', 3 ]; // array: [ 1, "B", 3 ]
print(arr2); // [ 1, "B", 3 ]

obj3 = { hello: true, world: 123 }; // object: { "hello": true, "world": 123 }
print(obj3); // { "hello": true, "world": 123 }

print(10 / 3.0); // 3.3333333333333
print(1 != 2); // true
print(0xff); // 255

print(proto({foo: 'bar'}, {tostring: () => 'MyObj'})); // MyObj
printf(fmt, …Arguments)   Formats the given arguments according to the given format string and outputs the result to stdout str1 = 'Hello'; // string: "Hello"
printf('%s world', str1); // Hello world

int2 = 123; // int: 123
printf('%08x', int2); // 0000007b

printf('%g', 10 / 3.0); // 3.33333
printf('%2$d %1$d', 12, 34); // 34 12

printf('%J', [1,2,3]); // [ 1, 2, 3 ]
printf('%.2J', [1,2,3]); // [ 1, 2, 3 ]

printf('%J', {'c': 1, 'b': 2, 'a': 3}); // { "c": 1, "b": 2, "a": 3 }
printf('%s', 32 < 10); // false
push(arr, …values)   Pushes the given argument(s) to the given array arr1 = [ 1, 2 ]; // array: [ 1, 2 ]
str2 = push(arr1, 'three', 'four'); // string: "four"
dbl2 = push(arr1, 5.09, 6.1); // double: 6.1
bool2 = push(arr1, false); // bool: false
arr2 = push(arr1, [ 8 ]); // array: [ 8 ]
int2 = push(arr1, 9); // int: 9
obj2 = push(arr1, { 'last': 10 }); // object: { "last": 10 }
print(arr1); // [ 1, 2, "three", "four", 5.09, 6.1, false, [ 8 ], 9, { "last": 10 } ]
regexp(source, flags)   Construct a regular expression instance from the source string and any flags optionally given // Supported flags are: 'g', 'i', 's'
str1 = 'is'; // string: "is"
rex1 = regexp('foo.*bar', str1); // regexp: /foo.*bar/is
replace(str, pattern, replace, limit)   Replace occurrences of the specified pattern in the string passed as the first argument replace('barfoobaz', 'a', 'X'); // string: "bXrfoobXz"

str1 = 'barfoobaz'; // string: "barfoobaz"
rex1 = regexp('(f)(o+)', 'g'); // regexp: /(f)(o+)/g
str2 = '[$$|$`|$&|$1|$2|$3]'; // string: "[$$|$`|$&|$1|$2|$3]"
replace(str1, rex1, str2); // string: "bar[$|bar|foo|f|oo|$3]baz"

replace('barfoobaz', /(f)(o+)/g, uc); // string: "barFOObaz"

replace('foo bar baz', /[ao]/g, 'x', 3); // string: "fxx bxr baz"
reverse(arr_or_str)   Reverse the order of the given input array or string arr1 = [1, 2, 3]; // array: [ 1, 2, 3 ]
arr2 = reverse(arr1); // array: [ 3, 2, 1 ]
str1 = 'Abc'; // string: "Abc"
str2 = reverse(str1); // string: "cbA"
rindex(arr_or_str, needle)   Finds the given value passed as the second argument within the array or string specified in the first argument str1 = 'Hello hello hello'; // string: "Hello hello hello"
str2 = 'll'; // string: "ll"
rindex(str1, str2);

arr3 = [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]; // array: [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
int3 = 2; // int: 2
rindex(arr3, int3);
rtrim(str, c)   Trim any of the specified characters from the end of the string. If the 2nd argument is omitted, trims ' ', '\t', '\r', '\n' str1 = ' foo '; // string: " foo "
str2 = rtrim(str1); // string: " foo"

print(rtrim('--bar--', '-')); // --bar
shift(arr)   Pops the first item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = shift(arr1); // int: 1
print(arr1); // [ 2, 3 ]

arr2 = [ 1, 'two', 3.09, false, [ 5, 6 ], { 'last': 7 } ]; // array: [ 1, "two", 3.09, false, [ 5, 6 ], { "last": 7 } ]
int2 = shift(arr2); // int: 1
str2 = shift(arr2); // string: "two"
dbl3 = shift(arr2); // double: 3.09
bool3 = shift(arr2); // bool: false
arr3 = shift(arr2); // array: [ 5, 6 ]
obj3 = shift(arr2); // object: { "last": 7 }
print(arr2); // [ ]
sourcepath(depth, dironly)   Determine the path of the source file currently being executed by ucode sourcepath(); // the path of the currently executed file
sourcepath(1); // the path of the parent source file
sourcepath(2, true); // the directory portion of the grandparent source file path
split(str, sep, limit)   Split the string using the separator and return an array containing the resulting pieces str1 = 'foo,bar,baz'; // string: "foo,bar,baz"
arr1 = split(str1, ','); // array: [ "foo", "bar", "baz" ]

print(split('foobar', '')); // [ "f", "o", "o", "b", "a", "r" ]

rex2 = regexp('[ao]'); // regexp: /[ao]/
arr2 = split('foo,bar,baz', rex2); // array: [ "f", "", ",b", "r,b", "z" ]

print(split('foo=bar=baz', '=', 2)); // [ "foo", "bar=baz" ]
sprintf(fmt, …Arguments)   Formats the given arguments according to the given format string str1 = 'world'; // string: "world"
str2 = sprintf('Hello %s', str1); // string: "Hello world"

str3 = sprintf('%08x', 123); // string: "0000007b"
str4 = sprintf('%g', 10 / 3.0); // string: "3.33333"
str5 = sprintf('%2$d %1$d', 12, 34); // string: "34 12"
str6 = sprintf('%.2J', [ 1, 2, 3 ]); // string: "[ 1, 2, 3 ]"
str7 = sprintf('%.2J', { 'A': 1, 'B': 2, 'C': 3 }); // string: "{ "A": 1, "B": 2, "C": 3 }"
str8 = sprintf(33 > 22); // string: ""
substr(str, off, len)   Extracts a substring out of str and returns it. First character is at offset zero str1 = 'The black cat climbed the green tree'; // string: "The black cat climbed the green tree"
str2 = substr(str1, 4, 5); // string: "black"
str3 = substr(str1, -4, 2); // string: "tr"
trim(str, c)   Trim any of the specified characters in c from the start and end of str. If the 2nd argument is omitted, trims ' ', '\t', '\r', '\n' str1 = ' foo '; // string: " foo "
str2 = trim(str1); // string: "foo"

str3 = '--bar--'; // string: "--bar--"
str4 = trim(str3, '-'); // string: "bar"
type(x)   Query the type of the given value str1 = type('cat'); // string: "string"
str2 = type(321); // string: "int"
str3 = type(54.321); // string: "double"
str4 = type([1, 2]); // string: "array"
str5 = type({ 'a': 1, 'b': 2 }); // string: "object"
str6 = type(43 < 21); // string: "bool"
str7 = type(/[b]/i); // string: "regexp"
uc(str)   Converts the given string to uppercase and returns the resulting string str1 = uc('hello'); // string: "HELLO"
 
uchr(…Numeric)   Converts each given numeric value to an UTF-8 multibyte sequence and returns the resulting string str1 = uchr(0x2600, 0x26C6, 0x2601); // string: "☀⛆☁"
 
unshift(arr, …Values)   Add the given values to the beginning of the array passed via first argument arr1 = [ 3, 4, 5 ]; // array: [ 3, 4, 5 ]
print(unshift(arr1, 1, 2)); // 2
print(arr1); // [ 1, 2, 3, 4, 5 ]

arr2 = [ 9, 10 ]; // array: [ 9, 10 ]
str3 = unshift(arr2, 'seven', 'eight'); // string: "eight"
dbl3 = unshift(arr2, 5.09, 6.1); // double: 6.1
bool3 = unshift(arr2, false); // bool: false
arr3 = unshift(arr2, [ 3 ]); // array: [ 3 ]
int3 = unshift(arr2, 2); // int: 2
obj3 = unshift(arr2, { 'first': 1 }); // object: { "first": 1 }
print(arr2); // [ { "first": 1 }, 2, [ 3 ], false, 5.09, 6.1, "seven", "eight", 9, 10 ]
wildcard(subject, pattern, nocase)   Match the given subject against the supplied wildcard (file glob) pattern str1 = 'file.txt'; // string: "file.txt"
bool1 = wildcard(str1, '*.txt'); // bool: true
bool2 = wildcard(str1, '*.TXT', true); // bool: true
bool3 = wildcard(str1, '*.jpg'); // bool: false

function

call(fn, ctx, scope, …arg)   Calls the given function value with a modified environment // Override this context
call(function() { printf('%J', this) }, { x: 1 }); // { 'x': 1 }
call(function() { printf('%J', this) }, { x: 2 }); // { 'x': 2 }

// Run with default scope
global.a = 1;
call(function() { printf('%J', a) }); // 1

// Override scope, inherit from current global scope (implicit)
call(function() { printf('%J', a) }, null, { a: 2 }); // 2

// Override scope, inherit from current global scope (explicit)
call(function() { printf('%J', a) }, null,
proto({ a: 2 }, global)); // 2

// Override scope, don't inherit (pass `printf()` but not `a`)
call(function() { printf('%J', a) }, null,
proto({}, { printf })); // null

// Forward arguments
x = call((x, y, z) => x * y * z, null, null, 2, 3, 4); // x = 24
filter(arr, fn)   Filter the array passed as the first argument by invoking the function specified in the second argument for each array item arr1 = ['foo', '', 'bar', '', 'baz']; // array: [ "foo", "", "bar", "", "baz" ]
arr2 = filter(arr1, length); // array: [ "foo", "bar", "baz" ]

arr3 = ['foo', 1, true, null, 2.2]; // array: [ "foo", 1, true, null, 2.2 ]
arr4 = filter(arr3, function(v) {return (type(v) == 'int' || type(v) == 'double');}); // array: [ 1, 2.2 ]
loadfile(path, options)   Compiles the given file into a ucode program and returns the resulting program entry function loadfile('./templates/example.uc'); // function main() { ... }
 
loadstring(code, options)   Compiles the given code string into a ucode program and returns the resulting program entry function fn1 = loadstring('Hello, {{ name }}', { raw_mode: false });

global.name = 'Alice';
fn1(); // prints `Hello, Alice`

fn2 = loadstring('return 1 + 2;', { raw_mode: true });
fn2(); // 3
map(arr, fn)   Transform the array passed as the first argument by invoking the function specified in the second argument for each array item arr1 = ['Apple', 'Banana', 'Bean'];
arr2 = map(arr1, length);

arr3 = ['foo', 1, true, null, 2.2];
arr4 = map(arr3, type);

arr5 = ['22', '1010', '0001', '0101'];
arr6 = map(arr5, (x) => int(x, 2));
render(path_or_func, scope_or_fnarg1, …fnargN)   Execute included ucode file, or a function, and capture output // Renders template file with given scope and captures the output as a string
output = render('./template.uc', { foo: 'bar' });

// Calls a function, captures the output, and returns it as a string
result = render(function(name) {
printf('Hello, %s! ', name);
}, 'Alice');
replace(str, pattern, replace, limit)   Replace occurrences of the specified pattern in the string passed as the first argument replace('barfoobaz', 'a', 'X'); // string: "bXrfoobXz"

str1 = 'barfoobaz'; // string: "barfoobaz"
rex1 = regexp('(f)(o+)', 'g'); // regexp: /(f)(o+)/g
str2 = '[$$|$`|$&|$1|$2|$3]'; // string: "[$$|$`|$&|$1|$2|$3]"
replace(str1, rex1, str2); // string: "bar[$|bar|foo|f|oo|$3]baz"

replace('barfoobaz', /(f)(o+)/g, uc); // string: "barFOObaz"

replace('foo bar baz', /[ao]/g, 'x', 3); // string: "fxx bxr baz"
signal(signal, handler)   Set or query process signal handler function signal('INT', 'ignore'); // Ignore signal

signal('INT', 'default'); // Restore signal default behavior

// Set custom handler function
function intexit(signo) {printf('I received signal number %d ', signo); exit(1);}
sort(arr, fn)   Sort the array according to the sort function. If no function is provided, a default ascending sort order is applied arr1 = [8, 1, 5, 9]; // array: [ 8, 1, 5, 9 ]
arr2 = sort(arr1); // array: [ 1, 5, 8, 9 ]

print(sort(['Bean', 'Orange', 'Apple'], function(a, b) {return length(a) - length(b);})); // [ "Bean", "Apple", "Orange" ]

object

exists(obj, key)   Check whether the given key exists within the given object value obj1 = { foo: true, bar: false, qrx: null }; // object: { "foo": true, "bar": false, "qrx": null }
str1 = exists(obj1, str1); // bool: false
bool1 = exists(obj1, 'foo'); // bool: true
bool2 = exists(obj1, 'qrx'); // bool: true
bool3 = exists(obj1, 'baz'); // bool: false
getenv(name)   Query an environment variable or then entire environment obj1 = getenv(); // object: { "USER": "root", "SSH_CLIENT": "192.168.1.172 50802 22", "SHLVL": "2", "HOME": "/root", "OLDPWD": "/root", "SSH_TTY": "/dev/pts/0", "PS1": "\\[\\e]0;\\u@\\h: \\w\\a\\]\\u@\\h:\\w\\$ ", "ENV": "/etc/shinit", "LOGNAME": "root", "TERM": "xterm-256color", "PATH": "/usr/sbin:/usr/bin:/sbin:/bin", "SHELL": "/bin/ash", "PWD": "/root/ucode", "SSH_CONNECTION": "192.168.1.172 50802 192.168.1.1 22" }
str1 = keys(obj1)[0]; // string: "USER"
str2 = getenv(str1); // string: "root"
gmtime(epoch)   Like localtime() but interpreting the given epoch value as UTC time int1 = time(); // int: 1774518813
objTime = gmtime(int1);
// object: { 'sec': 33, 'min': 53, 'hour': 9, 'mday': 26, 'mon': 3, 'year': 2026, 'wday': 4, 'yday': 85, 'isdst': 0 }
json(str_or_resource)   Parse the given string or resource as JSON and return the resulting value str1 = '{ "a":true, "b":123 }';
obj1 = json(str1);

import { open } from 'fs';
fd = open('example.json', 'r');
// will keep invoking fd.read() until EOF and incrementally parse each read chunk
obj2 = json(fd);

arr3 = proto(['{"foo":', 'true, ', '"bar":', 'false}'], {read: function() {return shift(this)}});
obj3 = json(arr3);
keys(obj)   Enumerates all object key names obj1 = { 'one': 1, 'two': 2, 'six': 6 }; // object: { "one": 1, "two": 2, "six": 6 }
arr1 = keys(obj1); // array: [ "one", "two", "six" ]
length(x)   Determine the length of the given object, array or string str1 = 'test'; // string: "test"
int1 = length(str1); // int: 4

arr2 = [true, false, null, 123, 'test']; // array: [ true, false, null, 123, "test" ]
int2 = length(arr2); // int: 5

obj3 = {foo: true, bar: 123, baz: 'test'}; // object: { "foo": true, "bar": 123, "baz": "test" }
int3 = length(obj3); // int: 3
localtime(epoch)   Return the given epoch timestamp (or now, if omitted) as a dictionary int1 = time(); // int: 1774602418
obj1 = localtime(int1); // object: { "sec": 58, "min": 6, "hour": 11, "mday": 27, "mon": 3, "year": 2026, "wday": 5, "yday": 86, "isdst": 0 }
pop(arr)   Pops the last item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = pop(arr1); // int: 3
print(arr1); // [ 1, 2 ]

arr2 = [ 1, 2, 'three', 4.09, false, [ 6, 7 ], { 'last': 7 } ]; // array: [ 1, 2, "three", 4.09, false, [ 6, 7 ], { "last": 7 } ]
obj3 = pop(arr2); // object: { "last": 7 }
arr3 = pop(arr2); // array: [ 6, 7 ]
bool3 = pop(arr2); // bool: false
dbl3 = pop(arr2); // double: 4.09
str3 = pop(arr2); // string: "three"
int3 = pop(arr2); // int: 2
print(arr2); // [ 1 ]
print(…values)   Print any of the given values to stdout str1 = 'Hello'; // string: "Hello"
print(str1, ' world!'); // Hello world!

arr2 = [ 1, 'B', 3 ]; // array: [ 1, "B", 3 ]
print(arr2); // [ 1, "B", 3 ]

obj3 = { hello: true, world: 123 }; // object: { "hello": true, "world": 123 }
print(obj3); // { "hello": true, "world": 123 }

print(10 / 3.0); // 3.3333333333333
print(1 != 2); // true
print(0xff); // 255

print(proto({foo: 'bar'}, {tostring: () => 'MyObj'})); // MyObj
printf(fmt, …Arguments)   Formats the given arguments according to the given format string and outputs the result to stdout str1 = 'Hello'; // string: "Hello"
printf('%s world', str1); // Hello world

int2 = 123; // int: 123
printf('%08x', int2); // 0000007b

printf('%g', 10 / 3.0); // 3.33333
printf('%2$d %1$d', 12, 34); // 34 12

printf('%J', [1,2,3]); // [ 1, 2, 3 ]
printf('%.2J', [1,2,3]); // [ 1, 2, 3 ]

printf('%J', {'c': 1, 'b': 2, 'a': 3}); // { "c": 1, "b": 2, "a": 3 }
printf('%s', 32 < 10); // false
proto(val, proto)   Get or set the prototype of the array or object value val arr1 = [1, 2, 3];
obj1 = proto(arr1);
arr2 = proto(arr1, { foo: true });
obj2 = proto(arr1);
obj3 = proto(arr2);
push(arr, …values)   Pushes the given argument(s) to the given array arr1 = [ 1, 2 ]; // array: [ 1, 2 ]
str2 = push(arr1, 'three', 'four'); // string: "four"
dbl2 = push(arr1, 5.09, 6.1); // double: 6.1
bool2 = push(arr1, false); // bool: false
arr2 = push(arr1, [ 8 ]); // array: [ 8 ]
int2 = push(arr1, 9); // int: 9
obj2 = push(arr1, { 'last': 10 }); // object: { "last": 10 }
print(arr1); // [ 1, 2, "three", "four", 5.09, 6.1, false, [ 8 ], 9, { "last": 10 } ]
shift(arr)   Pops the first item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = shift(arr1); // int: 1
print(arr1); // [ 2, 3 ]

arr2 = [ 1, 'two', 3.09, false, [ 5, 6 ], { 'last': 7 } ]; // array: [ 1, "two", 3.09, false, [ 5, 6 ], { "last": 7 } ]
int2 = shift(arr2); // int: 1
str2 = shift(arr2); // string: "two"
dbl3 = shift(arr2); // double: 3.09
bool3 = shift(arr2); // bool: false
arr3 = shift(arr2); // array: [ 5, 6 ]
obj3 = shift(arr2); // object: { "last": 7 }
print(arr2); // [ ]
sprintf(fmt, …Arguments)   Formats the given arguments according to the given format string str1 = 'world'; // string: "world"
str2 = sprintf('Hello %s', str1); // string: "Hello world"

str3 = sprintf('%08x', 123); // string: "0000007b"
str4 = sprintf('%g', 10 / 3.0); // string: "3.33333"
str5 = sprintf('%2$d %1$d', 12, 34); // string: "34 12"
str6 = sprintf('%.2J', [ 1, 2, 3 ]); // string: "[ 1, 2, 3 ]"
str7 = sprintf('%.2J', { 'A': 1, 'B': 2, 'C': 3 }); // string: "{ "A": 1, "B": 2, "C": 3 }"
str8 = sprintf(33 > 22); // string: ""
timegm(datetimespec)   Like timelocal() but interpreting the given date time specification as UTC time obj1 = { 'sec': 42, 'min': 51, 'hour': 13, 'mday': 22, 'mon': 3, 'year': 2022, 'isdst': 0 }; // object: { "sec": 42, "min": 51, "hour": 13, "mday": 22, "mon": 3, "year": 2022, "isdst": 0 }
int1 = timegm(obj1); // int: 1647957102
timelocal(datetimespec)   Transforms a broken-down date & time dictionary into an epoch value according to the local system timezone obj1 = { 'sec': 42, 'min': 51, 'hour': 13, 'mday': 22, 'mon': 3, 'year': 2022, 'isdst': 0 }; // object: { "sec": 42, "min": 51, "hour": 13, "mday": 22, "mon": 3, "year": 2022, "isdst": 0 }
int1 = timelocal(obj1); // int: 1647949902
unshift(arr, …Values)   Add the given values to the beginning of the array passed via first argument arr1 = [ 3, 4, 5 ]; // array: [ 3, 4, 5 ]
print(unshift(arr1, 1, 2)); // 2
print(arr1); // [ 1, 2, 3, 4, 5 ]

arr2 = [ 9, 10 ]; // array: [ 9, 10 ]
str3 = unshift(arr2, 'seven', 'eight'); // string: "eight"
dbl3 = unshift(arr2, 5.09, 6.1); // double: 6.1
bool3 = unshift(arr2, false); // bool: false
arr3 = unshift(arr2, [ 3 ]); // array: [ 3 ]
int3 = unshift(arr2, 2); // int: 2
obj3 = unshift(arr2, { 'first': 1 }); // object: { "first": 1 }
print(arr2); // [ { "first": 1 }, 2, [ 3 ], false, 5.09, 6.1, "seven", "eight", 9, 10 ]
values(obj)   Returns an array containing all values of the given object obj1 = { foo: true, bar: false }; // object: { "foo": true, "bar": false }
arr1 = values(obj1); // array: [ true, false ]

bool

exists(obj, key)   Check whether the given key exists within the given object value obj1 = { foo: true, bar: false, qrx: null }; // object: { "foo": true, "bar": false, "qrx": null }
str1 = exists(obj1, str1); // bool: false
bool1 = exists(obj1, 'foo'); // bool: true
bool2 = exists(obj1, 'qrx'); // bool: true
bool3 = exists(obj1, 'baz'); // bool: false
pop(arr)   Pops the last item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = pop(arr1); // int: 3
print(arr1); // [ 1, 2 ]

arr2 = [ 1, 2, 'three', 4.09, false, [ 6, 7 ], { 'last': 7 } ]; // array: [ 1, 2, "three", 4.09, false, [ 6, 7 ], { "last": 7 } ]
obj3 = pop(arr2); // object: { "last": 7 }
arr3 = pop(arr2); // array: [ 6, 7 ]
bool3 = pop(arr2); // bool: false
dbl3 = pop(arr2); // double: 4.09
str3 = pop(arr2); // string: "three"
int3 = pop(arr2); // int: 2
print(arr2); // [ 1 ]
print(…values)   Print any of the given values to stdout str1 = 'Hello'; // string: "Hello"
print(str1, ' world!'); // Hello world!

arr2 = [ 1, 'B', 3 ]; // array: [ 1, "B", 3 ]
print(arr2); // [ 1, "B", 3 ]

obj3 = { hello: true, world: 123 }; // object: { "hello": true, "world": 123 }
print(obj3); // { "hello": true, "world": 123 }

print(10 / 3.0); // 3.3333333333333
print(1 != 2); // true
print(0xff); // 255

print(proto({foo: 'bar'}, {tostring: () => 'MyObj'})); // MyObj
printf(fmt, …Arguments)   Formats the given arguments according to the given format string and outputs the result to stdout str1 = 'Hello'; // string: "Hello"
printf('%s world', str1); // Hello world

int2 = 123; // int: 123
printf('%08x', int2); // 0000007b

printf('%g', 10 / 3.0); // 3.33333
printf('%2$d %1$d', 12, 34); // 34 12

printf('%J', [1,2,3]); // [ 1, 2, 3 ]
printf('%.2J', [1,2,3]); // [ 1, 2, 3 ]

printf('%J', {'c': 1, 'b': 2, 'a': 3}); // { "c": 1, "b": 2, "a": 3 }
printf('%s', 32 < 10); // false
push(arr, …values)   Pushes the given argument(s) to the given array arr1 = [ 1, 2 ]; // array: [ 1, 2 ]
str2 = push(arr1, 'three', 'four'); // string: "four"
dbl2 = push(arr1, 5.09, 6.1); // double: 6.1
bool2 = push(arr1, false); // bool: false
arr2 = push(arr1, [ 8 ]); // array: [ 8 ]
int2 = push(arr1, 9); // int: 9
obj2 = push(arr1, { 'last': 10 }); // object: { "last": 10 }
print(arr1); // [ 1, 2, "three", "four", 5.09, 6.1, false, [ 8 ], 9, { "last": 10 } ]
shift(arr)   Pops the first item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = shift(arr1); // int: 1
print(arr1); // [ 2, 3 ]

arr2 = [ 1, 'two', 3.09, false, [ 5, 6 ], { 'last': 7 } ]; // array: [ 1, "two", 3.09, false, [ 5, 6 ], { "last": 7 } ]
int2 = shift(arr2); // int: 1
str2 = shift(arr2); // string: "two"
dbl3 = shift(arr2); // double: 3.09
bool3 = shift(arr2); // bool: false
arr3 = shift(arr2); // array: [ 5, 6 ]
obj3 = shift(arr2); // object: { "last": 7 }
print(arr2); // [ ]
sleep(milliseconds)   Pause execution for the given amount of milliseconds // Sleep for 1 second
bool1 = sleep(1000); // bool: true
sprintf(fmt, …Arguments)   Formats the given arguments according to the given format string str1 = 'world'; // string: "world"
str2 = sprintf('Hello %s', str1); // string: "Hello world"

str3 = sprintf('%08x', 123); // string: "0000007b"
str4 = sprintf('%g', 10 / 3.0); // string: "3.33333"
str5 = sprintf('%2$d %1$d', 12, 34); // string: "34 12"
str6 = sprintf('%.2J', [ 1, 2, 3 ]); // string: "[ 1, 2, 3 ]"
str7 = sprintf('%.2J', { 'A': 1, 'B': 2, 'C': 3 }); // string: "{ "A": 1, "B": 2, "C": 3 }"
str8 = sprintf(33 > 22); // string: ""
unshift(arr, …Values)   Add the given values to the beginning of the array passed via first argument arr1 = [ 3, 4, 5 ]; // array: [ 3, 4, 5 ]
print(unshift(arr1, 1, 2)); // 2
print(arr1); // [ 1, 2, 3, 4, 5 ]

arr2 = [ 9, 10 ]; // array: [ 9, 10 ]
str3 = unshift(arr2, 'seven', 'eight'); // string: "eight"
dbl3 = unshift(arr2, 5.09, 6.1); // double: 6.1
bool3 = unshift(arr2, false); // bool: false
arr3 = unshift(arr2, [ 3 ]); // array: [ 3 ]
int3 = unshift(arr2, 2); // int: 2
obj3 = unshift(arr2, { 'first': 1 }); // object: { "first": 1 }
print(arr2); // [ { "first": 1 }, 2, [ 3 ], false, 5.09, 6.1, "seven", "eight", 9, 10 ]
wildcard(subject, pattern, nocase)   Match the given subject against the supplied wildcard (file glob) pattern str1 = 'file.txt'; // string: "file.txt"
bool1 = wildcard(str1, '*.txt'); // bool: true
bool2 = wildcard(str1, '*.TXT', true); // bool: true
bool3 = wildcard(str1, '*.jpg'); // bool: false

time

gmtime(epoch)   Like localtime() but interpreting the given epoch value as UTC time int1 = time(); // int: 1774518813
objTime = gmtime(int1);
// object: { 'sec': 33, 'min': 53, 'hour': 9, 'mday': 26, 'mon': 3, 'year': 2026, 'wday': 4, 'yday': 85, 'isdst': 0 }
localtime(epoch)   Return the given epoch timestamp (or now, if omitted) as a dictionary int1 = time(); // int: 1774602418
obj1 = localtime(int1); // object: { "sec": 58, "min": 6, "hour": 11, "mday": 27, "mon": 3, "year": 2026, "wday": 5, "yday": 86, "isdst": 0 }
time()   Returns the current UNIX epoch int1 = time(); // int: 1774602423
 
timegm(datetimespec)   Like timelocal() but interpreting the given date time specification as UTC time obj1 = { 'sec': 42, 'min': 51, 'hour': 13, 'mday': 22, 'mon': 3, 'year': 2022, 'isdst': 0 }; // object: { "sec": 42, "min": 51, "hour": 13, "mday": 22, "mon": 3, "year": 2022, "isdst": 0 }
int1 = timegm(obj1); // int: 1647957102
timelocal(datetimespec)   Transforms a broken-down date & time dictionary into an epoch value according to the local system timezone obj1 = { 'sec': 42, 'min': 51, 'hour': 13, 'mday': 22, 'mon': 3, 'year': 2022, 'isdst': 0 }; // object: { "sec": 42, "min": 51, "hour": 13, "mday": 22, "mon": 3, "year": 2022, "isdst": 0 }
int1 = timelocal(obj1); // int: 1647949902

int

hex(x)   Converts the given hexadecimal string into a number str1 = 'FE38'; // string: "FE38"
int = hex(str1); // int: 65080
index(arr_or_str, needle)   Finds the given value passed as the second argument within the array or string specified in the first argument str1 = 'Hello hello hello'; // string: "Hello hello hello"
int1 = index(str1, 'll'); // int: 2

arr2 = [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]; // array: [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
int2 = index(arr2, 2); // int: 1

arr3 = ['Red', 'Blue', 'Green']; // array: [ "Red", "Blue", "Green" ]
int3 = index(arr3, 'Brown'); // int: -1
int(x, base)   Converts the given value to an integer, using an optional base str1 = '123'; // string: "123"
int1 = int(str1); // int: 123

int2 = int('10 or more'); // int: 10
int3 = int('12.9'); // int: 12
int4 = int(987.654); // int: 987
str5 = '101010'; // string: "101010"
int5 = int(str5, 2); // int: 42
length(x)   Determine the length of the given object, array or string str1 = 'test'; // string: "test"
int1 = length(str1); // int: 4

arr2 = [true, false, null, 123, 'test']; // array: [ true, false, null, 123, "test" ]
int2 = length(arr2); // int: 5

obj3 = {foo: true, bar: 123, baz: 'test'}; // object: { "foo": true, "bar": 123, "baz": "test" }
int3 = length(obj3); // int: 3
localtime(epoch)   Return the given epoch timestamp (or now, if omitted) as a dictionary int1 = time(); // int: 1774602418
obj1 = localtime(int1); // object: { "sec": 58, "min": 6, "hour": 11, "mday": 27, "mon": 3, "year": 2026, "wday": 5, "yday": 86, "isdst": 0 }
max(…val)   Return the largest value among all parameters passed to the function int1 = max(5, 2.1, 6.3, 0.3); // double: 6.3
int2 = max(1, 'abc'); // int: 1
str3 = max('def', 'abc', 'ghi'); // string: "ghi"
min(…val)   Return the smallest value among all parameters passed to the function int1 = min(5, 2.1, 6.3, 0.3); // double: 0.3
int2 = min(1, 'abc'); // int: 1
str3 = min('def', 'abc', 'ghi'); // string: "abc"
ord(s, offset)   Returns the byte value of a character in the given string str1 = 'Abc'; // string: "Abc"
int1 = ord(str1); // int: 65

int2 = ord(str1, 2); // int: 99
pop(arr)   Pops the last item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = pop(arr1); // int: 3
print(arr1); // [ 1, 2 ]

arr2 = [ 1, 2, 'three', 4.09, false, [ 6, 7 ], { 'last': 7 } ]; // array: [ 1, 2, "three", 4.09, false, [ 6, 7 ], { "last": 7 } ]
obj3 = pop(arr2); // object: { "last": 7 }
arr3 = pop(arr2); // array: [ 6, 7 ]
bool3 = pop(arr2); // bool: false
dbl3 = pop(arr2); // double: 4.09
str3 = pop(arr2); // string: "three"
int3 = pop(arr2); // int: 2
print(arr2); // [ 1 ]
print(…values)   Print any of the given values to stdout str1 = 'Hello'; // string: "Hello"
print(str1, ' world!'); // Hello world!

arr2 = [ 1, 'B', 3 ]; // array: [ 1, "B", 3 ]
print(arr2); // [ 1, "B", 3 ]

obj3 = { hello: true, world: 123 }; // object: { "hello": true, "world": 123 }
print(obj3); // { "hello": true, "world": 123 }

print(10 / 3.0); // 3.3333333333333
print(1 != 2); // true
print(0xff); // 255

print(proto({foo: 'bar'}, {tostring: () => 'MyObj'})); // MyObj
printf(fmt, …Arguments)   Formats the given arguments according to the given format string and outputs the result to stdout str1 = 'Hello'; // string: "Hello"
printf('%s world', str1); // Hello world

int2 = 123; // int: 123
printf('%08x', int2); // 0000007b

printf('%g', 10 / 3.0); // 3.33333
printf('%2$d %1$d', 12, 34); // 34 12

printf('%J', [1,2,3]); // [ 1, 2, 3 ]
printf('%.2J', [1,2,3]); // [ 1, 2, 3 ]

printf('%J', {'c': 1, 'b': 2, 'a': 3}); // { "c": 1, "b": 2, "a": 3 }
printf('%s', 32 < 10); // false
push(arr, …values)   Pushes the given argument(s) to the given array arr1 = [ 1, 2 ]; // array: [ 1, 2 ]
str2 = push(arr1, 'three', 'four'); // string: "four"
dbl2 = push(arr1, 5.09, 6.1); // double: 6.1
bool2 = push(arr1, false); // bool: false
arr2 = push(arr1, [ 8 ]); // array: [ 8 ]
int2 = push(arr1, 9); // int: 9
obj2 = push(arr1, { 'last': 10 }); // object: { "last": 10 }
print(arr1); // [ 1, 2, "three", "four", 5.09, 6.1, false, [ 8 ], 9, { "last": 10 } ]
rindex(arr_or_str, needle)   Finds the given value passed as the second argument within the array or string specified in the first argument str1 = 'Hello hello hello'; // string: "Hello hello hello"
str2 = 'll'; // string: "ll"
rindex(str1, str2);

arr3 = [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]; // array: [ 1, 2, 3, 1, 2, 3, 1, 2, 3 ]
int3 = 2; // int: 2
rindex(arr3, int3);
shift(arr)   Pops the first item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = shift(arr1); // int: 1
print(arr1); // [ 2, 3 ]

arr2 = [ 1, 'two', 3.09, false, [ 5, 6 ], { 'last': 7 } ]; // array: [ 1, "two", 3.09, false, [ 5, 6 ], { "last": 7 } ]
int2 = shift(arr2); // int: 1
str2 = shift(arr2); // string: "two"
dbl3 = shift(arr2); // double: 3.09
bool3 = shift(arr2); // bool: false
arr3 = shift(arr2); // array: [ 5, 6 ]
obj3 = shift(arr2); // object: { "last": 7 }
print(arr2); // [ ]
sprintf(fmt, …Arguments)   Formats the given arguments according to the given format string str1 = 'world'; // string: "world"
str2 = sprintf('Hello %s', str1); // string: "Hello world"

str3 = sprintf('%08x', 123); // string: "0000007b"
str4 = sprintf('%g', 10 / 3.0); // string: "3.33333"
str5 = sprintf('%2$d %1$d', 12, 34); // string: "34 12"
str6 = sprintf('%.2J', [ 1, 2, 3 ]); // string: "[ 1, 2, 3 ]"
str7 = sprintf('%.2J', { 'A': 1, 'B': 2, 'C': 3 }); // string: "{ "A": 1, "B": 2, "C": 3 }"
str8 = sprintf(33 > 22); // string: ""
time()   Returns the current UNIX epoch int1 = time(); // int: 1774602423
 
timegm(datetimespec)   Like timelocal() but interpreting the given date time specification as UTC time obj1 = { 'sec': 42, 'min': 51, 'hour': 13, 'mday': 22, 'mon': 3, 'year': 2022, 'isdst': 0 }; // object: { "sec": 42, "min": 51, "hour": 13, "mday": 22, "mon": 3, "year": 2022, "isdst": 0 }
int1 = timegm(obj1); // int: 1647957102
timelocal(datetimespec)   Transforms a broken-down date & time dictionary into an epoch value according to the local system timezone obj1 = { 'sec': 42, 'min': 51, 'hour': 13, 'mday': 22, 'mon': 3, 'year': 2022, 'isdst': 0 }; // object: { "sec": 42, "min": 51, "hour": 13, "mday": 22, "mon": 3, "year": 2022, "isdst": 0 }
int1 = timelocal(obj1); // int: 1647949902
unshift(arr, …Values)   Add the given values to the beginning of the array passed via first argument arr1 = [ 3, 4, 5 ]; // array: [ 3, 4, 5 ]
print(unshift(arr1, 1, 2)); // 2
print(arr1); // [ 1, 2, 3, 4, 5 ]

arr2 = [ 9, 10 ]; // array: [ 9, 10 ]
str3 = unshift(arr2, 'seven', 'eight'); // string: "eight"
dbl3 = unshift(arr2, 5.09, 6.1); // double: 6.1
bool3 = unshift(arr2, false); // bool: false
arr3 = unshift(arr2, [ 3 ]); // array: [ 3 ]
int3 = unshift(arr2, 2); // int: 2
obj3 = unshift(arr2, { 'first': 1 }); // object: { "first": 1 }
print(arr2); // [ { "first": 1 }, 2, [ 3 ], false, 5.09, 6.1, "seven", "eight", 9, 10 ]

regexp

match(str, pattern)   Match the given string against the regular expression pattern specified as the second argument rex1 = regexp('b.(.)'); // regexp: /b.(.)/
str1 = 'foobarbaz'; // string: "foobarbaz"
arr1 = match(str1, rex1); // array: [ "bar", "r" ]

arr2 = match('foobarbaz', /b.(.)/g); // array: [ [ "bar", "r" ], [ "baz", "z" ] ]
regexp(source, flags)   Construct a regular expression instance from the source string and any flags optionally given // Supported flags are: 'g', 'i', 's'
str1 = 'is'; // string: "is"
rex1 = regexp('foo.*bar', str1); // regexp: /foo.*bar/is
replace(str, pattern, replace, limit)   Replace occurrences of the specified pattern in the string passed as the first argument replace('barfoobaz', 'a', 'X'); // string: "bXrfoobXz"

str1 = 'barfoobaz'; // string: "barfoobaz"
rex1 = regexp('(f)(o+)', 'g'); // regexp: /(f)(o+)/g
str2 = '[$$|$`|$&|$1|$2|$3]'; // string: "[$$|$`|$&|$1|$2|$3]"
replace(str1, rex1, str2); // string: "bar[$|bar|foo|f|oo|$3]baz"

replace('barfoobaz', /(f)(o+)/g, uc); // string: "barFOObaz"

replace('foo bar baz', /[ao]/g, 'x', 3); // string: "fxx bxr baz"
split(str, sep, limit)   Split the string using the separator and return an array containing the resulting pieces str1 = 'foo,bar,baz'; // string: "foo,bar,baz"
arr1 = split(str1, ','); // array: [ "foo", "bar", "baz" ]

print(split('foobar', '')); // [ "f", "o", "o", "b", "a", "r" ]

rex2 = regexp('[ao]'); // regexp: /[ao]/
arr2 = split('foo,bar,baz', rex2); // array: [ "f", "", ",b", "r,b", "z" ]

print(split('foo=bar=baz', '=', 2)); // [ "foo", "bar=baz" ]

double

max(…val)   Return the largest value among all parameters passed to the function int1 = max(5, 2.1, 6.3, 0.3); // double: 6.3
int2 = max(1, 'abc'); // int: 1
str3 = max('def', 'abc', 'ghi'); // string: "ghi"
min(…val)   Return the smallest value among all parameters passed to the function int1 = min(5, 2.1, 6.3, 0.3); // double: 0.3
int2 = min(1, 'abc'); // int: 1
str3 = min('def', 'abc', 'ghi'); // string: "abc"
pop(arr)   Pops the last item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = pop(arr1); // int: 3
print(arr1); // [ 1, 2 ]

arr2 = [ 1, 2, 'three', 4.09, false, [ 6, 7 ], { 'last': 7 } ]; // array: [ 1, 2, "three", 4.09, false, [ 6, 7 ], { "last": 7 } ]
obj3 = pop(arr2); // object: { "last": 7 }
arr3 = pop(arr2); // array: [ 6, 7 ]
bool3 = pop(arr2); // bool: false
dbl3 = pop(arr2); // double: 4.09
str3 = pop(arr2); // string: "three"
int3 = pop(arr2); // int: 2
print(arr2); // [ 1 ]
print(…values)   Print any of the given values to stdout str1 = 'Hello'; // string: "Hello"
print(str1, ' world!'); // Hello world!

arr2 = [ 1, 'B', 3 ]; // array: [ 1, "B", 3 ]
print(arr2); // [ 1, "B", 3 ]

obj3 = { hello: true, world: 123 }; // object: { "hello": true, "world": 123 }
print(obj3); // { "hello": true, "world": 123 }

print(10 / 3.0); // 3.3333333333333
print(1 != 2); // true
print(0xff); // 255

print(proto({foo: 'bar'}, {tostring: () => 'MyObj'})); // MyObj
printf(fmt, …Arguments)   Formats the given arguments according to the given format string and outputs the result to stdout str1 = 'Hello'; // string: "Hello"
printf('%s world', str1); // Hello world

int2 = 123; // int: 123
printf('%08x', int2); // 0000007b

printf('%g', 10 / 3.0); // 3.33333
printf('%2$d %1$d', 12, 34); // 34 12

printf('%J', [1,2,3]); // [ 1, 2, 3 ]
printf('%.2J', [1,2,3]); // [ 1, 2, 3 ]

printf('%J', {'c': 1, 'b': 2, 'a': 3}); // { "c": 1, "b": 2, "a": 3 }
printf('%s', 32 < 10); // false
push(arr, …values)   Pushes the given argument(s) to the given array arr1 = [ 1, 2 ]; // array: [ 1, 2 ]
str2 = push(arr1, 'three', 'four'); // string: "four"
dbl2 = push(arr1, 5.09, 6.1); // double: 6.1
bool2 = push(arr1, false); // bool: false
arr2 = push(arr1, [ 8 ]); // array: [ 8 ]
int2 = push(arr1, 9); // int: 9
obj2 = push(arr1, { 'last': 10 }); // object: { "last": 10 }
print(arr1); // [ 1, 2, "three", "four", 5.09, 6.1, false, [ 8 ], 9, { "last": 10 } ]
shift(arr)   Pops the first item from the given array and returns it arr1 = [ 1, 2, 3 ]; // array: [ 1, 2, 3 ]
int1 = shift(arr1); // int: 1
print(arr1); // [ 2, 3 ]

arr2 = [ 1, 'two', 3.09, false, [ 5, 6 ], { 'last': 7 } ]; // array: [ 1, "two", 3.09, false, [ 5, 6 ], { "last": 7 } ]
int2 = shift(arr2); // int: 1
str2 = shift(arr2); // string: "two"
dbl3 = shift(arr2); // double: 3.09
bool3 = shift(arr2); // bool: false
arr3 = shift(arr2); // array: [ 5, 6 ]
obj3 = shift(arr2); // object: { "last": 7 }
print(arr2); // [ ]
sprintf(fmt, …Arguments)   Formats the given arguments according to the given format string str1 = 'world'; // string: "world"
str2 = sprintf('Hello %s', str1); // string: "Hello world"

str3 = sprintf('%08x', 123); // string: "0000007b"
str4 = sprintf('%g', 10 / 3.0); // string: "3.33333"
str5 = sprintf('%2$d %1$d', 12, 34); // string: "34 12"
str6 = sprintf('%.2J', [ 1, 2, 3 ]); // string: "[ 1, 2, 3 ]"
str7 = sprintf('%.2J', { 'A': 1, 'B': 2, 'C': 3 }); // string: "{ "A": 1, "B": 2, "C": 3 }"
str8 = sprintf(33 > 22); // string: ""
unshift(arr, …Values)   Add the given values to the beginning of the array passed via first argument arr1 = [ 3, 4, 5 ]; // array: [ 3, 4, 5 ]
print(unshift(arr1, 1, 2)); // 2
print(arr1); // [ 1, 2, 3, 4, 5 ]

arr2 = [ 9, 10 ]; // array: [ 9, 10 ]
str3 = unshift(arr2, 'seven', 'eight'); // string: "eight"
dbl3 = unshift(arr2, 5.09, 6.1); // double: 6.1
bool3 = unshift(arr2, false); // bool: false
arr3 = unshift(arr2, [ 3 ]); // array: [ 3 ]
int3 = unshift(arr2, 2); // int: 2
obj3 = unshift(arr2, { 'first': 1 }); // object: { "first": 1 }
print(arr2); // [ { "first": 1 }, 2, [ 3 ], false, 5.09, 6.1, "seven", "eight", 9, 10 ]

system

system(command, timeout)   Executes the given command, waits for completion, and returns the resulting exit code system('echo 'Hello world' && exit 3'); // print 'Hello world' and return 3
system(['/usr/bin/date', '+%s']); // print the UNIX timestamp and return 0
warn(…x)   Print any of the given values to stderr. Arrays and objects are converted to their JSON representation warn('Hello', 'world'); // Print 'Helloworld' to stderr
warn({ key: 'value' }); // Print JSON representation of the object to stderr

file

popen(command, mode)   Starts a process and returns a handle representing the executed process import * as fs from 'fs';
p = fs.popen('ls -al');
print(p.read('all'));
p.close();
read(length)   Reads a chunk of data from the program handle import * as fs from 'fs';
p = fs.popen('ls -al');
print(p.read('all'));
p.close();
close()   Closes the program handle and awaits program termination import * as fs from 'fs';
p = fs.popen('ls -al');
print(p.read('all'));
p.close();