usage

Usage

To use shazi-js-compiler, you first need to import it in your project:

import { compileJs } from 'shazi-js-compiler';

or

import { compileJsSafely } from 'shazi-js-compiler';

The difference between compileJs and compileJsSafely is that compile function uses eval directly which is dangerous and can make our site easily hackable while compileJsSafely is intented to improve security.

The compileJs and compileJsSafely function takes two arguments: input and setOutputs. input is a string that represents the code to be executed and evaluated, and setOutputs is a function that is used to set the outputs of the evaluation.

Here is an example of using the compileJs function:

const [outputs, setOutputs] = useState([]);
 
compileJs('console.log(1 + 2)', setOutputs);
 
console.log(outputs);
// outputs: [3]

Here is an example of using the compileJsSafely function:

const [outputs, setOutputs] = useState([]);
 
compileJsSafely('console.log(1 + 2)', setOutputs);
 
console.log(outputs);
// outputs: [3]
Last updated on February 13, 2023