remote-code-evaluator
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Remote Code Evaluator

Api for validation code submitions for javascript and dom.

Example for validating simple html and css changelles

const htmlChallenge = {
  id: '123',
  tests: [
    {
      id : "1",
      given: `document.querySelector("p").textContent`,
      expected: 'hello',
      evaluation: 'lodash.isEqual(given, expected)'
    },
    {
      id : "2",
      given: `document.querySelector("p").classList[0]`,
      expected: "color-dangoer",
      evaluation: 'lodash.includes(given, expected)'
    },
    {
      id : "3",
      given: `document.querySelector("p").textContent`,
      expected: 'hello',
      evaluation: 'lodash.isEqual(given, expected)'
    },
  ]
};

const solution = `<p class="color-danger" id="heading">hello</p>`;

validateDOM(htmlChallenge, solution).then((value) => console.log(JSON.stringify(value, null, 2)))

Example for validating javascript. Good for algorithms validation

const twoNumberSumChallenge = {
  id: '234',
  functionName: 'twoNumberSum',
  validation: `lodash.isEqual(given.sort(), expected.sort())`,
  tests: [
    {
      id: '1',
      params: [[3, 5, -4, 8, 11, 1, -1, 6], 10],
      expected: [-1, 11],
    },
    {
      id: '2',
      params: [[3, 5], 8],
      expected: [3, 5],
    },
  ],
}


const twoNumberSumSolution = `
function twoNumberSum(array, targetSum) {
   let obj = {};
   for (let i = 0; i < array.length; i++) {
     const y = targetSum - array[i];
     if (obj[y]) return [y, array[i]];
     else obj[array[i]] = true;
   }
   return [];
 }
 `;

 validate(twoNumberSumChallenge, twoNumberSumSolution).then(value => {
  console.log(JSON.stringify(value, null, 2));
 })

Readme

Keywords

none

Package Sidebar

Install

npm i remote-code-evaluator

Weekly Downloads

2

Version

0.2.0

License

MIT

Unpacked Size

32.7 kB

Total Files

16

Last publish

Collaborators

  • jose_aburto