How to use dsh-tool-calculator
Safe math expression evaluator, zero-dependency recursive-descent parser.
This article is auto-derived from indexed fields (wiki / faq / compatibility_json), not freshly AI-generated.
This article is derived from the plugin's already-indexed fields (wiki / faq / compatibility_json / readme), not freshly generated by AI. Source field is noted at the end of each section.
Quick start
Safe math expression evaluator, zero-dependency recursive-descent parser.
— source: plugins.ai_summary
Install & verify
dsh plugin --profile web add github:omdsh-dev/dsh-tool-calculator
Run the command above in your DSH Web Profile. Then enable the plugin in the plugin list.
— source: plugins.install
Key points
- 词法层只识别数字字面量、白名单标识符、运算符;引号、分号、反引号、
{}[]直接报错 - 标识符按名查白名单表(15 个函数 + 2 个常量),查不到即抛
Unknown identifier - 求值结果必须是有限数字,
NaN/Infinity(除零、负数开方等)统一拒绝 src/index.ts:Cordis 插件入口(name/inject/apply),注册calculator工具src/evaluate.ts:evaluate(expression: unknown): number——入口独立校验类型(非字符串抛calculator: expression must be a string),返回有限数字,非法输入全部抛错
— source: plugin_wiki.readme_en (fallback readme_raw)
Pitfalls
Review the upstream repo before installing. This guide is auto-derived from indexed fields and may lag the latest release. If anything contradicts the official docs, treat the upstream source as authoritative.
— source: general rule