
안전한 표현식 평가기 - CVE-2025-12735 취약점이 없는 expr-eval의 드롭인 대체
JavaScript 및 TypeScript를 위한 빠르고 가벼운 표현식 평가기.
익숙한 API, 제로 종속성, 완전한 TypeScript 지원을 갖춘 현대적인 표현식 파서입니다.
npm install safe-expr-eval
import { Parser } from 'safe-expr-eval';
const parser = new Parser();
const expr = parser.parse('2 * x + 1');
console.log(expr.evaluate({ x: 3 })); // 7
console.log(expr.evaluate({ x: 10 })); // 21
import { evaluate } from 'safe-expr-eval';
const result = evaluate('10 + 5 * 2');
console.log(result); // 20
import { compile } from 'safe-expr-eval';
const fn = compile('price * quantity * (1 - discount)');
console.log(
fn({
price: 100,
quantity: 2,
discount: 0.1
})
); // 180
+ - * / %
== != > < >= <=
and or not
&& || !
Numbers → 42, 3.14
Strings → "hello"
Booleans → true, false
Variables → price, user.name
const parser = new Parser();
parser.functions.max = Math.max;
parser.functions.min = Math.min;
parser.functions.round = Math.round;
const expr = parser.parse(
'round(max(a, b) * 1.5)'
);
console.log(
expr.evaluate({
a: 10,
b: 20
})
); // 30
const parser = new Parser();
parser.consts.PI = Math.PI;
parser.consts.TAX_RATE = 0.15;
const expr = parser.parse(
'price * (1 + TAX_RATE)'
);
console.log(
expr.evaluate({
price: 100
})
); // 115
new Parser()
parser.parse(expression)
parser.evaluate(expression, variables?)
parser.functions
parser.consts
evaluate(expression, variables?)
compile(expression)
npm test
npm run test:coverage
MIT
자세한 내용은 LICENSE 파일을 참조하세요.
풀 리퀘스트 및 기여를 환영합니다.
버그를 발견하거나 기능 요청이 있으면 이슈를 열어 주세요.
Alejandro Castrillon
GitHub: https://github.com/