Documentation
    Preparing search index...

    Class Conf<Schema>

    Simple config handling for your app or module.

    Type Parameters

    • Schema extends StandardSchemaV1
    Index
    events: EventTarget
    path: string
    • get size(): number

      Number of top-level config items.

      Returns number

    • get store(): SchemaValues<Schema>

      Get or replace the full config object.

      Reading this property loads and validates the config file from disk.

      Returns SchemaValues<Schema>

    • set store(value: SchemaValues<Schema>): void

      Validates value and persists the schema output. Missing top-level keys are filled from the defaults option and schema defaults.

      Does not read the current file, so it also replaces a corrupt or schema-invalid file.

      Parameters

      Returns void

    • Close the file watcher if one exists.

      Useful in tests to prevent the process from hanging.

      Returns void

    • Append an item to an array config value.

      Creates the array when the key does not exist.

      Type Parameters

      • Key extends string | number | symbol | string & Record<never, never>

      Parameters

      Returns void

    • Reset the config to the defaults option and schema default values.

      Does not read the current file, so it also replaces a corrupt or schema-invalid file.

      Returns void

    • Get a config item.

      Type Parameters

      • Key extends string | number | symbol | string & Record<never, never>

      Parameters

      • key: Key

        Item key. Supports dot notation when enabled.

      Returns SchemaValue<Schema, Key>

    • Get a config item, falling back to a default value when missing.

      Type Parameters

      • Key extends string | number | symbol | string & Record<never, never>
      • DefaultValue

      Parameters

      • key: Key

        Item key. Supports dot notation when enabled.

      • defaultValue: DefaultValue

        Value returned when the item does not exist.

      Returns DefaultValue | Exclude<SchemaValue<Schema, Key>, undefined>

    • Reset items to their default values.

      Values come from the defaults option first, then from the schema. Keys without a default are left unchanged.

      Parameters

      Returns void

    • Set one or more config items.

      Type Parameters

      • Key extends string | number | symbol | string & Record<never, never>

      Parameters

      Returns void

    • Set multiple config items.

      Parameters

      Returns void

    • Read, change and write the whole config in one step.

      fn gets a fresh copy of the stored config and returns the new config, which is validated and written. Nothing is written when it is unchanged. With the lock option, no other process can write between the read and the write, so a "set if missing" is safe across processes:

      const { installId } = config.update((store) =>
      store.installId ? store : { ...store, installId: randomUUID() }
      )

      Parameters

      Returns SchemaValues<Schema>

      The stored config.