Introduction

GDI.js (Global Device Interface) is a javascript runtime that written in object pascal. It's powered by Google Chrome's v8 engine which implements ECMA-262 standard.

Designed for hardware interfacing and desktop automation. Just taking advantage of javascript language for string and math operations without requiring any external packages, libraries, complex deployments or long compilation times.

Capabilities

It's deeply integrated with windows operating system. Able to manipulate serial ports, read & write digital I/O on your mainboard, hook keyboard, scan wifi networks, access to activex objects, run wmi queries and much more directly implemented from win32 api without any third party libraries.

Javascript's string manipulation capabilities makes it perfect candidate for receiving end of m2m communications. For example you can parse nmea messages of a gps receiver with only one line of code. Or create a fully featured web scraper with it's inline regex parser with only three lines.

Limitations

GDI.js started as a private project, so internal modules were developed only as needed over years. Unlike other js runtimes the platform executes code synchronously and creates extra threads only for functions with uncertain outcomes like tcp, udp or large file operations. Uses windows message loop as event handler which is default for most win32 applications.

Global js functions are fully supported but "Window" execution context from W3 standards are limited to setTimeout() clearTimeout() setInterval() clearInterval() alert() and confirm() check out w3schools for detailed api reference.

Command line arguments

GDI.js treats all command line arguments as a script and appends them into execution context in same order. so in that case if you have a library and a script that uses that library, the command line argument would be:


> gdi.exe "path\to\library\library.js" script.js

path delimiters can be forward or backslash, directories with spaces should be quoted

  • Name
    --hide
    Type
    null
    Description

    Hides the console window (stealth mode)

  • Name
    --log
    Type
    null
    Description

    Write syntax errors, warnings and console output to file "engine.log"

  • Name
    --zombie
    Type
    null
    Description

    Keep the process alive even if provided script done it's execution

  • Name
    --new
    Type
    null
    Description

    Prevent attaching into existing console such as conhost, cmd, powershell or windows terminal. Powershell versions older than 7.x messing with console colors.

  • Name
    --version or -v
    Type
    null
    Description

    Prints version information

  • Name
    --update
    Type
    null
    Description

    Checks most recent build from https://gdi.sh/ and update the installation

REPL Commands

When app started without any arguments, v8 engine enters into REPL mode which you can test your snippets or do some js exercise. Single variables are automatically pre-processed via built-in inspect() function in this mode, also few exra commands available besides common js syntax:

  • Name
    save [filename]
    Type
    command
    Description

    Saves the console content to file, defaults to "repl.log" if no parameter supplied

  • Name
    load [filename]
    Type
    command
    Description

    Loads and compiles given javascript file into active context

  • Name
    clear
    Type
    command
    Description

    Clear screen and reset history log

  • Name
    help
    Type
    command
    Description

    List declared REPL commands

  • Name
    update
    Type
    command
    Description

    Checks for new application updates, automatically updates itself if new version is backwards compatible.

  • Name
    exit
    Type
    command
    Description

    Exit the application immediately without freeing the resources (kill process)

Glossary

GDI.js extends the standard javascript syntax with it's built-in helper functions, only application specific methods are documented in here. Check out Mozilla MDN or w3schools if you're feeling rusty on classic javascript language set.

  • Extensions to global javascript objects, executed at v8 side, can be called directly without initilization.

  • Classes that executed at application layer, provides access to hardware, desktop, audio and windows api. Separated into static and non-static library categories, non-static classes requires initilization before use.

  • Static types that designed for hardware prototyping scenerios. Runs at v8 side, available in global scope, no initilization required.

  • Built-in ubiquitous modules that wraps around GDI.js native classes for rapid prototyping and portability.

Runtime

  • Name
    include(file[string]);
    Type
    boolean
    Description

    Injects a script from disk into called line

  • Name
    include_dir(path[string]);
    Type
    boolean
    Description

    Retrieves all files from a folder and injects into execution context

  • Name
    alert(message[string],title[string]);
    Type
    boolean
    Description

    Shows a messagebox from foreground window, blocks main thread

  • Name
    confirm(message[string],title[string]);
    Type
    string
    Description

    Asks input from user and return as string, blocks main thread

  • Name
    time();
    Type
    integer
    Description

    Returns unix timestamp in seconds, faster than Date.unix() suitable for time critical operations

  • Name
    millis();
    Type
    integer
    Description

    Returns script running time in miliseconds

