Marked

Build Status codecov npm version downloads

:tennis: JavaScript code runner in JavaScript, safe with marked territory, asynchronous

Install

yarn add @sudoo/marked
# Or
npm install @sudoo/marked --save

Usage

For more examples, see JavaScript files under docs folder.

High level client

import { Marked } from '@sudoo/marked'

Marked(`import print from 'print'; print(1)`, {
    options: // options
    injects: // inject variable
    provides: {
        print: {
            default: (...contents) => {
                console.log(...contents.map((content) => content ? content.toString() : 'undefined'));
            },
        },
    },
})
    .then((result)=>/*handle result*/)
    .catch((err)=>/*handle error*/);

Low level client

import { Sandbox } from '@sudoo/marked'

const sandbox = Sandbox.create();

// use evaluator
// provide internal function

sandbox
    .provide('print', {
        default: (...contents) => {
            console.log(...contents.map((content) => content ? content.toString() : 'undefined'));
        },
    })
    .evaluate(`import print from 'print'; print(1)`)
    .then((result)=>/*handle result*/)
    .catch((err)=>/*handle error*/);