Socket
Socket
Sign inDemoInstall

@00sukhjeet00/compilerjs

Package Overview
Dependencies
1
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @00sukhjeet00/compilerjs

Code Compiling library


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
52.5 kB
Created
Weekly downloads
 

Readme

Source

CompilerJs

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

Setting Up Compilers

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

Documentation
1) Require compilerJs

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.

2) C and C++

//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

})

3) C and C++ with inputs

//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);

});

4) Java

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

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

console.log(data);

});

5) Java with inputs

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

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

console.log(data);

});

6) Python

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

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

console.log(data);

});

7) Python with inputs

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

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

console.log(data);

});

Timeout functionality

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.

Demo Code

Python:

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)

}

})

Similar code structure for other languages

Keywords

FAQs

Last updated on 15 Oct 2022

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