wandbox-api.js
v1.2.1
Published
A basic wrapper for Wandbox API (Unofficial).
Downloads
5
Maintainers
Readme
Wandbox-API.js
A basic wrapper for Wandbox API (Unofficial).
Table of Contents
Install
This package requires axios for HTTP client.
npm install axios @tfagaming/wandbox-api
yarn add axios @tfagaming/wandbox-api
Supported languages
These are the languages that Wandbox can compile:
Bash script
, C
, C#
, C++
, Crystal
, D
, Elixir
, Erlang
, Go
, Groovy
, Haskell
, Java
, JavaScript
, Julia
, Lazy K
, Lisp
, Lua
, Nim
, OCaml
, OpenSSL
, PHP
, Pascal
, Perl
, Pony
, Python
, R
, Ruby
, Rust
, SQL
, Scala
, Swift
, TypeScript
, Vim script
, and Zig
.
Usage
import { WandboxAPI } from 'wandbox-api.js';
const api = new WandboxAPI();
Get compilers list:
await api.getCompilersList();
Find best compiler by language name:
// By language name:
await api.findBestCompiler('javascript');
await api.findBestCompiler('Rust', 0.75);
// By file extension:
await api.findBestCompiler('py', 0.2);
await api.findBestCompiler('cs');
Info: The
rate
parameter in the options must be in this following condition: 0 < rate ≤ 1
Compile a code from string:
Note: The empty array is Stdin (Standard Input). If there is no input for the code, simply use an empty array.
- Using compiler name only:
await api.compileFromString(
{ name: 'nodejs-v16.14.0' }, `console.log('Hello world!');`, []
);
- Using the method findBestCompiler():
const compilers = await api.findBestCompiler('javascript');
await api.compileFromString(
compilers[index], `console.log('Hello world!');`, []
);
Compile a code from a file (using fs#readFileSync
):
Note: The empty array is Stdin (Standard Input). If there is no input for the code, simply use an empty array.
- Using compiler name only:
await api.compileFromFile(
{ name: 'typescript-4.2.4' }, `/path/to/the/file.ts`, []
);
- Using the method findBestCompiler():
const compilers = await api.findBestCompiler('typescript');
await api.compileFromFile(
compilers[index], `/path/to/the/file.ts`, []
);
Get sponsors:
await api.getSponsors();
Find a template by compiler name:
await api.findTemplate('gcc');
await api.findTemplate('clang');
Example: C++ "Hello World!":
Create a new C++ file: (*.cpp
)
#include <iostream>
int main() {
std::cout << "Hello World!";
return 0;
}
Create a new wrapper and compile the file code:
const api = new WandboxAPI();
const compilers = await api.findBestCompiler('c++', 0.5);
const output = await api.compileFromFile(
compilers[0], `/path/to/the/cpp/file.cpp`
);
console.log(output);
Output from the console (JSON format):
{
status: '0',
compiler_output: '',
compiler_error: '',
compiler_message: '',
program_output: 'Hello World!',
program_error: '',
program_message: 'Hello World!'
}
License
GPL-3.0, General Public License v3.0.