Constants

  • Name
    nil
    Type
    null
    Description

    Shorthand for empty function

  • Name
    nl
    Type
    string
    Description

    Line ending for win32 platform

  • Name
    _1h
    Type
    number
    Description

    Represents one hour in seconds

  • Name
    _1d
    Type
    number
    Description

    Represents one day in seconds

  • Name
    _1m
    Type
    number
    Description

    Represents one month in seconds

  • Name
    _1y
    Type
    number
    Description

    Represents one year in seconds

Parsers

  • Name
    parseNumber(value[string])
    Type
    number
    Description

    Converts string value into arithmetic operable number type with content awareness. integer, float, hex, decimal, octal etc.

  • Name
    parseBit(value [any])
    Type
    integer
    Description

    Converts provided value to 1 or 0

  • Name
    parseBool(value [any])
    Type
    boolean
    Description

    Converts provided value to true or false

Helpers

  • Name
    urlEncode(value [string])
    Type
    string
    Description

    Shorthand for encodeURIComponent() added for cross-compatibility

  • Name
    urlDecode(value [string])
    Type
    string
    Description

    Shorthand for decodeURIComponent() added for cross-compatibility

  • Name
    escapeRegExp(value [string])
    Type
    string
    Description

    Adds escape characters to provided regex string, useful on dynamic regex templates

  • Name
    extractFileName(path [string])
    Type
    string
    Description

    Returns filename from a full file path

  • Name
    extractFilePath(path [string])
    Type
    string
    Description

    Returns directory from a full file path

  • Name
    extractFileExt(filename [string])
    Type
    string
    Description

    Returns extension from filename

  • Name
    inspect(value [object])
    Type
    object
    Description

    Enumerates all child elements of given object including functions and constructors. Limited to 32 nested elements

Type Checks

  • Name
    isset(value [any])
    Type
    boolean
    Description

    Checks if a variable set

  • Name
    isJson(value [string])
    Type
    boolean
    Description

    Checks if provided string JSON or not

  • Name
    isPrime(value [number])
    Type
    boolean
    Description

    Checks if provided value is a prime number

  • Name
    isDate(value [Date])
    Type
    boolean
    Description

    Checks if provided value is a javascript Date object

  • Name
    isArray(value [object])
    Type
    boolean
    Description

    Checks if provided object represents a javascript array

  • Name
    isFloat(value [number])
    Type
    boolean
    Description

    Checks if provided value is a floating point number or not

  • Name
    isInt(value [string])
    Type
    boolean
    Description

    Checks if provided string is an integer

  • Name
    isNumeric(value [string])
    Type
    boolean
    Description

    Checks if provided string is numerical (hex, integer, float) returns true only if provided string can be converted to number without alteration

    
    console.log(isNumeric("123.456"));  // true
    console.log(isNumeric("123"));      // true
    console.log(isNumeric(".456"));     // true
    console.log(isNumeric("123."));     // true
    console.log(isNumeric("0x1A"));     // true
    console.log(isNumeric("1.2e3"));    // true
    console.log(isNumeric("1.2E-3"));   // true
    console.log(isNumeric("0123"));     // true (as decimal)
    console.log(isNumeric("0001"));     // true
    console.log(isNumeric("NaN"));      // false
    console.log(isNumeric("Infinity")); // false
    console.log(isNumeric("abc"));      // false
    console.log(isNumeric("123abc"));   // false
    console.log(isNumeric(""));         // false
    
  • Name
    isAlphabetic(value [string])
    Type
    boolean
    Description

    Checks if provided string only consists of letters without white space and punctation

Booleans

  • Name
    Boolean.random()
    Type
    boolean
    Description

    Returns a random true or false

