Skip to content

A small TypeScript library that lets you evaluate code in a sandboxed environment everywhere with TryItOnline.

License

Notifications You must be signed in to change notification settings

null8626/tio.js

Repository files navigation

A small TypeScript library that lets you evaluate code in a sandboxed environment everywhere with TryItOnline.

Supported languages

Before getting to the examples, please note that tio.js supports a wide variety of programming languages. These programming languages contain their own IDs that can be used in customizing the programming language to use.

For example javascript-node is for running JavaScript in a Node.js runtime, python3 is for running in a Python 3 environment, etc.

In code, these can be retrieved programmatically by using:

console.log(tio.languages)
// => ['05ab1e', '1l-a', '1l-aoi', '2dfuck', ...]

Therefore, here are the full list of supported programming languages alongside with their IDs in alphabetical order for your convenience.

Practical programming languages (260)
Name ID
ABC abc
ABC-assembler abc-assembler
Ada (GNAT) ada-gnat
Agda agda
ALGOL 68 (Genie) algol68g
Alice ML aliceml
APL (Dyalog Unicode) apl-dyalog
APL (Dyalog Classic) apl-dyalog-classic
APL (Dyalog Extended) apl-dyalog-extended
APL (dzaima/APL) apl-dzaima
APL (ngn/apl) apl-ngn
Appleseed appleseed
ASPeRiX asperix
Assembly (as, x64, Linux) assembly-as
Assembly (fasm, x64, Linux) assembly-fasm
Assembly (gcc, x64, Linux) assembly-gcc
Assembly (JWasm, x64, Linux) assembly-jwasm
Assembly (nasm, x64, Linux) assembly-nasm
ATS2 ats2
Attache attache
AWK awk
Bash bash
bc bc
BeanShell beanshell
Boo boo
bosh bosh
Bracmat bracmat
Brat brat
C (clang) c-clang
C (gcc) c-gcc
C (tcc) c-tcc
Caboose caboose
CakeML cakeml
calc (TTK) calc2
Ceylon ceylon
Charm charm
Chapel chapel
Checked C checkedc
Cheddar cheddar
CIL (Mono IL assembler) cil-mono
cixl cixl
Clean clean
CLIPS clips
Common Lisp clisp
Clojure clojure
COBOL (GNU) cobol-gnu
Cobra cobra
Coconut coconut
CoffeeScript 1 coffeescript
CoffeeScript 2 coffeescript2
C++ (clang) cpp-clang
C++ (gcc) cpp-gcc
CPY cpy
Cryptol cryptol
Crystal crystal
C# (.NET Core) cs-core
C# (Visual C# Compiler) cs-csc
C# (Visual C# Interactive Compiler) cs-csi
C# (Mono C# compiler) cs-mono
C# (Mono C# Shell) cs-mono-shell
Curry (PAKCS) curry-pakcs
Curry (Sloth) curry-sloth
Cyclone cyclone
D d
Dafny dafny
Dart dart
Dash dash
dc dc
dg dg
DScript dscript
eC ec
ecpp + C (gcc) ecpp-c
ecpp + C++ (gcc) ecpp-cpp
Dyvil dyvil
ed ed
Egel egel
ELF (x86/x64, Linux) elf
Elixir elixir
Emacs Lisp emacs-lisp
Erlang (escript) erlang-escript
es es
Euphoria 3 euphoria3
Euphoria 4 euphoria4
Factor factor
Fantom fantom
Farnsworth farnsworth
Felix felix
fish fish-shell
FOCAL-69 focal
Forth (gforth) forth-gforth
Fortran (GFortran) fortran-gfortran
F# (.NET Core) fs-core
F# (Mono) fs-mono
Funky funky
Funky 2 funky2
GAP gap
Gema gema
gnuplot gnuplot
Go go
Granule granule
Groovy groovy
Gwion gwion
HadesLang hades
Haskell haskell
Haskell 1.2 (Gofer) haskell-gofer
Haskell 98 (Hugs) haskell-hugs
Literate Haskell haskell-literate
Haxe haxe
Hobbes hobbes
Huginn huginn
Hy hy
Icon icon
Idris idris
ink ink
Io io
J j
jq jq
Jx jx
Java (JDK) java-jdk
Java (OpenJDK 8) java-openjdk
JavaScript (Babel Node) javascript-babel-node
JavaScript (Node.js) javascript-node
JavaScript (SpiderMonkey) javascript-spidermonkey
JavaScript (V8) javascript-v8
Joy joy
Julia 0.4 julia
Julia 1.0 julia1x
Julia 0.5 julia5
Julia 0.6 julia6
Julia 0.7 julia7
K (Kona) k-kona
K (ngn/k) k-ngn
K (oK) k-ok
Kobeři-C koberi-c
Koka koka
Kotlin kotlin
ksh ksh
Lean lean
Lily lily
LLVM IR llvm
Lua lua
Lua (LuaJIT) lua-luajit
Lua (OpenResty) lua-openresty
M4 m4
Make make
Mamba mamba
Wolfram Language (Mathematica) mathematica
Mathics mathics
Maxima maxima
Moonscript moonscript
Mouse-79 mouse
Mouse-2002 mouse2002
Mouse-83 mouse83
MUMPS mumps
MY-BASIC my-basic
Nial nial
Nim nim
Oberon-07 oberon-07
Object Pascal (FPC) object-pascal-fpc
Objective-C (clang) objective-c-clang
Objective-C (gcc) objective-c-gcc
occam-pi occam-pi
OCaml ocaml
Octave octave
Odin odin
OSH osh
Pari/GP pari-gp
Pascal (FPC) pascal-fpc
Perl 4 perl4
Perl 5 perl5
Perl 5 (cperl) perl5-cperl
Perl 6 perl6
Perl 6 (Niecza) perl6-niecza
Phoenix phoenix
PHP php
Physica physica
PicoLisp picolisp
Pike pike
PILOT (psPILOT) pilot-pspilot
PILOT (RPilot) pilot-rpilot
Pony pony
Positron positron
PostScript (xpost) postscript-xpost
PowerShell powershell
PowerShell Core powershell-core
Prolog (Ciao) prolog-ciao
Prolog (SWI) prolog-swi
Proton proton
Proton 2.0 proton2
P# ps-core
Pure pure
PureScript purescript
Python 1 python1
Python 2 python2
Python 2 (Cython) python2-cython
Python 2 (IronPython) python2-iron
Python 2 (Jython) python2-jython
Python 2 (PyPy) python2-pypy
Python 3 python3
Python 3.8 (pre-release) python38pr
Python 3 (Cython) python3-cython
Python 3 (PyPy) python3-pypy
Python 3 (Stackless) python3-stackless
Q# qs-core
R r
Racket racket
RAD rad
Rapira rapira
Reason reason
REBOL rebol
REBOL 3 rebol3
Red red
Rexx (Regina) rexx
Ring ring
rk rk
Röda roda
Ruby ruby
Rust rust
Scala scala
Chez Scheme scheme-chez
CHICKEN Scheme scheme-chicken
Gambit Scheme (gsi) scheme-gambit
Guile scheme-guile
sed 4.2.2 sed
sed sed-gnu
sfk sfk
Shnap shnap
Sidef sidef
Simula (cim) simula
SISAL sisal
Standard ML (MLton) sml-mlton
SNOBOL4 (CSNOBOL4) snobol4
Assembly (MIPS, SPIM) spim
SQLite sqlite
Squirrel squirrel
Stacked stacked
Swift swift4
Tcl tcl
tcsh tcsh
TemplAt templat
TypeScript typescript
uBASIC ubasic
Ursala ursala
Vala vala
Visual Basic .NET (.NET Core) vb-core
Visual Basic .NET (Mono) visual-basic-net-mono
Visual Basic .NET (VBC) visual-basic-net-vbc
V (vlang.io) vlang
VSL vsl
WebAssembly (WaWrapper) wasm
Wren wren
Yabasic yabasic
yash yash
B (ybc) ybc
Z3 z3
Zephyr zephyr
Zig zig
zkl zkl
Zoidberg zoidberg
Zsh zsh
Esoteric programming languages (421)
Name ID
4 4
7 7
33 33
99 99
05AB1E (legacy) 05ab1e
1L_a 1l-a
1L_AOI 1l-aoi
2DFuck 2dfuck
2L 2l
2sable 2sable
3var 3var
a-gram a-gram
A Pear Tree a-pear-tree
Acc!! accbb
Aceto aceto
Actually actually
Adapt adapt
Add++ addpp
ADJUST adjust
Agony agony
Ahead ahead
Aheui (esotope) aheui
Alchemist alchemist
Alice alice
Alice & Bob alice-bob
AlphaBeta alphabeta
Alphabetti spaghetti alphabetti-spaghetti
Alphuck alphuck
Alumin alumin
The Amnesiac From Minsk amnesiac-from-minsk
Ante ante
anyfix anyfix
ARBLE arble
Archway archway
Archway2 archway2
Arcyóu arcyou
ArnoldC arnoldc
AsciiDots asciidots
Aubergine aubergine
axo axo
Backhand backhand
Bitwise Cyclic Tag But Way Worse bctbww
Bitwise Cyclic Tag But Way Worse 2.0 bctbww2
Beam beam
Bean bean
Beatnik beatnik
Beeswax beeswax
Befunge-93 befunge
Befunge-93 (FBBI) befunge-93-fbbi
Befunge-93 (MTFI) befunge-93-mtfi
Befunge-93 (PyFunge) befunge-93-pyfunge
Befunge-96 (MTFI) befunge-96-mtfi
Befunge-97 (MTFI) befunge-97-mtfi
Befunge-98 (FBBI) befunge-98
Befunge-98 (PyFunge) befunge-98-pyfunge
Bit bit
BitBitJump bitbitjump
bitch bitch
bitch (bit-h) bitch-bith
bitch (shifty) bitch-shifty
BitChanger bitchanger
BitCycle bitcycle
Bitwise bitwise
Black (blak) blak
Binary Lambda Calculus blc
Boolfuck boolfuck
Bot Engine bot-engine
Brachylog v1 brachylog
Brachylog brachylog2
Braille braille
Brain-Flak brain-flak
Brainbash brainbash
brainbool brainbool
BrainFlump brainflump
brainfuck brainfuck
Braingolf braingolf
Brain-Flak (BrainHack) brainhack
Brainlove brainlove
BrainSpace brainspace
Brian & Chuck brian-chuck
Broccoli broccoli
Bubblegum bubblegum
Burlesque burlesque
BuzzFizz buzzfizz
Bitwise Fuckery bwfuckery
Canvas canvas
Cardinal cardinal
Carol & Dave carol-dave
Carrot carrot
Cascade cascade
Catholicon catholicon
Cauliflower cauliflower
Ceres ceres
Chain chain
Chef chef
Changeling changeling
Charcoal charcoal
Check check
Chip chip
Cinnamon Gum cinnamon-gum
CJam cjam
Clam clam
,,, commata
Commentator commentator
Commercial commercial
Condit condit
Convex convex
Cood cood
Corea corea
COW cow
cQuents cquents
Crayon crayon
CSL csl
Cubically cubically
Cubix cubix
Curlyfrick curlyfrick
Cy cy
D2 d2
Deadfish~ deadfish-
Decimal decimal
Del|m|t delimit
Deorst deorst
Dirty dirty
Detour detour
DOBELA dobela
DOBELA (dobcon) dobela-dobcon
Dodos dodos
Dreaderef dreaderef
Drive-In Window drive-in-window
DStack dstack
eacal eacal
!@#$%^&*()_+ ecndpcaalrlp
Element element
ELVM-IR elvm-ir
Emmental emmental
Emoji emoji
Emoji-gramming emoji-gramming
Emojicode 0.5 emojicode
Emojicode emojicode6
EmojiCoder emojicoder
emotifuck emotifuck
Emotinomicon emotinomicon
(()) empty-nest
Enlist enlist
ESOPUNK esopunk
ETA eta
evil evil
Explode explode
Extended Brainfuck Type I extended-brainfuck-type-i
ExtraC extrac
face face
FALSE false
FerNANDo fernando
FEU feu
FIM++ fimpp
><> fish
Fission fission
Fission 2 fission2
Flipbit flipbit
Floater floater
Flobnar flobnar
Foam foam
Foo foo
Forget forget
Forked forked
Forte forte
Fourier fourier
FRACTRAN fractran
Fueue fueue
Funciton funciton
Functoid functoid
Fynyl fynyl
Gaia gaia
Gaot++ gaotpp
Geo geo
Glypho glypho
Glypho (shorthand) glypho-shorthand
Gol><> golfish
GolfScript golfscript
Grass grass
Grime grime
GS2 gs2
hASM hasm
Haystack haystack
Half-Broken Car in Heavy Traffic hbcht
Hyper-Dimensional Brainfuck hdbf
Hexagony hexagony
Hodor hodor
Homespring homespring
Hexadecimal Stacking Pseudo-Assembly Language hspal
Husk husk
I i
iag iag
Incident incident
INTERCAL intercal
JAEL jael
J-uby j-uby
Japt japt
Jelly jelly
Jellyfish jellyfish
kavod kavod
Keg keg
Kipple (cipple) kipple-cipple
Klein klein
krrp krrp
l33t l33t
Labyrinth labyrinth
Lean Mean Bean Machine lmbm
LNUSP lnusp
Locksmith locksmith
Logicode logicode
LOLCODE lolcode
Lost lost
LOWER lower
Ly ly
M m
MachineCode machinecode
Malbolge malbolge
Malbolge Unshackled malbolge-unshackled
MarioLANG mariolang
Mascarpone mascarpone
MathGolf mathgolf
MATL matl
Maverick maverick
MaybeLater maybelater
Memory GAP memory-gap
MiLambda milambda
Milky Way milky-way
MineFriff minefriff
Minimal-2D minimal-2d
miniML miniml
Minkolang minkolang
Mirror mirror
Momema momema
Monkeys monkeys
Moorhens moorhens
Mornington Crescent mornington-crescent
µ6 mu6
Muriel muriel
MY my
nameless language nameless
Nandy nandy
Nikud nikud
Neim neim
Neutrino neutrino
Nhohnhehr nhohnhehr
No no
Noether noether
NotQuiteThere nqt
NTFJ (NTFJC) ntfjc
Numberwang numberwang
Oasis oasis
ObCode obcode
Ohm ohm
Ohm v2 ohm2
OML oml
oOo CODE ooocode
Oration oration
ORK ork
Orst orst
05AB1E osabie
Pain-Flak pain-flak
Paradoc paradoc
Parenthesis Hell parenthesis-hell
Parenthetic parenthetic
PATH path
pbrain pbrain
Phooey phooey
Piet piet
PingPong pingpong
Pip pip
Pixiedust pixiedust
pl pl
PostL postl
Prelude prelude
Premier premier
Preproc preproc
Purple purple
Pushy pushy
Puzzlang puzzlang
Pyke pyke
Pylons pylons
PynTree pyn-tree
Pyon pyon
Pyramid Scheme pyramid-scheme
Pyret pyret
Pyt pyt
Pyth pyth
??? qqq
QuadR quadr
Quadrefunge-97 (MTFI) quadrefunge-97-mtfi
QuadS quads
Quarterstaff quarterstaff
Quintefunge-97 (MTFI) quintefunge-97-mtfi
Rail rail
Random Brainfuck random-brainfuck
Re:direction re-direction
Recursiva recursiva
Reng reng
ReRegex reregex
res res
ResPlicate resplicate
Reticular reticular
Retina 0.8.2 retina
Retina retina1
RETURN return
Rockstar rockstar
ROOP roop
Ropy ropy
Rotor rotor
RProgN rprogn
RProgN 2 rprogn-2
Runic Enchantments runic
Rutger rutger
Sad-Flak sad-flak
Sakura sakura
Symbolic Brainfuck sbf
Seed seed
Septefunge-97 (MTFI) septefunge-97-mtfi
Seriously seriously
Sesos sesos
Set set
Sexefunge-97 (MTFI) sexefunge-97-mtfi
ShapeScript shapescript
shortC shortc
Shove shove
;#+ shp
Shtriped shtriped
S.I.L.O.S silos
Silberjoder silberjoder
Simplefunge simplefunge
Implicit simplestack
Simplex simplex
Sisi sisi
/// slashes
Self-modifying Brainfuck smbf
smol smol
Snails snails
Snowman snowman
SNUSP (Modular) snusp
SNUSP (Bloated) snusp-bloated
SNUSP (Snuspi) snuspi
Somme somme
Spaced spaced
Shakespeare Programming Language spl
Spoon spoon
Stack Cats stackcats
*><> starfish
Starry starry
Stax stax
Stencil stencil
Stones stones
str str
Straw straw
Subskin subskin
Sumerian sumerian
SuperMarioLang supermariolang
Super Stack! superstack
Surface surface
Swap swap
Syms syms
Symbolic Python symbolic-python
TacO taco
Tampio (functional) tampio
Tampio (imperative) tampioi
Tamsin tamsin
TapeBagel tapebagel
Taxi taxi
Templates Considered Harmful templates
Thing thing
Threead threead
Thue thue
Thutu thutu
Tidy tidy
TinCan tincan
tinyBF tinybf
tinylisp tinylisp
Tir tir
TIS tis
Toi toi
Turing Machine But Way Worse tmbww
TRANSCRIPT transcript
Trefunge-97 (MTFI) trefunge-97-mtfi
Trefunge-98 (PyFunge) trefunge-98-pyfunge
Triangular triangular
Triangularity triangularity
Trigger trigger
Triple Threat triple-threat
TrumpScript trumpscript
Turtlèd turtled
Underload underload
Unefunge-97 (MTFI) unefunge-97-mtfi
Unefunge-98 (PyFunge) unefunge-98-pyfunge
Unicat unicat
Unlambda unlambda
Uno uno
Unreadable unreadable
V (vim) v
V (FMota) v-fmota
VAR var
Verbosity verbosity
Verbosity v2 verbosity2
Versert versert
Vitsy vitsy
The Waterfall Model waterfall
Whirl whirl
Whispers v1 whispers
Whispers v2 whispers2
Whitespace whitespace
Width width
Wierd (John's) wierd
Wise wise
Woefully woefully
wsf wsf
Wumpus wumpus
W.Y.A.L.H.E.I.N. wyalhein
xEec xeec
xeraph xeraph
YABALL yaball
yup yup
Z80Golf z80golf

Examples

In your code:

import tio from 'tio.js'
Evaluating a code
const response = await tio('console.log("Hello, World!");')

console.log(response)
// =>
// {
//   output: 'Hello, World!\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }
Evaluating a code from another programming language
let response = await tio('print("Hello, World!")', {
  language: 'python3'
})

console.log(response)
// =>
// {
//   output: 'Hello, World!\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }

// tio.js uses 'javascript-node' by default.
tio.defaultLanguage = 'python3'

response = await tio('print("Hello, World!")')

console.log(response)
// =>
// {
//   output: 'Hello, World!\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }
Surpressing infinite loops with timeouts
// make the response timeout after 10000 ms (10 seconds).
let response = await tio('for (;;);', {
  timeout: 10000
})

console.log(response)
// =>
// {
//   output: 'Request timed out after 10000ms',
//   timedOut: true,
//   realTime: 10,
//   userTime: 10,
//   sysTime: 10,
//   CPUshare: 0,
//   exitCode: 0
// }

// tio.js uses Infinity (no timeouts) by default.
tio.defaultTimeout = 10000

response = await tio('for (;;);')

console.log(response)
// =>
// {
//   output: 'Request timed out after 10000ms',
//   timedOut: true,
//   realTime: 10,
//   userTime: 10,
//   sysTime: 10,
//   CPUshare: 0,
//   exitCode: 0
// }
Passing in extra compiler flags
// this only works in compiled languages. (e.g rust)
const code = `
fn main() {
  #[cfg(feature = "something")]
  println!("this will be printed");
}
`

// compiled as 'rustc code.rs --cfg feature="something"'
let response = await tio(code, {
  language: 'rust',
  cflags: ['--cfg', 'feature="something"']
})

console.log(response)
// =>
// {
//   output: 'this will be printed\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }

// tio.js uses [] (no extra compiler flags) by default.
tio.defaultCflags = ['--cfg', 'feature="something"']

response = await tio(code, {
  language: 'rust'
})

console.log(response)
// =>
// {
//   output: 'this will be printed\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }
Passing in command-line arguments
let response = await tio('console.log(process.argv.slice(2).join(", "))', {
  argv: ['Hello', 'World!']
})

console.log(response)
// =>
// {
//   output: 'Hello, World!\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }

// tio.js uses [] (no command-line arguments) by default.
tio.defaultArgv = ['Hello', 'World!']

response = await tio('console.log(process.argv.slice(2).join(", "))')

console.log(response)
// =>
// {
//   output: 'Hello, World!\n',
//   timedOut: false,
//   realTime: 0.069,
//   userTime: 0.069,
//   sysTime: 0.069,
//   CPUshare: 99.99,
//   exitCode: 0
// }

Donations

If you want to support this project, consider donating! ❤

ko-fi