@buildnbuzz/form-core

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

Framework-agnostic core primitives for BuzzForm.

原始使用文档
文档目录11 节
  1. Installation
  2. Quick Start
  3. Core Features
  4. Schema Definition
  5. Dynamic Values
  6. Visibility Conditions
  7. Validation
  8. Output Transforms
  9. Field Types
  10. Type Inference
  11. Resources

@buildnbuzz/form-core

Framework-agnostic form primitives for BuzzForm. Zero DOM or UI dependencies.

Installation

pnpm add @buildnbuzz/form-core

Quick Start

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 }

Core Features

Schema Definition

Use defineSchema for type-safe schemas with auto-inferred types:

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" },
      ],
    },
  ],
});

Dynamic Values

Reference form data ($data) or external context ($context) for dynamic labels, defaults, and conditions:

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
    },
  ],
});

Visibility Conditions

Show/hide fields based on form data or context:

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 @
    },
  ],
});

Supports $and, $or, and comparison operators (eq, neq, gt, lt, contains, etc.).

Validation

Auto-derived validators from field properties plus custom rules:

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.",
            },
          ],
        },
      },
    },
  ],
});

Register custom validators with 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";
  },
});

Output Transforms

Flatten nested submission data into path-keyed format:

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

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

Field Types

Basic: text, email, password, textarea, number
Selection: select, radio, checkbox, switch, tags
Complex: date, group, array
Layout: row, tabs, collapsible

Type Inference

ConfigInferred Type
required: trueRequired key
No requiredOptional key (?)
type: "group"Nested object
type: "array"Array of nested objects
type: "select" + hasMany: truestring[]
type: "checkbox" + tristate: trueboolean | null

Resources

版本与发布记录

@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 是什么?

Framework-agnostic core primitives for 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 和提交记录判断。