static-eval

WebJar for static-eval

Лицензия

Лицензия

MIT
Группа

Группа

org.webjars.npm
Идентификатор

Идентификатор

static-eval
Последняя версия

Последняя версия

2.1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

static-eval
WebJar for static-eval
Ссылка на сайт

Ссылка на сайт

https://www.webjars.org
Система контроля версий

Система контроля версий

https://github.com/browserify/static-eval

Скачать static-eval

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.webjars.npm/static-eval/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>static-eval</artifactId>
    <version>2.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/static-eval/
implementation 'org.webjars.npm:static-eval:2.1.0'
// https://jarcasting.com/artifacts/org.webjars.npm/static-eval/
implementation ("org.webjars.npm:static-eval:2.1.0")
'org.webjars.npm:static-eval:jar:2.1.0'
<dependency org="org.webjars.npm" name="static-eval" rev="2.1.0">
  <artifact name="static-eval" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='static-eval', version='2.1.0')
)
libraryDependencies += "org.webjars.npm" % "static-eval" % "2.1.0"
[org.webjars.npm/static-eval "2.1.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
org.webjars.npm : escodegen jar [1.11.1,2)

Модули Проекта

Данный проект не имеет модулей.

static-eval

evaluate statically-analyzable expressions

testling badge

build status

security

static-eval is like eval. It is intended for use in build scripts and code transformations, doing some evaluation at build time—it is NOT suitable for handling arbitrary untrusted user input. Malicious user input can execute arbitrary code.

example

var evaluate = require('static-eval');
var parse = require('esprima').parse;

var src = process.argv[2];
var ast = parse(src).body[0].expression;

console.log(evaluate(ast));

If you stick to simple expressions, the result is statically analyzable:

$ node '7*8+9'
65
$ node eval.js '[1,2,3+4*5-(5*11)]'
[ 1, 2, -32 ]

but if you use statements, undeclared identifiers, or syntax, the result is no longer statically analyzable and evaluate() returns undefined:

$ node eval.js '1+2+3*n'
undefined
$ node eval.js 'x=5; x*2'
undefined
$ node eval.js '5-4*3'
-7

You can also declare variables and functions to use in the static evaluation:

var evaluate = require('static-eval');
var parse = require('esprima').parse;

var src = '[1,2,3+4*10+n,foo(3+5),obj[""+"x"].y]';
var ast = parse(src).body[0].expression;

console.log(evaluate(ast, {
    n: 6,
    foo: function (x) { return x * 100 },
    obj: { x: { y: 555 } }
}));

methods

var evaluate = require('static-eval');

evaluate(ast, vars={})

Evaluate the esprima-parsed abstract syntax tree object ast with an optional collection of variables vars to use in the static expression resolution.

If the expression contained in ast can't be statically resolved, evaluate() returns undefined.

install

With npm do:

npm install static-eval

license

MIT

org.webjars.npm

Версии библиотеки

Версия
2.1.0
2.0.3
2.0.2
2.0.0
0.2.4
0.2.0