Skip to main content

Built and signed on GitHub Actions

Works with
This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score100%
License
MIT
Downloads333/wk
Publisheda week ago (1.0.0)

Configuration file support for Optique with Standard Schema validation

Functions

f
bindConfig<
M extends "sync" | "async",
TValue,
TState,
T,
TConfigMeta = ConfigMeta
>
(
parser: Parser<M, TValue, TState>,
options: BindConfigOptions<T, TValue, TConfigMeta>
): Parser<M, TValue, TState>

Binds a parser to configuration values with fallback priority.

f
createConfigContext<T, TConfigMeta = ConfigMeta>(options: ConfigContextOptions<T>): ConfigContext<T, TConfigMeta>

Creates a config context for use with Optique parsers.

Interfaces

I

Options for binding a parser to config values.

  • context: ConfigContext<T, TConfigMeta>

    The config context to use for fallback values.

  • default: TValue

    Default value to use when neither CLI nor config provides a value. If not specified, the parser will fail when no value is available.

  • key:
    keyof T
    | ((
    config: T,
    meta: TConfigMeta | undefined
    ) => TValue)

    Key or accessor function to extract the value from config. Can be a property key (for top-level config values) or a function that extracts nested values. Accessor callbacks receive config metadata, if available, as the second argument.

I

A config context that provides configuration data via annotations.

  • schema: StandardSchemaV1<unknown, T>

    The Standard Schema validator for the config file.

I

Options for creating a config context.

  • fileParser: (contents: Uint8Array) => unknown

    Custom parser function for reading config file contents. If not provided, defaults to JSON.parse.

  • schema: StandardSchemaV1<unknown, T>

    Standard Schema validator for the config file. Accepts any Standard Schema-compatible library (Zod, Valibot, ArkType, etc.).

I

Required options for ConfigContext when used with runWith() or run(). The ParserValuePlaceholder will be substituted with the actual parser result type by runWith().

  • getConfigPath: (parsed: ParserValuePlaceholder) => string | undefined

    Function to extract config file path from parsed CLI arguments. Used in single-file mode. The parsed parameter is typed as the parser's result type.

  • load: (parsed: ParserValuePlaceholder) =>
    Promise<ConfigLoadResult<TConfigMeta> | undefined | null>
    | ConfigLoadResult<TConfigMeta>
    | undefined
    | null

    Custom loader function that receives the first-pass parse result and returns the config data (or a Promise of it). This allows full control over file discovery, loading, merging, and error handling.

I

Result type for custom config loading.

  • config: unknown

    Raw config data to validate against the schema. The value is always passed to the schema validator, even when undefined or null. To signal "no config found" without validation, return undefined or null directly from load() instead of wrapping it in an object.

  • meta: TConfigMeta | undefined

    Metadata about where the config came from, if available.

I

Metadata about the loaded config source.

  • configDir: string

    Directory containing the config file.

  • configPath: string

    Absolute path to the config file.

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@optique/config

Import symbol

import * as mod from "@optique/config";
or

Import directly with a jsr specifier

import * as mod from "jsr:@optique/config";