@ formdown/ core (中文(简体) )
Formdown 解析器,生成器和工具:将Formdown 读出——用形式字段标记为Markdown,并变成一个字段和 schema,使它成为HTML,编辑它的源而不会失去任何东西,并将所持有的数据写回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
入境点
仅导入您使用的东西; 每个子路径只携带它需要的东西 .
| 导入 | 它给的是什么 |
|---|---|
@formdown/core | 下面的一切 FormManager |
@formdown/core/parser | FormdownParser ——领域,诊断和源位. 它发现首要问题,但只有在给读者读取时才读出YAML,所以它没有YAML的执行 |
@formdown/core/front-matter | yamlFrontMatter (读者给出解析器), readFrontMatter |
@formdown/core/format | formatFormdown(fields), (中文(简体) ), formatField(field) —— 以Formdown文本写成的数据所持有的字段; 解析它使相同的字段返回 |
@formdown/core/schema | getSchema(content) ——取自已解析的文本或内容 |
@formdown/core/generator | FormdownGenerator —— HTML 从解析的内容 |
@formdown/core/form-manager | FormManager ——解析,渲染,数据绑定和验证一起进行 |
@formdown/core/extensions | 钩和插件 |
@formdown/core/messages/ko | 韩语验证句子, 用于 validateForm(…, { messages }) 或者说 <formdown-ui>是因为 messages |
验证是每个字段宣布的 required (和 required-if, (中文(简体) ), minlength 编号 : maxlength, (中文(简体) ), min 编号 : max,格式 number, (中文(简体) ), email, (中文(简体) ), url, (中文(简体) ), tel 财务报告和审定财务报表 date,以及 pattern 匹配整个值,如浏览器所做的:
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 替换任何规则的句子(required, (中文(简体) ), minLength, (中文(简体) ), maxLength, (中文(简体) ), min, (中文(简体) ), max, (中文(简体) ), number, (中文(简体) ), email, (中文(简体) ), url, (中文(简体) ), tel, (中文(简体) ), date, (中文(简体) ), dateMin, (中文(简体) ), dateMax, (中文(简体) ), pattern),与 {label}, (中文(简体) ), {min} 财务报告和审定财务报表 {max} 填入; 一个字段本身 error-message 胜过所有这些——这是字段所说的一句话,对于第一个规则,它的价值破裂.
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
文档
许可证
麻省理工学院