Socket
Socket
Sign inDemoInstall

tio.js

Package Overview
Dependencies
0
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tio.js

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


Version published
Weekly downloads
67
increased by3250%
Maintainers
1
Install size
143 kB
Created
Weekly downloads
 

Readme

Source

tio.js npm npm downloads ko-fi

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)
NameID
ABCabc
ABC-assemblerabc-assembler
Ada (GNAT)ada-gnat
Agdaagda
ALGOL 68 (Genie)algol68g
Alice MLaliceml
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
Appleseedappleseed
ASPeRiXasperix
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
ATS2ats2
Attacheattache
AWKawk
Bashbash
bcbc
BeanShellbeanshell
Booboo
boshbosh
Bracmatbracmat
Bratbrat
C (clang)c-clang
C (gcc)c-gcc
C (tcc)c-tcc
Caboosecaboose
CakeMLcakeml
calc (TTK)calc2
Ceylonceylon
Charmcharm
Chapelchapel
Checked Ccheckedc
Cheddarcheddar
CIL (Mono IL assembler)cil-mono
cixlcixl
Cleanclean
CLIPSclips
Common Lispclisp
Clojureclojure
COBOL (GNU)cobol-gnu
Cobracobra
Coconutcoconut
CoffeeScript 1coffeescript
CoffeeScript 2coffeescript2
C++ (clang)cpp-clang
C++ (gcc)cpp-gcc
CPYcpy
Cryptolcryptol
Crystalcrystal
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
Cyclonecyclone
Dd
Dafnydafny
Dartdart
Dashdash
dcdc
dgdg
DScriptdscript
eCec
ecpp + C (gcc)ecpp-c
ecpp + C++ (gcc)ecpp-cpp
Dyvildyvil
eded
Egelegel
ELF (x86/x64, Linux)elf
Elixirelixir
Emacs Lispemacs-lisp
Erlang (escript)erlang-escript
eses
Euphoria 3euphoria3
Euphoria 4euphoria4
Factorfactor
Fantomfantom
Farnsworthfarnsworth
Felixfelix
fishfish-shell
FOCAL-69focal
Forth (gforth)forth-gforth
Fortran (GFortran)fortran-gfortran
F# (.NET Core)fs-core
F# (Mono)fs-mono
Funkyfunky
Funky 2funky2
GAPgap
Gemagema
gnuplotgnuplot
Gogo
Granulegranule
Groovygroovy
Gwiongwion
HadesLanghades
Haskellhaskell
Haskell 1.2 (Gofer)haskell-gofer
Haskell 98 (Hugs)haskell-hugs
Literate Haskellhaskell-literate
Haxehaxe
Hobbeshobbes
Huginnhuginn
Hyhy
Iconicon
Idrisidris
inkink
Ioio
Jj
jqjq
Jxjx
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
Joyjoy
Julia 0.4julia
Julia 1.0julia1x
Julia 0.5julia5
Julia 0.6julia6
Julia 0.7julia7
K (Kona)k-kona
K (ngn/k)k-ngn
K (oK)k-ok
Kobeři-Ckoberi-c
Kokakoka
Kotlinkotlin
kshksh
Leanlean
Lilylily
LLVM IRllvm
Lualua
Lua (LuaJIT)lua-luajit
Lua (OpenResty)lua-openresty
M4m4
Makemake
Mambamamba
Wolfram Language (Mathematica)mathematica
Mathicsmathics
Maximamaxima
Moonscriptmoonscript
Mouse-79mouse
Mouse-2002mouse2002
Mouse-83mouse83
MUMPSmumps
MY-BASICmy-basic
Nialnial
Nimnim
Oberon-07oberon-07
Object Pascal (FPC)object-pascal-fpc
Objective-C (clang)objective-c-clang
Objective-C (gcc)objective-c-gcc
occam-pioccam-pi
OCamlocaml
Octaveoctave
Odinodin
OSHosh
Pari/GPpari-gp
Pascal (FPC)pascal-fpc
Perl 4perl4
Perl 5perl5
Perl 5 (cperl)perl5-cperl
Perl 6perl6
Perl 6 (Niecza)perl6-niecza
Phoenixphoenix
PHPphp
Physicaphysica
PicoLisppicolisp
Pikepike
PILOT (psPILOT)pilot-pspilot
PILOT (RPilot)pilot-rpilot
Ponypony
Positronpositron
PostScript (xpost)postscript-xpost
PowerShellpowershell
PowerShell Corepowershell-core
Prolog (Ciao)prolog-ciao
Prolog (SWI)prolog-swi
Protonproton
Proton 2.0proton2
P#ps-core
Purepure
PureScriptpurescript
Python 1python1
Python 2python2
Python 2 (Cython)python2-cython
Python 2 (IronPython)python2-iron
Python 2 (Jython)python2-jython
Python 2 (PyPy)python2-pypy
Python 3python3
Python 3.8 (pre-release)python38pr
Python 3 (Cython)python3-cython
Python 3 (PyPy)python3-pypy
Python 3 (Stackless)python3-stackless
Q#qs-core
Rr
Racketracket
RADrad
Rapirarapira
Reasonreason
REBOLrebol
REBOL 3rebol3
Redred
Rexx (Regina)rexx
Ringring
rkrk
Rödaroda
Rubyruby
Rustrust
Scalascala
Chez Schemescheme-chez
CHICKEN Schemescheme-chicken
Gambit Scheme (gsi)scheme-gambit
Guilescheme-guile
sed 4.2.2sed
sedsed-gnu
sfksfk
Shnapshnap
Sidefsidef
Simula (cim)simula
SISALsisal
Standard ML (MLton)sml-mlton
SNOBOL4 (CSNOBOL4)snobol4
Assembly (MIPS, SPIM)spim
SQLitesqlite
Squirrelsquirrel
Stackedstacked
Swiftswift4
Tcltcl
tcshtcsh
TemplAttemplat
TypeScripttypescript
uBASICubasic
Ursalaursala
Valavala
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
VSLvsl
WebAssembly (WaWrapper)wasm
Wrenwren
Yabasicyabasic
yashyash
B (ybc)ybc
Z3z3
Zephyrzephyr
Zigzig
zklzkl
Zoidbergzoidberg
Zshzsh
Esoteric programming languages (421)
NameID
44
77
3333
9999
05AB1E (legacy)05ab1e
1L_a1l-a
1L_AOI1l-aoi
2DFuck2dfuck
2L2l
2sable2sable
3var3var
a-grama-gram
A Pear Treea-pear-tree
Acc!!accbb
Acetoaceto
Actuallyactually
Adaptadapt
Add++addpp
ADJUSTadjust
Agonyagony
Aheadahead
Aheui (esotope)aheui
Alchemistalchemist
Alicealice
Alice & Bobalice-bob
AlphaBetaalphabeta
Alphabetti spaghettialphabetti-spaghetti
Alphuckalphuck
Aluminalumin
The Amnesiac From Minskamnesiac-from-minsk
Anteante
anyfixanyfix
ARBLEarble
Archwayarchway
Archway2archway2
Arcyóuarcyou
ArnoldCarnoldc
AsciiDotsasciidots
Aubergineaubergine
axoaxo
Backhandbackhand
Bitwise Cyclic Tag But Way Worsebctbww
Bitwise Cyclic Tag But Way Worse 2.0bctbww2
Beambeam
Beanbean
Beatnikbeatnik
Beeswaxbeeswax
Befunge-93befunge
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
Bitbit
BitBitJumpbitbitjump
bitchbitch
bitch (bit-h)bitch-bith
bitch (shifty)bitch-shifty
BitChangerbitchanger
BitCyclebitcycle
Bitwisebitwise
Black (blak)blak
Binary Lambda Calculusblc
Boolfuckboolfuck
Bot Enginebot-engine
Brachylog v1brachylog
Brachylogbrachylog2
Braillebraille
Brain-Flakbrain-flak
Brainbashbrainbash
brainboolbrainbool
BrainFlumpbrainflump
brainfuckbrainfuck
Braingolfbraingolf
Brain-Flak (BrainHack)brainhack
Brainlovebrainlove
BrainSpacebrainspace
Brian & Chuckbrian-chuck
Broccolibroccoli
Bubblegumbubblegum
Burlesqueburlesque
BuzzFizzbuzzfizz
Bitwise Fuckerybwfuckery
Canvascanvas
Cardinalcardinal
Carol & Davecarol-dave
Carrotcarrot
Cascadecascade
Catholiconcatholicon
Cauliflowercauliflower
Ceresceres
Chainchain
Chefchef
Changelingchangeling
Charcoalcharcoal
Checkcheck
Chipchip
Cinnamon Gumcinnamon-gum
CJamcjam
Clamclam
,,,commata
Commentatorcommentator
Commercialcommercial
Conditcondit
Convexconvex
Coodcood
Coreacorea
COWcow
cQuentscquents
Crayoncrayon
CSLcsl
Cubicallycubically
Cubixcubix
Curlyfrickcurlyfrick
Cycy
D2d2
Deadfish~deadfish-
Decimaldecimal
Del|m|tdelimit
Deorstdeorst
Dirtydirty
Detourdetour
DOBELAdobela
DOBELA (dobcon)dobela-dobcon
Dodosdodos
Dreaderefdreaderef
Drive-In Windowdrive-in-window
DStackdstack
eacaleacal
!@#$%^&*()_+ecndpcaalrlp
Elementelement
ELVM-IRelvm-ir
Emmentalemmental
Emojiemoji
Emoji-grammingemoji-gramming
Emojicode 0.5emojicode
Emojicodeemojicode6
EmojiCoderemojicoder
emotifuckemotifuck
Emotinomiconemotinomicon
(())empty-nest
Enlistenlist
ESOPUNKesopunk
ETAeta
evilevil
Explodeexplode
Extended Brainfuck Type Iextended-brainfuck-type-i
ExtraCextrac
faceface
FALSEfalse
FerNANDofernando
FEUfeu
FIM++fimpp
><>fish
Fissionfission
Fission 2fission2
Flipbitflipbit
Floaterfloater
Flobnarflobnar
Foamfoam
Foofoo
Forgetforget
Forkedforked
Forteforte
Fourierfourier
FRACTRANfractran
Fueuefueue
Funcitonfunciton
Functoidfunctoid
Fynylfynyl
Gaiagaia
Gaot++gaotpp
Geogeo
Glyphoglypho
Glypho (shorthand)glypho-shorthand
Gol><>golfish
GolfScriptgolfscript
Grassgrass
Grimegrime
GS2gs2
hASMhasm
Haystackhaystack
Half-Broken Car in Heavy Traffichbcht
Hyper-Dimensional Brainfuckhdbf
Hexagonyhexagony
Hodorhodor
Homespringhomespring
Hexadecimal Stacking Pseudo-Assembly Languagehspal
Huskhusk
Ii
iagiag
Incidentincident
INTERCALintercal
JAELjael
J-ubyj-uby
Japtjapt
Jellyjelly
Jellyfishjellyfish
kavodkavod
Kegkeg
Kipple (cipple)kipple-cipple
Kleinklein
krrpkrrp
l33tl33t
Labyrinthlabyrinth
Lean Mean Bean Machinelmbm
LNUSPlnusp
Locksmithlocksmith
Logicodelogicode
LOLCODElolcode
Lostlost
LOWERlower
Lyly
Mm
MachineCodemachinecode
Malbolgemalbolge
Malbolge Unshackledmalbolge-unshackled
MarioLANGmariolang
Mascarponemascarpone
MathGolfmathgolf
MATLmatl
Maverickmaverick
MaybeLatermaybelater
Memory GAPmemory-gap
MiLambdamilambda
Milky Waymilky-way
MineFriffminefriff
Minimal-2Dminimal-2d
miniMLminiml
Minkolangminkolang
Mirrormirror
Momemamomema
Monkeysmonkeys
Moorhensmoorhens
Mornington Crescentmornington-crescent
µ6mu6
Murielmuriel
MYmy
nameless languagenameless
Nandynandy
Nikudnikud
Neimneim
Neutrinoneutrino
Nhohnhehrnhohnhehr
Nono
Noethernoether
NotQuiteTherenqt
NTFJ (NTFJC)ntfjc
Numberwangnumberwang
Oasisoasis
ObCodeobcode
Ohmohm
Ohm v2ohm2
OMLoml
oOo CODEooocode
Orationoration
ORKork
Orstorst
05AB1Eosabie
Pain-Flakpain-flak
Paradocparadoc
Parenthesis Hellparenthesis-hell
Parentheticparenthetic
PATHpath
pbrainpbrain
Phooeyphooey
Pietpiet
PingPongpingpong
Pippip
Pixiedustpixiedust
plpl
PostLpostl
Preludeprelude
Premierpremier
Preprocpreproc
Purplepurple
Pushypushy
Puzzlangpuzzlang
Pykepyke
Pylonspylons
PynTreepyn-tree
Pyonpyon
Pyramid Schemepyramid-scheme
Pyretpyret
Pytpyt
Pythpyth
???qqq
QuadRquadr
Quadrefunge-97 (MTFI)quadrefunge-97-mtfi
QuadSquads
Quarterstaffquarterstaff
Quintefunge-97 (MTFI)quintefunge-97-mtfi
Railrail
Random Brainfuckrandom-brainfuck
Re:directionre-direction
Recursivarecursiva
Rengreng
ReRegexreregex
resres
ResPlicateresplicate
Reticularreticular
Retina 0.8.2retina
Retinaretina1
RETURNreturn
Rockstarrockstar
ROOProop
Ropyropy
Rotorrotor
RProgNrprogn
RProgN 2rprogn-2
Runic Enchantmentsrunic
Rutgerrutger
Sad-Flaksad-flak
Sakurasakura
Symbolic Brainfucksbf
Seedseed
Septefunge-97 (MTFI)septefunge-97-mtfi
Seriouslyseriously
Sesossesos
Setset
Sexefunge-97 (MTFI)sexefunge-97-mtfi
ShapeScriptshapescript
shortCshortc
Shoveshove
;#+shp
Shtripedshtriped
S.I.L.O.Ssilos
Silberjodersilberjoder
Simplefungesimplefunge
Implicitsimplestack
Simplexsimplex
Sisisisi
///slashes
Self-modifying Brainfucksmbf
smolsmol
Snailssnails
Snowmansnowman
SNUSP (Modular)snusp
SNUSP (Bloated)snusp-bloated
SNUSP (Snuspi)snuspi
Sommesomme
Spacedspaced
Shakespeare Programming Languagespl
Spoonspoon
Stack Catsstackcats
*><>starfish
Starrystarry
Staxstax
Stencilstencil
Stonesstones
strstr
Strawstraw
Subskinsubskin
Sumeriansumerian
SuperMarioLangsupermariolang
Super Stack!superstack
Surfacesurface
Swapswap
Symssyms
Symbolic Pythonsymbolic-python
TacOtaco
Tampio (functional)tampio
Tampio (imperative)tampioi
Tamsintamsin
TapeBageltapebagel
Taxitaxi
Templates Considered Harmfultemplates
Thingthing
Threeadthreead
Thuethue
Thututhutu
Tidytidy
TinCantincan
tinyBFtinybf
tinylisptinylisp
Tirtir
TIStis
Toitoi
Turing Machine But Way Worsetmbww
TRANSCRIPTtranscript
Trefunge-97 (MTFI)trefunge-97-mtfi
Trefunge-98 (PyFunge)trefunge-98-pyfunge
Triangulartriangular
Triangularitytriangularity
Triggertrigger
Triple Threattriple-threat
TrumpScripttrumpscript
Turtlèdturtled
Underloadunderload
Unefunge-97 (MTFI)unefunge-97-mtfi
Unefunge-98 (PyFunge)unefunge-98-pyfunge
Unicatunicat
Unlambdaunlambda
Unouno
Unreadableunreadable
V (vim)v
V (FMota)v-fmota
VARvar
Verbosityverbosity
Verbosity v2verbosity2
Versertversert
Vitsyvitsy
The Waterfall Modelwaterfall
Whirlwhirl
Whispers v1whispers
Whispers v2whispers2
Whitespacewhitespace
Widthwidth
Wierd (John's)wierd
Wisewise
Woefullywoefully
wsfwsf
Wumpuswumpus
W.Y.A.L.H.E.I.N.wyalhein
xEecxeec
xeraphxeraph
YABALLyaball
yupyup
Z80Golfz80golf

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

Keywords

FAQs

Last updated on 25 Apr 2024

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc