@formdown/core

中文文档
0.26.1发布于 2026/11/09MITTypeScriptES Module构建来源已验证近 30 天下载 4207

Core parsing and generation engine for Formdown

原始使用文档
文档目录3 节
  1. Entry points
  2. Documentation
  3. License

@formdown/core

The Formdown parser, generator and tools: read Formdown — Markdown with form fields — into fields and a schema, render it as HTML, edit its source without losing anything, and write fields held as data back as Formdown.

npm install @formdown/core
import { parseFormdown, getSchema, generateFormHTML } from '@formdown/core'

const source = '@name*: []\n@email*: @[]\n@notify(Email me about replies): c[switch]'
parseFormdown(source).forms   // the fields, with diagnostics for anything the parser could not read
getSchema(source)             // { name: { type: 'text', required: true, … }, …, notify: { type: 'checkbox', switch: true, … } }
generateFormHTML(source)      // the form as HTML

Entry points

Import only what you use; each subpath carries only what it needs.

ImportWhat it gives
@formdown/coreEverything below, and FormManager
@formdown/core/parserFormdownParser — fields, diagnostics and source positions. It finds front matter but reads its YAML only when given a reader, so it carries no YAML implementation
@formdown/core/front-matteryamlFrontMatter (the reader to give the parser), readFrontMatter
@formdown/core/formatformatFormdown(fields), formatField(field) — fields held as data written as Formdown text; parsing it gives the same fields back
@formdown/core/schemagetSchema(content) — from text or from content already parsed
@formdown/core/generatorFormdownGenerator — HTML from parsed content
@formdown/core/form-managerFormManager — parse, render, data binding and validation together
@formdown/core/extensionsHooks and plugins
@formdown/core/messages/koKorean validation sentences, for validateForm(…, { messages }) or <formdown-ui>'s messages

Validation holds what each field declares — required (and required-if), minlength / maxlength, min / max, the format of number, email, url, tel and date, and pattern matched against the whole value, as the browser does:

import { getSchema, validateForm, typedData } from '@formdown/core'
import { messages as ko } from '@formdown/core/messages/ko'

const schema = getSchema('@title(Title)*: [minlength=3]
@n: [number max=10]')
validateForm({ title: 'ab', n: '12' }, schema).errors
// [{ field: 'title', message: 'Must be at least 3 characters' }, { field: 'n', message: 'Value must be at most 10' }]
validateForm({}, schema, { messages: ko }).errors   // [{ field: 'title', message: 'Title 칸을 채워 주세요' }]
typedData({ n: '12' }, schema)                      // { n: 12 } — number fields' values as numbers

messages replaces the sentence of any rule (required, minLength, maxLength, min, max, number, email, url, tel, date, dateMin, dateMax, pattern), with {label}, {min} and {max} filled in; a field's own error-message wins over them all — it is the one sentence that field says, for the first rule its value breaks.

import { FormdownParser } from '@formdown/core/parser'
import { yamlFrontMatter } from '@formdown/core/front-matter'

new FormdownParser().parseFormdown(source)                                    // no front matter values
new FormdownParser({ frontMatter: yamlFrontMatter }).parseFormdown(source)    // as parseFormdown() reads them

Documentation

License

MIT

版本与发布记录

@formdown/core 共发布 58 个版本,首次发布于 2025/06/23;过去 12 个月发布了 39 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.26.1latest2026/11/096 天前
0.26.02026/10/2422 天前
0.25.02026/10/2422 天前
0.24.02026/10/2224 天前
0.23.02026/10/2225 天前
0.22.02026/10/2026 天前

关于 @formdown/core 的常见问题

@formdown/core 是什么?

Core parsing and generation engine for Formdown

如何安装 @formdown/core?

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

@formdown/core 支持 TypeScript 吗?

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

@formdown/core 支持 ESM 还是 CommonJS?

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

@formdown/core 可以商用吗?

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

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

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

@formdown/core 还在维护吗?

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