Skip to content

Datapad

@theholocron/datapad finds a <name>.config.* file, loads it (JSON, JS, TS, ESM or CJS), layers a dedicated file over a key of a parent file, deep-merges, and hands back a plain object. TypeScript configs load through tsx with no build step.

It is Holocron-agnostic: no schema, no validation, no defaults. Consumers build those on top:

Terminal window
pnpm add @theholocron/datapad
import { loadConfigFile, loadLayered, mergeConfig, createDefineConfig } from "@theholocron/datapad";
// One file: holocron.config.{ts,js,mjs,cjs,json}
const found = await loadConfigFile<MyConfig>({ cwd, name: "holocron" });
// { config, filepath } | null
// A dedicated file layered over the `tasks` key of a parent file
const layered = await loadLayered<TasksConfig>({
cwd,
name: "astromech",
fallback: { file: "holocron", key: "tasks" },
});
// { config, filepath, sources } | null (the dedicated file wins on conflict)
const merged = mergeConfig(defaults, layered?.config);
// A typed identity defineConfig for one config shape
export const defineConfig = createDefineConfig<TasksConfig>();

“Not found” is null, never an error. A file that exists but is unusable throws ConfigFileError, carrying its filepath.

The loaders probe .ts, .js, .mjs, .cjs, then .json.

The full API reference is generated from the package’s TSDoc comments.