Strings

  • Name
    String.random(len [number])
    Type
    string
    Description

    Generates a random string at given length

  • Name
    String.prototype.count(search [string])
    Type
    integer
    Description

    Returns the occurrance count of the given substring

  • Name
    String.prototype.extract(_from [string],to [string])
    Type
    string
    Description

    Extract subcontents of string from A to B

    "[tag]the custom content[tag]".extract("[tag]","[/tag]");
    // output
    "the custom content"
    
    "her sister born at 1997 that's the date".extract("at","that");
    // output
    " 1997 "
    
  • Name
    String.prototype.capitalize(all [boolean])
    Type
    string
    Description

    Makes the very first letter uppercase, applies to all words in sentence if "all" parameter is true

  • Name
    String.prototype.render(values [object])
    Type
    string
    Description

    Replaces {{mustache}} keys with object's values

    "SELECT * from {{table}} where id={{id}}".render({"id":15,"table":"mytable"});
    // output
    "SELECT * from mytable where id=15"                                                      
    
  • Name
    String.prototype.eval(code [string])
    Type
    string
    Description

    Sends string to compiler

  • Name
    String.prototype.removeLastChar(text [string])
    Type
    string
    Description

    Deletes last character of the string

  • Name
    String.prototype.replaceAt(n[char], c[char])
    Type
    string
    Description

    Replaces nth character of the string with given one

  • Name
    String.prototype.getByteLen()
    Type
    integer
    Description

    Returns the string size in bytes

  • Name
    String.prototype.pad(w[char],c[int])
    Type
    string
    Description

    Keeps the string in a fixed [c] size by prefixing with character [w]

  • Name
    String.prototype.clean()
    Type
    string
    Description

    Removes null termination characters from string

  • Name
    String.prototype.explode(c[char],n[int])
    Type
    string
    Description

    Splits the string with c character and returns nth item

    "hello my name is eminem".explode(" ",4);
    // output
    "eminem"                                                      
    
  • Name
    String.prototype.ignore(c[char],n[int])
    Type
    string
    Description

    Splits the string with c character and joins back by ignoring nth item

    "hello my name is eminem".ignore(" ",0);
    // output
    "my name is eminem"                                                      
    
  • Name
    String.prototype.trimAll()
    Type
    string
    Description

    Removes all whitespace from string

  • Name
    String.prototype.reverse()
    Type
    string
    Description

    Reconstructs the string in reverse order

  • Name
    String.prototype.toDecimal()
    Type
    integer
    Description

    Converts octal binary string into decimal byte

  • Name
    String.prototype.toBool()
    Type
    boolean
    Description

    Converts "1" or "0" into boolean

  • Name
    String.prototype.toFloat()
    Type
    number
    Description

    Locale aware parseFloat()

  • Name
    String.prototype.toBitArray()
    Type
    Array
    Description

    Converts octal binary string into boolean array

  • Name
    String.prototype.lastDelimiter(c[char])
    Type
    Array
    Description

    Splits the string with [c] and returns the last piece

  • Name
    String.prototype.ignorelastDelimiter(c[char])
    Type
    Array
    Description

    Splits the string with [c] and reconstructs the string by ignoring the last piece

Numbers

  • Name
    Number.prototype.add(v);
    Number.prototype.substract(v);
    Number.prototype.multiply(v);
    Number.prototype.divide(v);
    Type
    integer
    Description

    Shorthand for simple mathematical operations

  • Name
    Number.prototype.round(precision [integer]);
    Type
    integer
    Description

    Reduce precision of the long floating point number

  • Name
    Number.prototype.toTime();
    Type
    string
    Description

    Translates seconds into days, hours, minutes

  • Name
    Number.primes(min,max);
    Type
    Array
    Description

    Generates array of prime numbers between x and y

  • Name
    Number.randPrime(min,max);
    Type
    integer
    Description

    Generates a random prime number between x and y

  • Name
    Number.random(min,max);
    Type
    integer
    Description

    Generates a random integer between x and y

  • Name
    Number.randomFloat(min,max);
    Type
    number
    Description

    Generates a random random float between x and y

  • Name
    Number.prototype.pad(w,n);
    Type
    string
    Description

    Converts the number into string and keeps in fixed length by padding with [w]

  • Name
    Number.prototype.toBinary(length[integer]);
    Type
    string
    Description

    Converts the decimal byte into binary string

  • Name
    Number.prototype.toBool();
    Type
    string
    Description

    Converts 1 or 0 to true or false

  • Name
    Number.prototype.toBitArray();
    Type
    Array
    Description

    Converts the decimal byte into boolean array

  • Name
    Number.prototype.setPercent(percent);
    Type
    integer
    Description

    Returns the n% amount of number

  • Name
    Number.prototype.getPercent(value);
    Type
    integer
    Description

    Calculates the percentage of the value

  • Name
    Number.prototype.map(in_min, in_max, out_min, out_max);
    Type
    integer
    Description

    Scales the number to according to a new scale, useful on data normalization and progressbar visualization

    var num = 50;
    var newNum = num.map(0, 100, 0, 200);
    console.log(newNum);  // Outputs: 100                                                  
    

