0.5.4 • Published 1 year ago

@voidvoxel/parse-function v0.5.4

Weekly downloads
-
License
MPL-2.0
Repository
-
Last release
1 year ago

@voidvoxel/parse-function

Known Vulnerabilities

Get the body of a JavaScript function's source code as a string.

Installation

npm i @voidvoxel/parse-function

Usage

// Import `@voidvoxel/parse-function`.
import parseFunction from "@voidvoxel/parse-function";
/* OR */
const parseFunction = require("@voidvoxel/parse-function");


// Parse a function from a string.
const add = parseFunction(`function add (x, y) { return x + y; }`);

// Call the parsed function.
console.log(add(400, 20));


// Create a function to parse.
function helloWorld () {
    console.log("Hello, world!");
}


// Run the function to see what it normally does.
helloWorld();

// Parse the function.
const ast = parseFunction.ast(helloWorld);

// Evaluate the body of the function to run the code directly.
// Normally, `eval` is a security risk, but it's okay to use for testing
// purposes so long as it's not within a production environment.
eval(ast.body);
0.5.4

1 year ago

0.5.4-alpha

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.1

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago