@match-kit/decomp-yaml
v0.1.0
Published
Read a project's decomp.yaml (the decomp_settings format), checked against the spec, and each tool's block with a Standard Schema
Downloads
217
Readme
@match-kit/decomp-yaml
Read a project's decomp.yaml, the decomp_settings
format that matching-decompilation tools share, checked against its spec. Read your tool's block with
your own Standard Schema (zod, valibot, ArkType, …).
npm install @match-kit/decomp-yamlRead a project's decomp.yaml
import { toolBlock } from '@match-kit/decomp-yaml';
import { loadDecompYaml, searchDecompYaml } from '@match-kit/decomp-yaml/files';
import * as z from 'zod';
const loaded = searchDecompYaml(); // { path, dir, config }, or null when there is none
loaded?.config.platform; // 'gba'
const MyTool = z.strictObject({ compiler: z.string().optional(), jobs: z.number().int().optional() });
const settings = toolBlock(loaded, 'mytool', MyTool); // { compiler?, jobs? }, or undefinedsearchDecompYaml(from?)reads the nearest decomp.yaml fromfrom(default: the working directory) up to the root, tryingdecomp.yamlbeforedecomp.ymlin each directory, or returnsnull.loadDecompYaml(path)reads the file atpath, and a missing one throws.@match-kit/decomp-yaml/filesneeds Node or Bun. In a browser, useparseDecompYaml(text, path?).
Your tool's block
toolBlock(loaded, tool, schema) validates tools.<tool> with schema and returns the schema's
output, so defaults and transforms apply. It returns undefined when there is no config or no block
for the tool.
The schema decides what the block may hold: z.strictObject refuses unknown keys, such as a typo,
and z.object drops them. The schema must validate synchronously.
The format
SPEC.md specifies decomp.yaml as decomp_settings 0.0.10 declares it, and
schema.json is the same specification as a JSON Schema, also exported as
@match-kit/decomp-yaml/schema.json. To check a file in your editor, start it with:
# yaml-language-server: $schema=https://cdn.jsdelivr.net/npm/@match-kit/decomp-yaml/schema.json