Arrays

  • Name
    Object.values(obj);
    Type
    Array
    Description

    Returns an array of values of the enumerable properties of an object.

    const obj = { a: 1, b: 2, c: 3 };
    console.log(Object.values(obj));  // Outputs: [1, 2, 3]
    
  • Name
    Object.entries(obj);
    Type
    Array
    Description

    Returns an array of key-value pairs of the enumerable properties of an object.

    const obj = { a: 1, b: 2, c: 3 };
    console.log(Object.entries(obj));  // Outputs: [["a", 1], ["b", 2], ["c", 3]]
    
  • Name
    Array.prototype.group(category);
    Type
    Object
    Description

    Groups elements of an array by a specified category and returns an object with each group.

    const items = [{ category: 'fruit', name: 'apple' }, { category: 'vegetable', name: 'carrot' }];
    console.log(items.group('category'));
    // Outputs: { fruit: [{name: 'apple'}], vegetable: [{name: 'carrot'}] }
    
  • Name
    Array.prototype.prune();
    Type
    Array
    Description

    Filters out duplicate and empty values from an array, returning a clean array.

    const array = [null, "", "apple", "banana", "apple"];
    console.log(array.prune());
    // Outputs: ["apple", "banana"]
    
  • Name
    Array.prototype.random();
    Type
    mixed
    Description

    Returns a random element from an array, which can be useful for sampling or games.

    const fruits = ["apple", "banana", "cherry"];
    console.log(fruits.random());
    // Outputs: "banana" (output may vary)
    
  • Name
    Array.prototype.fill(content, size);
    Type
    Array
    Description

    Fills an array with a specific content, repeated for a given size. The content can be a static value or provided by a function.

    const array = [];
    console.log(array.fill('apple', 3));
    // Outputs: ["apple", "apple", "apple"]
    
  • Name
    Array.prototype.Find(key, val);
    Type
    Array
    Description

    Returns the indices of elements that match a specified key, value, or key-value pair.

    const items = [{ name: 'apple' }, { name: 'banana' }];
    console.log(items.Find('name', 'apple'));
    // Outputs: [0]
    
  • Name
    Array.prototype.delete(key, val);
    Type
    Array
    Description

    Removes elements from the array that match the specified key-value criteria.

    const items = [{ name: 'apple' }, { name: 'banana' }];
    console.log(items.delete('name', 'banana'));
    // Outputs: [{ name: 'apple' }]
    
  • Name
    Array.prototype.get(key, val);
    Type
    Array
    Description

    Searches for and returns elements that match a specific key-value pair, key, or value.

    const items = [{ name: 'apple' }, { name: 'banana' }, { name: 'cherry' }];
    console.log(items.get('name', 'banana'));
    // Outputs: [{ name: 'banana' }]
    
  • Name
    Array.prototype.each(callback, onFinish);
    Type
    void
    Description

    Iterates over the array, executing the initial callback on each element. An optional end callback can terminate the loop early.

    const fruits = ["apple", "banana", "cherry"];
    fruits.each(e => console.log(e), () => console.log('Finished!'));
    // Outputs each fruit followed by 'Finished!'
    
  • Name
    Object.prototype.extend(o);
    Type
    Object
    Description

    Extends an object by adding new properties from another object, modifying the original object.

    const base = { a: 1 };
    const extension = { b: 2 };
    console.log(base.extend(extension));
    // Outputs: { a: 1, b: 2 }
    
  • Name
    Array.prototype.extract(key);
    Type
    Array
    Description

    Extracts a specific property from each object in an array, effectively fetching a column from a table of data.

    const items = [{ name: 'apple' }, { name: 'banana' }];
    console.log(items.extract('name'));
    // Outputs: ['apple', 'banana']
    
  • Name
    Array.prototype.toDecimal();
    Type
    Number
    Description

    Converts an array of boolean values to a decimal value, interpreting the boolean array as binary digits.

    const bits = [true, false, true]; // Representing binary 101
    console.log(bits.toDecimal());
    // Outputs: 5 (from binary 101 to decimal)
    
  • Name
    Array.prototype.last();
    Type
    Element
    Description

    Returns the last element of the array without modifying the array.

    const items = [1, 2, 3, 4, 5];
    console.log(items.last());
    // Outputs: 5
    

