
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
string-function-exec
Advanced tools
This module provides an ability to execute stringified javascript/node.js
functions. StringFunction
module can basically used
to execute any type of javascript's string-compiled routines such as a various of regular
, anonymous
or arrow
- functions.
Note #1 This module
can be used with any existing version of node.js
and npm
.
By using npmjs.org
:
npm install string-function-exec --save
string-function-exec
module installed:
// A string containing "regular" javascript function to be executed
var fn1_s = "function f(alias, args) { return alias + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn1_s).parse_function("fn1",[1,2,3]));
// A string containing "regular" javascript function containing "anonymous" and "arrow" functions
var fn2_s = "function f(alias, args) { var f1 = function (t_param1) { return t_param1; }; \
var f2 = (t_param2, t_args) => { return t_param2 + \" \" + t_args; }; \
return f1(alias) + \" \" + f2(alias, args) + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn2_s).parse_function("fn2",[10,20,30]));
// A string containing "anonymous" javascript function to be executed
var fn3_s = "function (alias, args) { return alias.toString() + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn3_s).parse_function("fn3",[100,200,300]));
// A string containing "arrow" javascript function to be executed
var fn4_s = "(alias, args)=>{ return alias.toString() + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn4_s).parse_function("fn4",[1000,2000,3000]));
// A string containing two nested "arrow" javascript function to be executed
var fn5_s = "(alias, args) => { var f1 = (p1, p2)=>{ return p1 + \" \" + JSON.stringify(p2); }; return f1(alias, args);}";
console.log(new StringFunction(fn5_s).parse_function("fn5",[10000,20000,30000]));
// A string containing "regular" javascript function to be executed
var fn1_s = "function f(alias, args) { return alias + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn1_s).execute("fn1",[1,2,3]));
// A string containing "regular" javascript function containing "anonymous" and "arrow" functions
var fn2_s = "function f(alias, args) { var f1 = function (t_param1) { return t_param1; }; \
var f2 = (t_param2, t_args) => { return t_param2 + \" \" + t_args; }; \
return f1(alias) + \" \" + f2(alias, args) + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn2_s).execute("fn2",[10,20,30]));
// A string containing "anonymous" javascript function to be executed
var fn3_s = "function (alias, args) { return alias.toString() + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn3_s).execute("fn3",[100,200,300]));
// A string containing "arrow" javascript function to be executed
var fn4_s = "(alias, args)=>{ return alias.toString() + \" \" + JSON.stringify(args); }";
console.log(new StringFunction(fn4_s).execute("fn4",[1000,2000,3000]));
// A string containing two nested "arrow" javascript function to be executed
var fn5_s = "(alias, args) => { var f1 = (p1, p2)=>{ return p1 + \" \" + JSON.stringify(p2); }; return f1(alias, args);}";
console.log(new StringFunction(fn5_s).execute("fn5",[10000,20000,30000]));
.StringFunction
#####.StringFunction(StringFunc)
StringFunc - an input string containing function's code,
parses a stringified javascript/node.js function and returns the compiled function's code ready to be executed by using generic javascript's global.eval
function. Method parse_function
accepts an array of arguments Args
of any time for a javascript's function being executed.
console.log(new StringFunction(fn1_s).execute("fn1",[1,2,3]));
compiles and executes javascript/node.js function passed as a parameter of string type to the StringFunction
object's constructor. The method execute
accepts the list of arguments passed to a stringified function being executed. This method normally returns a value passed at the end of stringified function execution or an specific code if a compilation or execution error has occured.
'use strict'
var StringFunction = require('string-function-exec');
var sf_obj = new StringFunction("function test(p1, p2) { return p1 + p2; }");
var compiled_func = sf_obj.parse_function(10, 20);
var result = sf_obj.execute(10,20);
if (compiled_func.length > 0 && result != undefined) {
console.log("compiled function = " +
compiled_func + "\n" + "return value = " + JSON.stringify(result));
}
process.exit(0);
That's All Folks :)
Arthur V. Ratz @ Epsilon Software Development Labs.
FAQs
Compiles and executes stringified javascript's/node.js functions
The npm package string-function-exec receives a total of 68 weekly downloads. As such, string-function-exec popularity was classified as not popular.
We found that string-function-exec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.