
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@idooel/expression
Advanced tools
一个轻量、安全且强大的 JavaScript/TypeScript 表达式求值引擎。它允许你针对数据上下文解析和计算字符串表达式(例如 `user.age > 18 && status === 'active'`),支持 AST 缓存和严格安全模式。
一个轻量、安全且强大的 JavaScript/TypeScript 表达式求值引擎。它允许你针对数据上下文解析和计算字符串表达式(例如 user.age > 18 && status === 'active'),支持 AST 缓存和严格安全模式。
它旨在作为低代码平台、动态表单规则和数据绑定系统的逻辑处理引擎。
eval() 或 new Function()。采用自定义解析器和解释器实现。constructor、__proto__)。支持严格模式。# pnpm
pnpm add @idooel/expression
# npm
npm install @idooel/expression
# yarn
yarn add @idooel/expression
使用 parse 进行一次性求值。
import { parse } from '@idooel/expression'
const context = {
user: {
name: 'Alice',
age: 25,
role: 'admin'
},
items: [10, 20, 30]
}
// 简单比较
parse('user.age >= 18', context) // true
// 逻辑运算
parse('user.role === "admin" && items.length > 0', context) // true
// 算术运算
parse('items[0] * 2 + 5', context) // 25
// 三元运算
parse('user.age > 18 ? "成年人" : "未成年"', context) // "成年人"
如果你需要多次使用不同的数据对同一个表达式进行求值,请使用 compile。这样只会解析一次 AST。
import { compile } from '@idooel/expression'
// 预编译表达式
const isAdult = compile('age >= 18')
console.log(isAdult({ age: 20 })) // true
console.log(isAdult({ age: 10 })) // false
默认情况下,访问未定义的属性会返回 undefined。启用 strict 模式后,访问不存在的属性将抛出错误。
import { parse } from '@idooel/expression'
try {
parse('user.address.city', { user: {} }, { strict: true })
} catch (e) {
// 抛出 EvalError: Failed to access property "city": ...
console.error(e.message)
}
null, undefineda.b, a['b'], arr[0]+, -, *, /, %==, !=, ===, !==, >, <, >=, <=&&, ||, !, ?? (空值合并)fn(a, b), obj.method()[1, 2, 3], { a: 1, b: 2 }condition ? trueVal : falseVal引擎显式禁止访问以下属性,以防止原型污染攻击和任意代码执行漏洞(这是 eval() 类方案的常见问题):
constructor__proto__prototypeISC
FAQs
一个轻量、安全且强大的 JavaScript/TypeScript 表达式求值引擎。它允许你针对数据上下文解析和计算字符串表达式(例如 `user.age > 18 && status === 'active'`),支持 AST 缓存和严格安全模式。
We found that @idooel/expression demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.