Audio

  • Constructor
    new Audio (rate[integer]);
    Type
    Class Constructor
    Description

    Initializes an Audio object with optional sample rate. Handles initialization of the audio system and sets up internal properties.

    const audio = new Audio();
    audio.play("test.ogg");
    
  • Method
    loadSample(file, callback)
    Type
    Function
    Description

    Loads an audio sample from a file, associates it with a tag derived from the file name, and optionally executes a callback with the tag as an argument. Tags are file names without extension, when you load "test.ogg" play the sample by calling playSample("test");

  • Method
    play(path)
    Type
    Function
    Description

    Plays an audio stream from the specified path.

  • Method
    playSample(tag)
    Type
    Function
    Description

    Plays a previously loaded audio sample associated with the specified tag.

  • Method
    on(event, callback)
    Type
    Function
    Description

    Registers a callback to be called when a specified event occurs. Events include activity, device changes, reinitialization, and mute status.

  • Method
    playDSP(f)
    Type
    Function
    Description

    Plays audio through a digital signal processing (DSP) function provided by the user.

  • Event Handling
    monitor(callback)
    Type
    Function
    Description

    Monitors various audio device events like activity, device connect/disconnect, mute, and volume changes, and executes callback functions associated with these events.

  • Property
    muted
    Type
    Boolean
    Description

    Indicates whether the audio output is currently muted. This property is dynamically updated based on system audio events.

  • Destructor
    release()
    Type
    Destructor
    Description

    Terminates the audio session and clean up loaded resources.

console

Built-in static object to write output to console. No initilization required

  • Method
    write(text)
    Type
    Function
    Description

    Directly writes content to console output as it is. No conversion.

  • Method
    log(content)
    Type
    Function
    Description

    Analyzes the provided content and parse/inspect it if necessary.

IPC

  • Constructor
    new IPC(win[vary]);
    Type
    Class Constructor
    Description

    Initializes a new IPC object for inter-process communication. It takes a window identifier or name, finds or sets the window handle, and prepares the object for IPC operations.

  • Method
    refresh()
    Type
    Function
    Description

    Updates or retrieves the window handle based on the initial window identifier provided. If the identifier is a number, it sets directly; otherwise, it uses an IPC method to find the handle.

  • Method
    write(string)
    Type
    Function
    Description

    Sends a string message to window handle of another process associated with the stored window handle. The other app should be able to accept WM_COPYDATA messages, otherwise script host might crash.

Desktop

  • Constructor
    new Desktop();
    Type
    Class Constructor
    Description

    Initializes a new desktop access interface.

  • WIP: API Documentation is work in progress

fs

It's a static object for basic file system operations. No initialization required.

  • Method
    write(filename[string], data[vary]);
    Type
    Function
    Description

    Writes given data to a file, typically used for creating new files or overwriting existing ones.

  • Method
    browse(dir[string],recursive[boolean])
    Type
    Function
    Description

    Provides functionality to browse through directories or files within the system.

  • Method
    read(pathToFile[string]);
    Type
    mixed
    Description

    Reads data from a file into variable

  • Method
    exists(file[string])
    Type
    Function
    Description

    Checks if a particular file or directory exists. It's used to verify the presence of files or directories before performing operations.

  • Method
    mkdir(path[string])
    Type
    Function
    Description

    Creates a new directory.

  • Method
    append(file[string])
    Type
    Function
    Description

    Adds data to the end of an existing file without overwriting the original content, preserving the existing data.

  • Method
    delete(file[string])
    Type
    Function
    Description

    Deletes a specified file or directory.

  • Method
    rename(file[string])
    Type
    Function
    Description

    Renames an existing file or directory

http

Built-in static object for generic web requests. No initialization required.

Uses windows winhttp api which supports ipv6, SSL 2.0, SSL3.0, TLS 1.0 and got experimental HTTP/2 feature. Availability depends on operating system version

  • Method
    get(url[string], callback[function]);
    Type
    Function
    Description

    Creates a new thread and passes the status code and response data to callback function when completed. Callback function converts data into relevant js type according to mime headers. Synchronously returns the url contents as string if no callback supplied.

  • Method
    post(url[string], payload[vary], callback[function]);
    Type
    Function
    Description

    Same usage as get() method. Processes the payload, converts the payload type into relevant format and initiates a post request.

    
    ["key=value","anotherkey=value"]    // application/x-www-form-urlencoded
    {"key":"string","anotherkey":1234}  // application/json
                                                        

    Equal sign is key=value delimiter for composing form data, Array elements without it is ignored and only one equal sign allowed per array item.

  • Method
    download(url[string], filename[string], onfinish[function], onprogress[function]);
    Type
    Function
    Description

    Initiates a download process and saves contents to disk, url parameter required other parameters are optional

    
    http.download("https://link.testfile.org/bNYZFw","test.mp4",function(e) {
        console.log(e);
    }, function(e) {
        console.log(e);
    });
    
    // progress callback
    {
      "read": 2219200,          // read bytes
      "total": 11340570,        // total bytes
      "speed": "2,12 MB/s",     // download speed
      "progress": 20            // download progress in percent
    }
    
    // finish callback
    {
      "result": true,           // operation status
      "response": 200,          // http response
      "downloaded": 11340570,   // downloaded file size
      "size": 11340570,         // reported file size
      "mime": "video/mp4",      // reported mime
      "local": "test.mp4",      // local file path
      "remote": "https://link.testfile.org/bNYZFw"  // remote url
    }
    
    

