npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

formula-gadget

v0.1.4

Published

Game combat formula DSL — compile to bytecode, evaluate in a tiny runtime

Readme

formula-gadget

游戏战斗公式 DSL 的全家桶主包。同时导出编译器与 TypeScript 运行时的完整 API,适合联调、工具链或不需要拆包优化的场景。

生产环境建议按需安装子包以控制打包体积:

  • 构建期 → npm install @formula-gadget/compiler -D
  • 运行时 → npm install @formula-gadget/runtime-ts

安装

npm install formula-gadget

快速开始

动态编译(调试 / 工具链)

import { FormulaDSL } from "formula-gadget";

const dsl = new FormulaDSL();
const formula = dsl.compileOrThrow(`
  base = max(atk - def, 0)
  bonus = hp < 30 ? 50 : 0
  return base + bonus
`);

console.log(formula.evaluate({ atk: 100, def: 20, hp: 25 })); // 130

预编译 + 运行时分离(生产推荐)

// === 构建期 ===
import { compileAndSerialize, createRegistry } from "formula-gadget/build";

const registry = createRegistry();
registry.register("myBuff", () => 0);

const blob = compileAndSerialize("max(atk - def, 0) + myBuff()", registry, undefined, {
  ctxSlots: ["atk", "def"],
});
// 将 blob 写入文件或打包

// === 运行时 ===
import { loadFormula, createRuntimeRegistry } from "formula-gadget/runtime";

const registry = createRuntimeRegistry();
registry.register("myBuff", (x) => x * 1.5);

const formula = loadFormula(blob, registry);
formula.evaluate({ atk: 100, def: 20 }); // number

子路径导出

| 路径 | 内容 | |------|------| | formula-gadget | 完整 API(FormulaDSL、编译器、运行时) | | formula-gadget/build | 仅编译器 API(@formula-gadget/compiler) | | formula-gadget/runtime | 仅运行时 API(@formula-gadget/runtime-ts) | | formula-gadget/wasm | Wasm/SIMD 批处理引擎 |

完整文档

请参阅 GitHub 仓库,内含:

  • DSL 语法参考
  • 自定义函数与 Registry
  • C++ / C# 跨语言运行时接入指南
  • 性能优化特性说明(常量折叠、Fast Slots、SIMD 批处理)