@ggts-sh/spec

中文文档
0.48.3发布于 2026/11/06MITTypeScriptES Module构建来源已验证近 30 天下载 9447

ggts plot spec: TypeBox schemas, PortableSpec types, normalize(), validate() with agent errors, fluent builder, JSON Schema artifact.

原始使用文档
文档目录3 节
  1. Quick example
  2. Agent contract
  3. Render

@ggts-sh/spec

codecov

PortableSpec types, published JSON Schema, normalize(), two-tier validate() with the agent error contract ({ code, path, message, allowed?, fix }), lintSpec(), and the fluent gg() / aes() builder. No DOM, no d3. Pre-1.0.

bun add @ggts-sh/spec     # or: npm install @ggts-sh/spec

Install alone for validation and authoring without a renderer. @ggts-sh/svelte re-exports this package.

Quick example

import { gg, aes, validate } from "@ggts-sh/spec";
// constrained decoding / tool schemas
import schema from "@ggts-sh/spec/schema/v0.json";

const spec = gg(
  [
    { year: "1835", value: 12 },
    { year: "2026", value: 31 },
  ],
  aes({ x: "year", y: "value" }),
)
  .geomLine()
  .spec();

const result = validate(spec, {
  profile: {
    fields: [
      { name: "year", type: "temporal" },
      { name: "value", type: "quantitative" },
    ],
  },
  lint: true,
});
if (!result.ok) {
  // Apply fix.example at path, then re-validate.
  // { code, path, message, allowed?, fix: { description, example } }
}

Agent contract

  • validate(spec) — shape only.
  • validate(spec, { profile }) — data-aware without shipping rows.
  • validate(spec, { lint: true }) — advisories for valid-but-questionable specs.
  • Every error carries fix.example. Apply it at path and re-validate.
  • PortableSpec is JSON-only: no Date, callbacks, or regular expressions. Builder Date values canonicalize to ISO strings.
  • JSON aes uses { field: "col" } (bare strings are invalid in JSON). The builder and Svelte props accept bare-string shorthand.

Render

Schema: schema/v0.json · Docs: ggts.sh · Repo: github.com/ggts-sh/ggts

MIT © Liam O'Dea

版本与发布记录

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

版本发布日期距今
0.48.3latest2026/11/0610 天前
0.48.22026/11/0610 天前
0.48.12026/11/0510 天前
0.48.02026/11/0511 天前
0.47.02026/11/0313 天前
0.46.02026/11/0313 天前

关于 @ggts-sh/spec 的常见问题

@ggts-sh/spec 是什么?

ggts plot spec: TypeBox schemas, PortableSpec types, normalize(), validate() with agent errors, fluent builder, JSON Schema artifact.

如何安装 @ggts-sh/spec?

在项目目录运行 npm install @ggts-sh/spec,或使用 pnpm add / yarn add / bun add。

@ggts-sh/spec 支持 TypeScript 吗?

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

@ggts-sh/spec 支持 ESM 还是 CommonJS?

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

@ggts-sh/spec 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@ggts-sh/spec 可以商用吗?

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

@ggts-sh/spec 的下载量有多少?

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

@ggts-sh/spec 还在维护吗?

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