Hardware

  • Constructor
    new Hardware();
    Type
    Class Constructor
    Description

    Initializes a new hardware listener object and sets system wide hooks

  • Method
    list()
    Type
    Function
    Description

    Retrieves a list of hardware devices, converting their information into a parsed format for further processing.

  • Method
    exists(devname)
    Type
    Function
    Description

    Checks if a device with a specified name exists within the current buffer of enumerated devices.

  • Method
    on(event, callback, devId)
    Type
    Function
    Description

    Registers an event listener for hardware events such as device arrival or removal, executing a callback when the specified event occurs, related to a particular device if specified.

    "arrival" for plugged-in devices, "removal" for plugged out hardware. Required parameter.

    "devId" is device name, listens only for this device if it's set, trigger for all hardware events otherwise.

  • Method
    free()
    Type
    Function
    Description

    Deactivates the hardware monitoring library, clearing any stored device data and removing all event listeners to prevent memory leaks and ensure clean shutdown.

Process

  • Constructor
    new Process(path[string]);
    Type
    Class Constructor
    Description

    Creates a new process.

  • WIP: API Documentation is work in progress

Serial

  • Constructor
    new Serial(port[string],baud[integer]);
    Type
    Class Constructor
    Description

    Creates a new serial port interface and connects to provided port if both parameters are supplied

  • Method
    open(port, baud)
    Type
    Function
    Description

    Initializes the serial port with the specified port and baud rate, setting up the communication channel. Handles automatic port detection if a non-standard port string is provided.

  • Method
    close()
    Type
    Function
    Description

    Closes the active serial port, stops any ongoing read operations, and cleans up related timers and resources.

  • Method
    available()
    Type
    boolean
    Description

    Checks if data available in read buffer

  • Method
    read()
    Type
    string
    Description

    Returns the available data in hardware buffer

  • Method
    write(data, cb)
    Type
    Function
    Description

    Sends data through the serial port. Supports an optional callback for handling confirmation of data sent.

  • Method
    start(callback[function],delimiter[char]);
    Type
    Function
    Description

    Begins continuous reading from the serial port, using a callback to process each line of incoming data. \n is default delimiter

  • Method
    stop()
    Type
    Function
    Description

    Stops the ongoing reading process from the serial port and clears the read timer, effectively halting data reception.

  • Method
    enum()
    Type
    Array
    Description

    Enumerates available serial devices

    
    var serial = new Serial();
    serial.enum();
    // output
    {
        "port":"COM3",
        "desc":"USB-SERIAL CH340",
        "busy":false
    },
    {
        "port":"COM1",
        "desc":"Communications Port",
        "busy":false
    }                                                    
    
  • Method
    find(desc, cb)
    Type
    Function
    Description

    Searches for a specific device description within the enumerated serial devices, using a callback to return the found device or null if not found.

Sqlite

  • Constructor
    new Sqlite(file[string]);
    Type
    Class Constructor
    Description

    Creates a new sqlite database instance or opens an existing file if file path supplied

  • Method
    open(f)
    Type
    Function
    Description

    Opens a connection to an SQLite database file. Sets up automatic closure upon release to ensure clean resource management.

  • Method
    close()
    Type
    Function
    Description

    Closes the open SQLite database connection, effectively freeing the associated resources.

  • Method
    query()
    Type
    Function
    Description

    Executes a SQL query against the open database. Overloads allow for synchronous returns or asynchronous callback handling of query results.

  • Method
    exec(sql)
    Type
    Function
    Description

    Executes a SQL statement that does not return data (such as UPDATE, DELETE, INSERT), providing a return value indicative of success or failure.

tcp

Built-in static object for basic tcp operations. Each instance process the connections in it's own thread


// triggers the callback on each line delimiter
tcp.listen(1234,function(data[string],client[object]) {
    // [client] object
    {
        "remoteAddr": "127.0.0.1",
        "close": "function()",        // closes the connection
        "send": "function(data)"      // sends a response
    }
    // [data] string
    "test"
});


TTS

Built-in static object to access microsoft speech api (SAPI)

  • function
    enum();
    Type
    Array
    Description

    Returns installed voice models

  • function
    speak(sentence[string],speaker[string],callback[function]);
    Type
    Array
    Description

    Synthesizes given text from primary audio output

  • function
    render(sentence[string],speaker[string],target[string],callback[function]);
    Type
    Array
    Description

    Creates a wav file at given filename

