@formspec/config

中文文档
0.1.0-alpha.70发布于 2026/08/21MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4190

Unified configuration for FormSpec - extensions, constraints, metadata, pipeline settings, and DSL-policy validation

原始使用文档
文档目录6 节
  1. Install
  2. formspec.config.ts
  3. Programmatic Use
  4. Static Non-Node Imports
  5. Main Exports
  6. License

@formspec/config

Unified configuration and DSL-policy validation for FormSpec projects.

Use this package when you want project-level rules such as:

  • disallowing certain field types
  • limiting layout nesting
  • restricting selected field options
  • registering extensions and project-wide FormSpec settings

Install

pnpm add @formspec/config

formspec.config.ts

import { defineFormSpecConfig } from "@formspec/config";

export default defineFormSpecConfig({
  constraints: {
    fieldTypes: {
      dynamicEnum: "warn",
      dynamicSchema: "error",
    },
    layout: {
      conditionals: "off",
      maxNestingDepth: 2,
    },
    fieldOptions: {
      placeholder: "off",
      minItems: "warn",
    },
  },
});

Programmatic Use

import { loadFormSpecConfig, validateFormSpecElements } from "@formspec/config";
import { field, formspec } from "@formspec/dsl";

const result = await loadFormSpecConfig();
const constraints = result.found ? result.config.constraints : undefined;

const form = formspec(field.text("name"), field.dynamicEnum("country", "countries"));
const validation = validateFormSpecElements(form.elements, { constraints });

Static Non-Node Imports

The main @formspec/config entry point does not statically import Node filesystem modules, so browser-oriented tools can import policy helpers without pulling in node:fs or node:path. Hosts that need config discovery can pass a FileSystem adapter for path and file operations:

import { loadFormSpecConfig, type FileSystem } from "@formspec/config";

const fileSystem: FileSystem = {
  exists: async (path) => existsInHost(path),
  readFile: async (path) => readFromHost(path),
  resolve: (...segments) => resolveInHost(...segments),
  dirname: (path) => dirnameInHost(path),
};

await loadFormSpecConfig({ searchFrom: ".", fileSystem });

The adapter covers discovery, existence checks, workspace-root checks, and file reads. Evaluating a TypeScript config module still uses the current Node-compatible jiti loader; a non-Node module evaluator is future work.

Main Exports

  • loadFormSpecConfig
  • defineFormSpecConfig
  • defineDSLPolicy
  • mergeWithDefaults
  • validateFormSpecElements
  • validateFormSpec

License

This package is part of the FormSpec monorepo and is released under the MIT License. See LICENSE for details.

版本与发布记录

@formspec/config 共发布 11 个版本,首次发布于 2026/04/16;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.0-alpha.70latest2026/08/212 个月前
0.1.0-alpha.632026/04/246 个月前
0.1.0-alpha.602026/04/236 个月前
0.1.0-alpha.592026/04/226 个月前
0.1.0-alpha.562026/04/206 个月前
0.1.0-alpha.552026/04/206 个月前

其他发布通道:alpha → 0.1.0-alpha.43。

关于 @formspec/config 的常见问题

@formspec/config 是什么?

Unified configuration for FormSpec - extensions, constraints, metadata, pipeline settings, and DSL-policy validation

如何安装 @formspec/config?

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

@formspec/config 支持 TypeScript 吗?

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

@formspec/config 支持 ESM 还是 CommonJS?

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

@formspec/config 可以商用吗?

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

@formspec/config 的下载量有多少?

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

@formspec/config 还在维护吗?

最新版本 0.1.0-alpha.70 发布于 2026/08/21(2 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 11 个;首次发布于 2026/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。