@bluprynt/forms-core

中文文档
4.2.0发布于 2026/10/21TypeScriptESM + CJS零依赖近 30 天下载 2.1万

JSON驱动的动态形式的框架不可知性引擎. Given a form schema (JSON),引擎通过条件逻辑处理字段能见度,根据特定类型的规则验证用户输入,并生成结构化的形式文档(JSON).

中文使用文档
文档目录6 节
  1. 密钥能力
  2. 快速启动
  3. 建立形式定义
  4. 编辑窗体值
  5. 文档
  6. 支持的外地类型

@ bluprynt/ 形式- 核心

JSON驱动的动态形式的框架不可知性引擎. Given a form schema (JSON),引擎通过条件逻辑处理字段能见度,根据特定类型的规则验证用户输入,并生成结构化的形式文档(JSON).

密钥能力

  • Schema 汇编 ——通过依赖性分析和循环检测,验证JSON形式定义并将其编成运行时引擎.
  • 有条件的能见度 ——以其他字段值为基础动态地显示/hides字段和分段,并带有串连的亲子能见度和地形评价顺序.
  • 类型意识验证 ——对照每个字段的规则(要求,分/最大,图案,日期范围,数组限制等)验证形成值,自动跳过隐藏字段.
  • 文档兼容性验证 - 核实表格文件的 form.id 财务报告和审定财务报表 form.version 在字段验证前匹配引擎定义.
  • 窗体定义编辑 ——流利建设API(FormDefinitionEditor用于方案构建和修改形式方案.
  • 窗体值编辑 ——流利编辑 API (FormValuesEditor)用于对定义进行程序读取和书写形式值,同时进行阵列操纵,验证和能见度查询.
  • 相对日期 ——日期界限如: "+7d" 或者说 "-1m" 在评估时按所需表格解决 submittedAt 时间戳,允许动态但可复制的日期限制.

快速启动

import { FormEngine } from '@bluprynt/forms-core'

// 1. Compile the form definition
const engine = new FormEngine(formDefinition)

// 2. Create a form document (with optional initial values)
const doc = engine.createFormDocument({ "1": "Alice", "2": 30 })

// 3. Compute visibility
const visibility = engine.getVisibilityMap(doc)

// 4. Validate (checks document compatibility + field rules)
const result = engine.validate(doc)
if (!result.valid) {
  result.documentErrors?.forEach(e => console.log(`Document: ${e.message}`))
  for (const [fieldId, errs] of result.fieldErrors) {
    for (const err of errs) {
      console.log(`Field ${fieldId}: ${err.message}`)
    }
  }
}

建立形式定义

import { FormDefinitionEditor } from '@bluprynt/forms-core'

const editor = new FormDefinitionEditor({
  id: 'my-form', version: '1.0.0', title: 'My Form', content: [],
})

editor
  .addField({ type: 'string', label: 'Name', validation: { required: true } })
  .addSection({ type: 'section', title: 'Details' })
  .addField({ type: 'number', label: 'Age' }, 2) // into section id=2

const definition = editor.toJSON()

编辑窗体值

import { FormValuesEditor } from '@bluprynt/forms-core'

// 1. Create an editor (optionally pre-populate from an existing document)
const editor = new FormValuesEditor(formDefinition)

// 2. Set field values (fluent chaining)
editor
  .setFieldValue(1, 'Alice')
  .setFieldValue(2, 30)
  .addArrayItem(6, 'TypeScript')
  .addArrayItem(6, 'React')
  .setSubmittedAt('2025-01-01T00:00:00Z')

// 3. Optionally record and resolve machine-proposed answers
editor
  .setSuggestion(1, { value: 'Alice Smith', confidence: 0.8, source: 'Passport MRZ, line 2' })
  .acceptSuggestion(1)   // copies the value across, keeps the suggestion
  .rejectSuggestion(2)   // removes a suggestion, leaves the value untouched

// 4. Validate and extract the document
const result = editor.validate()
const doc = editor.toJSON()

文件的可选建议 suggestions 块,绝不影响验证或 可见度. confidence 是一个 0..1 分数 块和三个元数据属性 (单位:千美元)placeholder, (中文(简体) ), answer_guidelines, (中文(简体) ), reference_id)关于字段和部分是可选的,因此存在 定义和文件保持不变.

文档

文档说明
建筑项目结构、模块依赖图、关键设计模式
API 参考完整的公共 API——类,方法,类型,错误处理
验证条件( C)每个字段类型、条件操作符、可见度分辨率的验证规则如何工作
Schema 问题代码全体 DocumentError 错误代码、 验证阶段、 错误处理
发展指南如何构建、测试、涂料和扩展引擎(例如添加新的字段类型)

出口类别、类型和公用事业的完整清单见 API 参考。 。 。 .

支持的外地类型

类型数值说明
stringstring文本输入
numbernumber数字输入
booleanboolean真假切换
datestring (ISO 8601) (中文(简体) )选取日期者
selectstring | number从预定义选项中选择
arrayT[]按顺序排列的平面值列表
fileFileValue 对象文件上传元数据( 名称、 mimeType、 大小、 url)

版本与发布记录

@bluprynt/forms-core 共发布 6 个版本,首次发布于 2026/03/20;过去 12 个月发布了 6 个版本。

版本发布日期距今
4.2.0latest2026/10/2117 天前
4.1.02026/09/221 个月前
4.0.12026/06/294 个月前
3.0.02026/03/247 个月前
2.0.02026/03/247 个月前
1.0.02026/03/207 个月前

关于 @bluprynt/forms-core 的常见问题

@bluprynt/forms-core 是什么?

JSON驱动的动态形式的框架不可知性引擎. Given a form schema (JSON),引擎通过条件逻辑处理字段能见度,根据特定类型的规则验证用户输入,并生成结构化的形式文档(JSON).

如何安装 @bluprynt/forms-core?

在项目目录运行 npm install @bluprynt/forms-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ajv(^8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bluprynt/forms-core 支持 TypeScript 吗?

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

@bluprynt/forms-core 支持 ESM 还是 CommonJS?

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

@bluprynt/forms-core 可以商用吗?

@bluprynt/forms-core 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@bluprynt/forms-core 的下载量有多少?

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

@bluprynt/forms-core 还在维护吗?

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