udp

Built-in static object for udp operations

  • function
    send(address:port[string],data[string]);
    Type
    boolean
    Description

    Sends an udp packet to given address:port combination.

  • function
    listen(port[integer],callback[function]);
    Type
    integer
    Description

    Listens for udp packets and trigger the given callback function when new packet received. Returns the server handle.

    
    udp.listen(1234,function(data,client) {
        // data[string]
        "test"
    
        // client[object]
        {
        "remoteAddr":"127.0.0.1",   // remote address
        "stop":"function()"         // stops listening
        }
    });
    
  • function
    stop(handle[integer]);
    Type
    boolean
    Description

    Stops the udp server instance of given handle

vm

Internal object to access execution environment related functions and variables

  • integer
    pid
    Type
    integer
    Description

    Get current process Id

  • integer
    handle
    Type
    integer
    Description

    Application message handle (HWND)

  • process
    string

    Returns full executable path

  • args
    Array

    Returns command line arguments

  • host
    Array

    Returns brief summary of host session

    
    {
      "name": "HOST",       // Computer name
      "user": "USER",       // Logged in user name
      "IsAdmin": true,      // Is user an administrator
      "os": "Windows 10.0 build 22631", // OS version
      "ram": 64,            // Installed RAM
      "IsElevated": true,   // Is UAC elevated process
      "country": "GB",      // OS reported country
      "timezone": "2",      // timezone in utc
      "locale": "en-GB"     // OS Locale
    }
    
  • env
    object

    Holds a key-value array of system environment variables. Values are automatically parsed into types and strings with semicolons (;) are converted to array

  • arch
    object

    Returns the application architecture

  • path
    object

    Returns commonly used system paths

  • function
    end();
    Type
    boolean
    Description

    gracefully ends the session and frees up the allocated resources

  • function
    terminate();
    Type
    boolean
    Description

    kills the host executable process

  • function
    ramUsage();
    Type
    integer
    Description

    Returns physical ram usage percentage of host session.

  • function
    getTickCount();
    Type
    integer
    Description

    Returns os uptime in miliseconds.

  • function
    release(callback[function]);
    Type
    void
    Description

    Executes provided callback function before script execution ends

Bio

Library providing health-related functions.

  • Function
    bmi
    Parameters
    weight: number, height: number
    Returns
    string
    Description

    Calculates the Body Mass Index (BMI) using weight (in kilograms) and height (in centimeters) and returns it formatted to two decimal places.

Color

Library providing utilities for color manipulation such as generating random colors, fading colors, and converting between color formats.

  • Function
    random
    Returns
    string
    Description

    Generates a random hex color.

  • Function
    fade
    Parameters
    col: string, amount: number
    Returns
    string
    Description

    Adjusts the brightness of a hex color by a specified amount and returns the modified color as a hex string.

  • Function
    hexToRgb
    Parameters
    hex: string
    Returns
    Object
    Description

    Converts a hex color to an RGB object with properties r, g, and b.

  • Function
    rgbToHex
    Parameters
    r: number, g: number, b: number
    Returns
    string
    Description

    Converts RGB values to a hex color string.

Date

Enhancements to the built-in Date object to provide additional date and time manipulation functionalities.

  • Method
    millis
    Returns
    number
    Description

    Returns the time value in milliseconds.

  • Static Method
    unix
    Returns
    number
    Description

    Returns the current UNIX timestamp in seconds.

  • Static Method
    clock
    Parameters
    d: Date (optional)
    Returns
    string
    Description

    Returns the current time formatted as HH:MM.

  • Static Method
    get
    Parameters
    d: Date (optional), div: string (optional)
    Returns
    string
    Description

    Returns the current date formatted as MM/DD/YYYY or with a specified divider.

  • Method
    addHour
    Parameters
    h: number
    Returns
    Date
    Description

    Adds a specified number of hours to the date and returns the updated Date object.

GraphWatcher

Object responsible for monitoring and managing state changes of various events based on predefined conditions and thresholds.

  • Function
    add
    Parameters
    key: string, obj: object, cb: function
    Description

    Registers a new event with an identifier, a state object, and an optional callback function. The state object is initialized with default properties and a time-to-live (TTL).

  • Function
    update
    Parameters
    event: string | string[], val: number
    Description

    Updates the value of one or more events and manages their state based on the new value. Triggers any registered callbacks if there are state changes.

Location

