Socket
Book a DemoInstallSign in
Socket

bds.js

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bds.js

A simple interpreter written to simulate and run BDScript Language in JavaScript

Source
npmnpm
Version
1.0.7
Version published
Weekly downloads
12
300%
Maintainers
1
Weekly downloads
 
Created
Source

bds.js

Run and simulate string-based BDScript language in JavaScript

Prerequisites

This project requires a JavaScript runtime which supports ES2020 and ESModules.

Table of Contents

  • bds.js

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!"); // A string value identifier
env.set("age", 24); // Number value identifier
env.set("random", () => Math.random()); // Function without argument (The use of [])
env.set("random50", (handler) => {
    // Getting raw arguments
    const raw_arguments = handler.getArgs(0, 2);
    // Waiting for arguments to run
    const arguments = handler.waitForArguments(...raw_arguments);
    // Calling functions
    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;
// Adding arithmetics and utility modules
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

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] # number
$typeof[Pi is $pi] #string

Goals

  • Usable
  • Basic utility Functions (25%)
  • Conditions support
  • Arithmetic support
  • Compile-able code to JavaScript
  • Easier access and friendly-code
  • Native code (JavaScript) support
  • Import & Export
  • Runtime Error

MIT License

License can be found here

Keywords

bdfd

FAQs

Package last updated on 02 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts