npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ve-compiler

v1.0.6

Published

VE-Compiler is a versatile JavaScript package that offers a solution for compiling code snippets written in various programming languages, including C++, Java, JavaScript, Python, and C. It simplifies the compilation process by providing a unified interfa

Downloads

17

Readme

VE-Compiler

Description

VE-Compiler is a versatile JavaScript package that offers a solution for compiling code snippets written in various programming languages, including C++, Java, JavaScript, Python, and C. It simplifies the compilation process by providing a unified interface for compiling code across different languages. The package generates unique identifiers for each compilation job, saves code snippets to files, invokes the appropriate compiler modules, and returns the compilation outputs.

Features

  • Multi-Language Support: Compile code written in C++, Java, JavaScript, Python, and C.
  • Unified Interface: Simplified API for compiling code snippets in different languages.
  • Error Handling: Detailed error messages are provided in case of compilation errors.
  • Output Generation: Returns compiled output for successful compilations.
  • Customizable: Easily configurable for specific requirements.
  • Cross-Platform Compatibility: Works seamlessly across different platforms and environments.

Installation

You can install the package via npm:

npm install ve-compiler

Usage

Language codes-

"c" , "cpp" , "js" , "py" , "java"

Example with Pure Node.js

const { CompileFile } = require('ve-compiler');


CompileFile(
    "c",
    '#include <stdio.h>\n int main() {\n  printf("Hello, World! c ");\n  return 0;\n}'
  );

Example with React + Node Server + Monaco Editor

In this example, we'll demonstrate how to integrate the VE-Compiler package with a React frontend using Monaco Editor, and a Node.js backend to handle compilation requests.

Frontend (React)

import React, { useState, useEffect } from 'react';
import { Editor } from '@monaco-editor/react';
import axios from 'axios';

function App() {
  const [code, setCode] = useState(localStorage.getItem('code') || '');
  const [output, setOutput] = useState('');
  const [language, setLanguage] = useState('javascript'); // Default language

  useEffect(() => {
    localStorage.setItem('code', code);
  }, [code]);

  const handleEditorChange = (value, event) => {
    setCode(value);
  };

  const handleLanguageChange = (event) => {
    const selectedLanguage = event.target.value;
    setLanguage(selectedLanguage);
  };

  const runCode = async () => {
    try {
      // Convert language to 'js' if it's 'javascript'
      const lang = language === 'javascript' ? 'js' : language;
      const response = await axios.post('http://localhost:4000/compile', {
        code,
        language: lang,
      });

      setOutput(response.data.message);
    } catch (error) {
      setOutput(error.toString());
    }
  };

  return (
    <div className="App">
      <div style={{ display: 'flex' }}>
        <div style={{ flex: 1, border: '1px solid #ccc', borderRadius: '5px', padding: '10px' }}>
          <div style={{ marginBottom: '10px', display: 'flex', alignItems: 'center' }}>
            <label style={{ marginRight: '10px' }}>Select Language:</label>
            <select value={language} onChange={handleLanguageChange}>
              <option value="javascript">JavaScript</option>
              <option value="c">C</option>
            </select>
          </div>
          <div style={{ border: '1px solid #ccc', borderRadius: '5px' }}>
            <Editor
              height="80vh"
              language={language}
              value={code}
              onChange={handleEditorChange}
            />
          </div>
          <button onClick={runCode}>Run</button>
        </div>
        <div style={{ flex: 1, marginLeft: '20px' }}>
          <h2>Output:</h2>
          <div style={{ border: '1px solid #ccc', padding: '10px', minHeight: '80vh' }}>
            {output.split('\n').map((line, index) => (
              <React.Fragment key={index}>
                {line}
                <br />
              </React.Fragment>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}

export default App;

Backend (Node.js)

const express = require('express');
const { CompileFile } = require('ve_compiler-test-1');
const cors = require('cors');

const app = express();
const PORT = 4000;

app.use(cors());
app.use(express.json());

app.post('/compile', async (req, res) => {
  const { code, language } = req.body;

  try {
    const output = await CompileFile(language, code);
    // Extract stdout from the output object
    const stdout = output.stdout || '';
    res.json({ message: stdout });
  } catch (error) {
    res.status(500).json({ error: error.toString() });
  }
});

app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}`);
});

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Important!

While using java compiler we request you to send the class name as - "Main" for it to function properly, we will enhance this feature in further updates.