Library providing utilities for geographic calculations, including conversions between different speed units and calculations of distance, time, and bearing based on coordinates.

  • Function
    milesToKMH
    Parameters
    miles: number
    Returns
    number
    Description

    Converts miles to kilometers per hour (km/h).

  • Function
    knotsToKMH
    Parameters
    knots: number
    Returns
    number
    Description

    Converts knots to kilometers per hour (km/h).

  • Function
    time
    Parameters
    distance: number, speed: number
    Returns
    number
    Description

    Calculates the time in minutes to travel a certain distance at a given speed, both in km and km/h respectively.

  • Function
    speed
    Parameters
    distance: number, minutes: number
    Returns
    number
    Description

    Calculates the speed in km/h needed to travel a given distance in a specified number of minutes.

  • Function
    distance
    Parameters
    lat1: number, lon1: number, lat2: number, lon2: number
    Returns
    number
    Description

    Calculates the great-circle distance between two points on the earth given their latitude and longitude in degrees.

  • Function
    bearing
    Parameters
    lat1: number, lng1: number, lat2: number, lng2: number
    Returns
    number
    Description

    Calculates the compass bearing from one geographic location to another.

sec

Basic hash and encryption functions

  • Method
    md5();
    Parameters
    input: string
    Returns
    string
    Description

    Returns MD5 hash of given string

  • Method
    sha1();
    Parameters
    input: string
    Returns
    string
    Description

    Returns SHA1 hash of given string

  • Method
    crc();
    Parameters
    input: string
    Returns
    string
    Description

    Returns CRC32 hash of given string

  • Method
    base64.encode();
    Parameters
    input: string
    Returns
    string
    Description

    Encodes a UTF-8 string into Base64 format. It handles all UTF-8 characters including multibyte ones.

  • Method
    base64.decode();
    Parameters
    input: string
    Returns
    string
    Description

    Decodes a Base64 encoded string back into a UTF-8 string. It correctly handles Base64 decoding, ensuring proper reconstruction of the original UTF-8 string.

Sun

Comprehensive module for calculating the positions of the sun and moon, including times for sunrise, sunset, and moon phases, based on the observer's geographical location.

  • Method
    getPosition
    Parameters
    date: Date, lat: number, lng: number
    Returns
    Object
    Description

    Calculates the sun's position at a specific date and geographical location, returning the azimuth and altitude of the sun.

  • Method
    get
    Parameters
    date: Date, lat: number, lng: number
    Returns
    Object
    Description

    Provides detailed sun and moon events for a given date and location, including times for various types of twilight and golden hours.

  • Method
    today
    Parameters
    lat: number, lng: number
    Returns
    Object
    Description

    Calculates sun and moon information for today, including the previous sunset and the next sunrise, for a given location.

  • Method
    getMoonPosition
    Parameters
    date: Date, lat: number, lng: number
    Returns
    Object
    Description

    Calculates the moon's position at a specific date and location, returning azimuth, altitude, distance, and parallactic angle.

  • Method
    getMoonIllumination
    Parameters
    date: Date
    Returns
    Object
    Description

    Provides detailed information on moon illumination for a given date, including fraction, phase, and angle of illumination.

Temp

Utility object for converting temperature units

  • Method
    toCelcius
    Parameters
    fahrenheit: number
    Returns
    number
    Description

    Converts a temperature from Fahrenheit to Celsius.

  • Method
    toFahrenheit
    Parameters
    celcius: number
    Returns
    number
    Description

    Converts a temperature from Celsius to Fahrenheit.

webServer

Lightweight web server to handle basic POST and GET requests

  • Method
    new webServer(port[integer]);
    Parameters
    constructor
    Returns
    number
    Description

    Creates a new server instance

  • Method
    listen(callback);
    Parameters
    function
    Returns
    number
    Description

    starts listening for connections, triggers the provided callback function on each request.

DBA

Database Access object for managing SQLite database interactions, supporting operations like querying, retrieving, and inserting data.

  • Method
    get
    Parameters
    table: string, cb: function
    Returns
    void
    Description

    Retrieves all records from a specified table and returns the results via a callback function.

  • Method
    query
    Parameters
    table: string, key: string, val: string | number
    Returns
    void | object
    Description

    Executes a query to retrieve records from a specified table where the column matches a specific value. Results are returned either synchronously or asynchronously.

  • Method
    insert
    Parameters
    table: string, data: object, cb: function (optional)
    Returns
    void | object
    Description

    Inserts a new record into a specified table using the data provided. Data is an object where keys correspond to column names. This operation can be synchronous or asynchronous, depending on the database connection type.