@adhikari_mithun/function_evaluator 中文文档教程
function_evaluator
将给定字符串作为函数求值的包
此模块是一种将字符串内容作为表达式求值的简单方法。 将非字符串传递给此模块会引发错误。
下载
它发布在节点包管理器(npm)上。 要安装,请执行:
npm i @adhikari_mithun/function_evaluator
用法
var evaluate = require('@adhikari_mithun/function_evaluator')
var res = _evaluate(content,callback)
可以使用以下选项:
content (String): 要评估的内容
callback ( Function) : 表达式时要调用的函数 被评估或抛出一些错误。
Example
<代码> var evaluate = require('@adhikari_mithun/function_evaluator')
var res = evaluate('let m = 123; exports.x = x',function(res,err){ // => res === { x: 123 } });
<代码> res = evaluate('module.exports = function () { return 123 }',function(res,err){ // => 资源()===123 });
<代码> res = evaluate(13,function(res,err){ // => err === "这个表达式只需要字符串,不需要其他" });
function_evaluator
A package that evaluates a given string as function
This module is a simple way to evaluate a string content as an expression. Passing other than string to this module throws an error.
Download
It is published on node package manager (npm). To install, do:
npm i @adhikari_mithun/function_evaluator
Usage
var evaluate = require('@adhikari_mithun/function_evaluator')
var res = _evaluate(content,callback)
The following options are available:
content (String): the content to be evaluated
callback (Function) : the function to be called when the expression is evaluated or some error is thrown.
Example
var evaluate = require('@adhikari_mithun/function_evaluator')
var res = evaluate('let m = 123; exports.x = x',function(res,err){ // => res === { x: 123 } });
res = evaluate('module.exports = function () { return 123 }',function(res,err){ // => res() === 123 });
res = evaluate(13,function(res,err){ // => err === "This expression requires only string and not other" });