Zero-dependency configuration loader with multi-format support and plugin extensibility
Find a file
2026-01-17 14:09:04 +02:00
.github/workflows ``` 2026-01-04 16:42:55 +02:00
examples Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
scripts Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
src Migrate from Vitest to Jest, fix cache/parser/crypto/merge/path bugs 2026-01-17 14:09:04 +02:00
website fix: add missing docs pages to git tracking 2026-01-04 17:29:03 +02:00
.gitignore fix: add missing docs pages to git tracking 2026-01-04 17:29:03 +02:00
.npmignore Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
babel.config.js Refactor: Adopt @oxog ecosystem by removing custom ESLint and Vitest configurations, adding Babel, and including @oxog-specific type definitions. 2026-01-17 11:08:25 +02:00
CHANGELOG.md Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
CONTRIBUTING.md Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
jest.config.cjs Migrate from Vitest to Jest, fix cache/parser/crypto/merge/path bugs 2026-01-17 14:09:04 +02:00
LICENSE init 2026-01-04 10:14:56 +02:00
llms.txt Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
package-lock.json Migrate from Vitest to Jest, fix cache/parser/crypto/merge/path bugs 2026-01-17 14:09:04 +02:00
package.json Migrate from Vitest to Jest, fix cache/parser/crypto/merge/path bugs 2026-01-17 14:09:04 +02:00
README.md Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
REFACTOR.md Refactor: Adopt @oxog ecosystem by removing custom ESLint and Vitest configurations, adding Babel, and including @oxog-specific type definitions. 2026-01-17 11:08:25 +02:00
tsconfig.json Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00
tsup.config.ts Based on the git diff and following the repository's concise commit style, here's the commit message: 2026-01-04 15:18:42 +02:00

@oxog/config

Zero-dependency configuration loader with multi-format support and plugin extensibility.

npm version License: MIT Node.js

Features

  • Multi-format support - JSON, YAML, TOML, INI, ENV out of the box
  • Zero dependencies - Pure TypeScript implementation
  • Type-safe - Full TypeScript support with generics
  • Plugin system - Micro-kernel architecture for extensibility
  • Environment overrides - Automatic environment-based configuration
  • Deep merging - Multiple merge strategies (replace, merge, append, prepend, unique)
  • Hot reload - File watching with debouncing
  • Encryption - AES-256-GCM for sensitive values
  • Validation - JSON Schema support

Installation

npm install @oxog/config

Quick Start

import { loadConfig } from '@oxog/config';

const config = await loadConfig({
  name: 'myapp',
  paths: ['./config.yaml'],
  env: process.env.NODE_ENV || 'development',
});

// Access values
const port = config.get('port');
const dbHost = config.get('database.host');

Type-Safe Configuration

interface AppConfig {
  port: number;
  database: {
    host: string;
    port: number;
  };
}

const config = await loadConfig<AppConfig>({ name: 'myapp' });
const port: number = config.get('port'); // Type-safe!

Supported Formats

JSON

{
  "port": 3000,
  "database": { "host": "localhost", "port": 5432 }
}

YAML

port: 3000
database:
  host: localhost
  port: 5432

TOML

port = 3000

[database]
host = "localhost"
port = 5432

INI

port = 3000

[database]
host = localhost
port = 5432

ENV

PORT=3000
DATABASE_HOST=localhost
DATABASE_PORT=5432

Environment Overrides

Automatically loads environment-specific configurations:

config.yaml              # Base config
config.development.yaml  # Development overrides
config.production.yaml   # Production overrides
config.local.yaml        # Local overrides (gitignored)
.env                     # Environment variables

Merge Strategies

const config = await loadConfig({
  name: 'myapp',
  mergeStrategy: {
    default: 'merge',
    arrays: 'unique',
    paths: {
      'server.plugins': 'append',
    },
  },
});

Plugins

Core Plugins (Always Loaded)

  • json-parser - JSON format support
  • env-parser - ENV format and environment variables
  • merge - Configuration merging
  • defaults - Default values and validation

Optional Plugins

import { validationPlugin, yamlParserPlugin } from '@oxog/config/plugins';

const config = await loadConfig({ name: 'myapp' });

// Add YAML support
config.use(yamlParserPlugin());

// Add schema validation
config.use(validationPlugin({
  schema: {
    type: 'object',
    properties: {
      port: { type: 'number', minimum: 1, maximum: 65535 },
    },
    required: ['port'],
  },
}));

API Reference

loadConfig(options)

interface LoadOptions {
  name: string;              // Application name
  paths?: string[];          // Config file paths
  cwd?: string;              // Base directory
  env?: string;              // Current environment
  environments?: string[];   // Supported environments
  envPrefix?: string;        // Env var prefix
  defaults?: object;         // Default values
  required?: string[];       // Required field paths
  mergeStrategy?: object;    // Merge strategies
  watch?: boolean;           // Enable file watching
  plugins?: ConfigPlugin[];  // Plugins to use
}

Config Instance

Method Description
get(path, default?) Get value at path
set(path, value) Set value at path
has(path) Check if path exists
delete(path) Delete value at path
toObject() Get all config as object
reload() Reload from files
watch() Start file watching
unwatch() Stop file watching
use(plugin) Register plugin
on(event, handler) Register event listener
off(event, handler) Remove event listener

Bundle Size

Package Size
Core ~5KB gzipped
With all plugins ~15KB gzipped

Zero runtime dependencies

Documentation

Visit config.oxog.dev for full documentation.

License

MIT

Author

Ersin Koc (@ersinkoc)