@buildnbuzz/form-core

中文文档
0.1.12发布于 2026/06/10MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3354

框架-不可知核原始为BuzzForm.

中文使用文档
文档目录11 节
  1. 安装
  2. 快速启动
  3. 核心特征
  4. Schema 定义
  5. 动态值
  6. 可见条件
  7. 验证
  8. 输出变换
  9. 字段类型
  10. 类型推论
  11. 资源

@ burnbuzz/ form- core (中文(简体) )

框架-可知性为BuzzForm所形成的原始. 零 DOM 或 UI 依赖性 .

安装

pnpm add @buildnbuzz/form-core

快速启动

import { defineSchema, type InferType } from "@buildnbuzz/form-core";

const schema = defineSchema({
  title: "Contact Form",
  fields: [
    { type: "text", name: "name", label: "Name", required: true },
    { type: "email", name: "email", label: "Email", required: true },
  ],
});

type FormData = InferType<typeof schema.fields>;
// { name: string; email: string }

核心特征

Schema 定义

使用 defineSchema 用于具有自动受精型号的型号安全计划:

import { defineSchema, type InferType } from "@buildnbuzz/form-core";

const schema = defineSchema({
  id: "user-profile",
  title: "User Profile",
  description: "Update your profile",
  fields: [
    { type: "text", name: "firstName", label: "First Name", required: true },
    { type: "number", name: "age", label: "Age", min: 18, max: 120 },
    {
      type: "select",
      name: "role",
      label: "Role",
      options: [
        { label: "Admin", value: "admin" },
        { label: "User", value: "user" },
      ],
    },
  ],
});

动态值

参考窗体数据( E)$data)或外部环境($context对于动态标签、默认和条件:

const schema = defineSchema({
  fields: [
    { type: "text", name: "firstName", label: "First Name" },
    {
      type: "text",
      name: "greeting",
      label: { $data: "/firstName" }, // Dynamic label
      defaultValue: { $context: "/defaultGreeting" }, // Dynamic default
    },
  ],
});

可见条件

基于窗体数据或上下文显示/隐藏字段 :

const schema = defineSchema({
  fields: [
    { type: "text", name: "email", label: "Email" },
    {
      type: "text",
      name: "confirmEmail",
      label: "Confirm Email",
      condition: { $data: "/email", contains: "@" }, // Only show if email contains @
    },
  ],
});

支助 $and, (中文(简体) ), $or,比较运算符(eq, (中文(简体) ), neq, (中文(简体) ), gt, (中文(简体) ), lt, (中文(简体) ), contains(见a/c.5/49/70,附件).

验证

从字段属性加自定义规则中自动生成的验证符:

const schema = defineSchema({
  fields: [
    {
      type: "text",
      name: "username",
      label: "Username",
      required: true,
      minLength: 3,
      validate: {
        onBlur: {
          checks: [
            {
              type: "usernameAvailable",
              message: "Username is taken.",
            },
          ],
        },
      },
    },
    {
      type: "password",
      name: "confirmPassword",
      label: "Confirm Password",
      required: true,
      validate: {
        onSubmit: {
          checks: [
            {
              type: "matches",
              args: { other: { $data: "/password" } },
              message: "Passwords do not match.",
            },
          ],
        },
      },
    },
  ],
});

使用 defineValidators数字 :

import { defineValidators } from "@buildnbuzz/form-core";

const customValidators = defineValidators({
  usernameAvailable: async (value: unknown) => {
    if (typeof value !== "string") return false;
    
    const available = await checkUsername(value);
    return available ? true : "Username is taken";
  },
});

输出变换

平整嵌入式提交数据为路径键格式 :

import { transformFormOutput } from "@buildnbuzz/form-core";

const payload = transformFormOutput(
  { profile: { name: "Ada" } },
  { type: "path" },
);
// { "profile.name": "Ada" }

字段类型

基础 : text, (中文(简体) ), email, (中文(简体) ), password, (中文(简体) ), textarea, (中文(简体) ), number
选择 : select, (中文(简体) ), radio, (中文(简体) ), checkbox, (中文(简体) ), switch, (中文(简体) ), tags
复杂 : date, (中文(简体) ), group, (中文(简体) ), array
布局 : row, (中文(简体) ), tabs, (中文(简体) ), collapsible

类型推论

配置推导类型
required: true需要的密钥
没有 required可选密钥 (E)?(中文(简体) )
type: "group"嵌入对象
type: "array"嵌入对象阵列
type: "select" + 键 hasMany: truestring[]
type: "checkbox" + 键 tristate: trueboolean | null

资源

版本与发布记录

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

版本发布日期距今
0.1.12latest2026/06/104 个月前
0.1.112026/06/035 个月前
0.1.102026/06/035 个月前
0.1.92026/05/195 个月前
0.1.82026/05/165 个月前
0.1.72026/04/196 个月前

关于 @buildnbuzz/form-core 的常见问题

@buildnbuzz/form-core 是什么?

框架-不可知核原始为BuzzForm.

如何安装 @buildnbuzz/form-core?

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

@buildnbuzz/form-core 支持 TypeScript 吗?

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

@buildnbuzz/form-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@buildnbuzz/form-core 可以商用吗?

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

@buildnbuzz/form-core 的下载量有多少?

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

@buildnbuzz/form-core 还在维护吗?

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