@formhaus/core

中文文档
1.12.1发布于 2026/11/03MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 1.3万

JSON form definition engine: validation, conditional visibility, multi-step and branching routes. Zero dependencies, works in React, Vue, Svelte or vanilla.

原始使用文档
文档目录7 节
  1. Install
  2. Usage
  3. Entry points
  4. Network
  5. Features
  6. Docs
  7. License

@formhaus/core

Framework-free engine for JSON form definitions: field state, validation, conditional visibility, repeatable groups, multi-step navigation and branching routes. No runtime dependencies and no UI. Part of Formhaus. For rendering, use @formhaus/react or @formhaus/vue.

Install

npm install @formhaus/core

Requires Node 22.12 or later. ESM; require() works too.

Usage

import { FormEngine, type FormDefinition } from '@formhaus/core';

const definition: FormDefinition = {
  id: 'contact',
  title: 'Contact Us',
  submit: { label: 'Send' },
  fields: [
    { key: 'name', type: 'text', label: 'Name', validation: { required: true } },
    { key: 'email', type: 'email', label: 'Email', validation: { required: true } },
  ],
};

const engine = new FormEngine(definition);

engine.setValue('name', 'Jane');
engine.validate();
// { email: 'This field is required' }

engine.setValue('email', '[email protected]');
engine.getSubmitValues();
// { name: 'Jane', email: '[email protected]' }

Entry points

ImportContents
@formhaus/coreFormEngine, checkDefinition(), types
@formhaus/core/servervalidateSubmission() for untrusted payloads, also as server.iife.js
@formhaus/core/cloudClient for Formhaus Cloud: fetchForm(), createSubmitter(), createChallengeFrame()
@formhaus/core/i18nMessage and label catalogs, overlays, translation keys
@formhaus/core/fixsuggestFixes(), applyFix(), fixAll()
@formhaus/core/fieldsHelpers for custom field components: fieldState(), scaleView(), fromDate(), toDate() and others
@formhaus/core/researchOpt-in survey features: research for random option order
@formhaus/core/schemaschemaValidate() and schemaParse() for Zod, Valibot, ArkType and other Standard Schema libraries
@formhaus/core/dirtytrackDirty() for unsaved changes
@formhaus/core/style.cssOptional baseline styles with --fh-* theme tokens
@formhaus/core/schema.jsonJSON Schema of the definition

@formhaus/core/internal holds code shared by @formhaus/react and @formhaus/vue. It is not a public API and has no semver guarantee: any release can change it. Do not import it.

Network

Only the /cloud entries make network requests.

  • @formhaus/core/cloud calls https://api.formhaus.cc, or the apiBase you pass, and loads a challenge frame from https://formhaus.cc.
  • Every other entry makes no network requests.

Features

  • Field types, validation rules, show / showAny conditions, sections and repeatable groups. See fields and validation.
  • Multi-step forms with lifecycle hooks, async step validation and branching routes. goToStep(id) opens a step for URL routing: if the step can't be opened, the form opens the previous available step and reports it.
  • Server-side validation against the same definition.
  • Form events: pass onFormEvent and call start() to get form_viewed, step_viewed, field_shown, form_submit_succeeded and more.
  • Granular subscriptions: subscribe(), subscribeField(), subscribeStructure() and subscribeValues().
  • Translations through catalogs and overlay files.
  • Definition checks and JSON Patch fix suggestions through checkDefinition() and @formhaus/core/fix.
  • Formhaus Cloud: hosted endpoint, submissions, files and bot check. FormhausForm in @formhaus/react/cloud and @formhaus/vue/cloud renders a published form.
  • Theming: import '@formhaus/core/style.css', then override --fh-* custom properties. A dark theme is on with data-fh-theme="dark".
  • Claude Code skill and MCP server to generate and check definitions.

Docs

License

MIT

版本与发布记录

@formhaus/core 共发布 62 个版本,首次发布于 2026/04/07;过去 12 个月发布了 62 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.12.1latest2026/11/0313 天前
1.12.02026/11/0313 天前
1.11.02026/11/0213 天前
1.10.02026/11/0213 天前
1.9.02026/11/0213 天前
1.8.12026/10/3016 天前

关于 @formhaus/core 的常见问题

@formhaus/core 是什么?

JSON form definition engine: validation, conditional visibility, multi-step and branching routes. Zero dependencies, works in React, Vue, Svelte or vanilla.

如何安装 @formhaus/core?

在项目目录运行 npm install @formhaus/core,或使用 pnpm add / yarn add / bun add。

@formhaus/core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@formhaus/core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@formhaus/core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@formhaus/core 可以商用吗?

@formhaus/core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@formhaus/core 的下载量有多少?

根据 npm 官方下载统计,@formhaus/core 在 2026/10/16 – 2026/11/14 这 30 天内被下载 13,167 次,日均约 439 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@formhaus/core 还在维护吗?

最新版本 1.12.1 发布于 2026/11/03(13 天前);至今共发布 62 个版本,其中过去 12 个月发布了 62 个;首次发布于 2026/04/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。