1.5.3 • Published 2 years ago

@00sukhjeet00/compilerjs v1.5.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

CompilerJs is Node JS library use to compile code for programming languages like C/C++, Java, Python.

In order to compile any programming language , you need to first have the compiler for that programming language in the server machine.

const  compilerJs  =  require('@00sukhjeet00/compilerjs');

compilerJs.init();

init() creates a folder named code in your project directory which is used for storage purpose.

Before using other methods , make sure to call init() method.

//Implementation for windows

const  envData  =  { ext :  "g++",options:{timeout:5000}}  // (uses g++ command to compile )

//Implementation for Linux and Mac OS(Timeout functionlity is not implemented)

const  envData  =  { ext :  "gcc", options:{timeout:5000}  }  // ( uses gcc command to compile )

compilerJs.compileCPP(envData  ,  code  ,(data)=>  {

console.log(data)

//data.error = error message

//data.output = output value

})
//Implementation for windows Linux and Mac OS(Timeout functionlity is not implemented)

const  envData  =  { ext :  "g++",options:{timeout:5000}}  // (uses g++ command to compile )

//Implementation for Linux and Mac OS(Timeout functionlity is not implemented)

const  envData  =  { ext :  "gcc"  ,options:{timeout:5000}};  // ( uses gcc command to compile )

compilerJs.compileCPPWithInput(envData  ,  code  ,  input  ,  (data)=>  {

console.log(data);

});
var  envData  =  { ext:"java"  ,options:{timeout:5000}  };

compilerJs.compileJava(  envData  ,  code  ,(data)=>{

console.log(data);

});
const  envData  =  { ext:"java"  ,options:{timeout:5000}  };

compilerJs.compileJavaWithInput(  envData  ,  code  ,  input  ,(data)=>{

console.log(data);

});
const  envData  =  { ext:"py"  ,options:{timeout:5000}  };

compilerJs.compilePython(  envData  ,  code  ,(data)=>{

console.log(data);

});
const  envData  =  { ext:"py"  options: {timeout:5000}  };

compilerJs.compilePythonWithInput(  envData  ,  code  ,  input  ,(data)=>{

console.log(data);

});

Timeout help to run program for particular time (in ms). It support window and linux system. Timeout can be used similarly in C/C++, Java, Python as showen below.

const  envData={ ext:  "py", options:  {timeout:5000}  }  // timeout: 5 running program for 5 sec.
const  compilerJS  =  require('@00sukhjeet00/compilerjs')

compilerJs.init()

const  envData  =  { ext:  'py', options:  { timeout:  1000  }  }

const  code=`print('hello')`

compilerJs.compilePy(envData,  code,  (data)  =>  {

if  (data.error)

console.log(data.error)

else

{

if  (data.timeout)

console.log('TLE')

else

console.log(data.out)

}

})
1.5.3

2 years ago

1.5.2

3 years ago

1.5.1

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago