Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
tio.js
Advanced tools
Readme
A small TypeScript library that lets you evaluate code in a sandboxed environment everywhere with TryItOnline.
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.
In your code:
import tio from 'tio.js'
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
// }
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
// }
// 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
// }
// 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
// }
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
// }
If you want to support this project, consider donating! ❤
FAQs
A small TypeScript library that lets you evaluate code in a sandboxed environment everywhere with TryItOnline.
The npm package tio.js receives a total of 67 weekly downloads. As such, tio.js popularity was classified as not popular.
We found that tio.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.