bds.js
Run and simulate string-based BDScript language in JavaScript
Prerequisites
This project requires a JavaScript runtime which supports ES2020 and ESModules.
Changelog v1.0.9
- Added
OS, Process, ObjectInteract class
- New features
$throw, $new, $tryAndCatch, $let, $get
Table of Contents
Installation
Install bds.js with npm:
$ npm install bds.js
or getting releases from github
Usage
Creating Environments
Environments are used to define variables outside BDScript code
Example of usage:
const Environment = require("bds.js").Environments.Environment;
const env = new Environment();
Creating variables and functions
The use of Environments are to define variables and functions. These "identifiers" can be created by static value or using a function, it doesn't matter if you need extra arguments or not.
Inputting arguments to a identifier (example $sum) is to use brackets ([ and ])
Example > $sum[2;3;4] is (2 + 3 + 4)
Creating identifiers:
env.set("hello", "world!");
env.set("age", 24);
env.set("random", () => Math.random());
env.set("random50", (handler) => {
const raw_arguments = handler.getArgs(0, 2);
const arguments = handler.waitForArguments(...raw_arguments);
const chance = handler.callIdentifier("random") * 100;
if (chance > 50) return args[1];
return args[0];
});
Preparing FileScript
Create a file with name index.bds and fill with BDScript code
Preparing a Script for the file:
const FileScript = require("bds.js").Scripts.FileScript;
const Script = new FileScript("./index.bds");
Script.getFileInput();
Multiple Environments
A way to utilize multiple environments without the need to chain. It is also to support third-party libraries
Initializing Environment Manager:
const lib = require("bds.js");
const { Arithmetics, Utility } = lib.Modules;
const envManager = lib.Environments.EnvironmentManager;
envManager.add("math", new Arithmetics()).add("util", new Utility());
Running Script
You can use console.log() to print the output to console
const runScript = Script.prepareModules(envManager);
runScript.run();
Working with Functions
These are modules / environments ready-for-use to help your development:
Arithmetics
Utility
Process
ObjectInteract
OS
Functions can return non-string Objects as long as it is not interferred by other type.
Functions are case-sensitive, if the function is not found the runtime will error
As example with $pi (from Arithmetics module) and $typeof (Utility):
$typeof[$pi]
$typeof[Pi is $pi]
Goals
MIT License
License can be found here