ys

yuan-sandbox

Run target function from the object environment and log error information into standard console without interrupting current process.

Showing:

Popularity

Downloads/wk

7

Maintenance

No Maintenance Data Available

Package

Dependencies

1

Size (min+gzip)

0.3KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

yuan-sandbox

yuan-sandbox is a module developed with TypeScript and runs under browser environment or node.

ATTENTION: This module is developed in AMD styled, NOT CommonJs style!

How to use?

Node

Just enter your program directory, run npm init if you don't have a package.json file.

When your package.json file is ready, run npm install yuan-sandbox --save to install our module.

In your own code, use yuan-sandbox like this:

var CE = require("yuan-sandbox");
new CE.Sandbox(obj).Exec(obj.LOG,test);// obj is an object that contains a method called LOG(), test is the parameter you want to pass to the function.

After all your files ready, use node to test nad enjoy!

Browser

We strongly recommend you to use requirejs to manage your JavaScript modules.

use the AMD style code like:

define("Script/yuan-sandbox",function(CE){
    // use as what it looks like in node environment.
});

Run your web application, enjoy debugging with yuan-sandbox!

Is it worth using?

After installing 'yuan-sandbox' module in the project directory, run test.js with node and you may get the following output:

bash-3.2$ node test.js
Error: Not A Number
    at Demo.LOG (/Users/dong/Desktop/test.js:9:24)
    at Sandbox.Exec (/Users/dong/Desktop/node_modules/yuan-sandbox/index.js:26:20)
    at Object.<anonymous> (/Users/dong/Desktop/test.js:15:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)

= Section A executed. =

/Users/dong/Desktop/test.js:9
            else throw new Error("Not A Number");
                 ^

Error: Not A Number
    at Demo.LOG (/Users/dong/Desktop/test.js:9:24)
    at Object.<anonymous> (/Users/dong/Desktop/test.js:17:5)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
bash-3.2$

test.js file content:

var CE = require("yuan-sandbox");
var Demo = (function () {
        function Demo(val) {
            this.value = val;
        }
        Demo.prototype.LOG = function (numstr) {
            if(parseInt(numstr))
                console.log(this.value + numstr);
            else throw new Error("Not A Number");
        };
        return Demo;
    }());
var obj = new Demo("Ziyuan is my pride.");
var test = "?32";
new CE.Sandbox(obj).Exec(obj.LOG,test);
console.log("\n= Section A executed. =\n");
obj.LOG(test);
console.log("\n= Section B executed. Program proceeding. =\n");
new CE.Sandbox(obj).Exec(obj.LOG,test);
console.log("\n= Section A executed. =\n");

Apparently, the program stopped after obj.Log(test); execution. According to our demo, the function passed to Sandbox encountered with an error, but the program keeps going. This is the thing we want it to do.

Have a try!

Good news here!

Any body can try it out in RunKit + npm environment with this example code:https://runkit.com/588af21dd5054b00140e448e/588af21dd5054b00140e448f. Have a try!

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100