npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gokceno/konfeti

v0.2.5

Published

Type-safe YAML configuration loader for Node.js, Bun, and Deno with Zod validation and environment variable override support.

Readme

Konfeti 🎊

Type-safe YAML configuration loader for Node.js, Bun, and Deno with Zod validation and environment variable override support.

Features

  • 🔒 Type-safe - Built on top of Zod for runtime validation and TypeScript inference
  • 📄 YAML Support - Load configuration from YAML files
  • 🔄 Environment Variable Override - Seamlessly override config values with environment variables
  • 🐫 Case Conversion - Automatic snake_case to camelCase conversion
  • 🚀 Runtime Agnostic - Works with Node.js, Bun, and Deno
  • 🎯 Zero Config - Simple API with sensible defaults

Installation

npm install @gokceno/konfeti

Quick Start

Create a configuration schema using Zod and load your YAML config file:

import { create as createConfig } from "@gokceno/konfeti";
import type { CamelCaseConfig } from "@gokceno/konfeti/types";
import * as z from "zod";

// Define your configuration schema
const configSchema = z.object({
  database: z.object({
    host: z.string(),
    port: z.number(),
    username: z.string(),
    password: z.string(),
  }),
  api: z.object({
    base_url: z.string().url(),
    timeout: z.number().default(5000),
  }),
});

// Infer types from schema
export type RawConfig = z.infer<typeof configSchema>;
export type Config = CamelCaseConfig<RawConfig>;

// Create config parser
export const { parse, raw } = createConfig(configSchema);

Usage

Basic Configuration Loading

Create a config.yml file:

database:
  host: localhost
  port: 5432
  username: admin
  password: secret

api:
  base_url: https://api.example.com
  timeout: 3000

Load and use the configuration:

import { parse } from "./config";

// Load with camelCase conversion
const config = parse("config.yml");

console.log(config.database.host); // "localhost"
console.log(config.api.baseUrl);   // "https://api.example.com" (snake_case → camelCase)
console.log(config.api.timeout);   // 3000

Raw Configuration (No Case Conversion)

If you prefer to keep the original key casing:

import { raw } from "./config";

const config = raw("config.yml");

console.log(config.api.base_url); // "https://api.example.com" (original snake_case)

Environment Variable Override

Konfeti automatically maps environment variables to configuration values, allowing you to override config file settings without modifying the YAML file.

Naming Convention

Environment variables map to config paths using this pattern:

  • Use double underscores (__) to denote nested properties
  • Convert to lowercase to match YAML keys
  • Example: DATABASE__HOSTdatabase.host

Example

Given this config.yml:

database:
  host: localhost
  port: 5432

api:
  base_url: https://staging.example.com
  api_key: dev-key-123

Override values with environment variables:

# Override database host
export DATABASE__HOST=prod.database.com

# Override database port
export DATABASE__PORT=3306

# Override API settings
export API__BASE_URL=https://api.production.com
export API__API_KEY=prod-key-xyz
import { parse } from "./config";

const config = parse("config.yml");

// Environment variables take precedence
console.log(config.database.host);  // "prod.database.com" (from env)
console.log(config.database.port);  // 3306 (from env)
console.log(config.api.baseUrl);    // "https://api.production.com" (from env)
console.log(config.api.apiKey);     // "prod-key-xyz" (from env)

Using .env Files

Konfeti automatically loads .env files via dotenv:

Create a .env file:

DATABASE__HOST=prod.database.com
DATABASE__PORT=3306
API__BASE_URL=https://api.production.com
API__API_KEY=prod-key-xyz

The values will be automatically applied when you load your config.

API Reference

create(schema)

Creates a configuration loader with the specified Zod schema.

Parameters:

  • schema: A Zod schema object defining the structure and validation rules for your configuration

Returns: An object with two methods:

  • parse(filename): Loads config with snake_case to camelCase conversion
  • raw(filename): Loads config preserving original key casing

Example:

import * as z from "zod";
import { create as createConfig } from "@gokceno/konfeti";

const schema = z.object({
  app_name: z.string(),
  version: z.string(),
});

const { parse, raw } = createConfig(schema);

parse(filename)

Loads and validates a YAML configuration file with automatic snake_case to camelCase conversion.

Parameters:

  • filename: Path to the YAML configuration file

Returns: Validated configuration object with camelCase keys

Throws:

  • Error if file doesn't exist
  • Error if YAML is invalid
  • Error if configuration doesn't match schema

Example:

const config = parse("config.yml");
// snake_case keys are converted to camelCase
console.log(config.apiKey); // from api_key in YAML

raw(filename)

Loads and validates a YAML configuration file preserving original key casing.

Parameters:

  • filename: Path to the YAML configuration file

Returns: Validated configuration object with original key casing

Example:

const config = raw("config.yml");
// Original casing preserved
console.log(config.api_key); // original snake_case

Type Utilities

CamelCaseConfig<T>

Type utility that converts object keys from snake_case to camelCase.

Example:

import type { CamelCaseConfig } from "@gokceno/konfeti/types";

type RawConfig = {
  api_key: string;
  base_url: string;
  max_retries: number;
};

type Config = CamelCaseConfig<RawConfig>;
// Resulting type:
// {
//   apiKey: string;
//   baseUrl: string;
//   maxRetries: number;
// }

Advanced Examples

Multiple Environment Configurations

import { create as createConfig } from "@gokceno/konfeti";
import * as z from "zod";

const configSchema = z.object({
  environment: z.enum(["development", "staging", "production"]),
  database: z.object({
    host: z.string(),
    port: z.number(),
  }),
});

const { parse } = createConfig(configSchema);

// Load different configs based on NODE_ENV
const env = process.env.NODE_ENV || "development";
const config = parse(`config.${env}.yml`);

Complex Nested Configurations

const configSchema = z.object({
  server: z.object({
    host: z.string(),
    port: z.number(),
    ssl: z.object({
      enabled: z.boolean(),
      cert_path: z.string().optional(),
      key_path: z.string().optional(),
    }),
  }),
  features: z.object({
    rate_limiting: z.object({
      enabled: z.boolean(),
      max_requests: z.number(),
      window_ms: z.number(),
    }),
  }),
});

const { parse } = createConfig(configSchema);
const config = parse("config.yml");

// Access nested values with camelCase
console.log(config.server.ssl.certPath);
console.log(config.features.rateLimiting.maxRequests);

With Default Values

const configSchema = z.object({
  api: z.object({
    timeout: z.number().default(5000),
    retry_attempts: z.number().default(3),
    base_url: z.string(),
  }),
  logging: z.object({
    level: z.enum(["debug", "info", "warn", "error"]).default("info"),
    pretty_print: z.boolean().default(false),
  }),
});

const { parse } = createConfig(configSchema);
const config = parse("config.yml");

// Missing values in YAML will use schema defaults
console.log(config.api.timeout); // 5000 if not specified in YAML

Error Handling

Konfeti throws descriptive errors for common issues:

try {
  const config = parse("config.yml");
} catch (error) {
  if (error.message.includes("Config file not found")) {
    console.error("Configuration file missing!");
  } else if (error.message.includes("Invalid config")) {
    console.error("Configuration validation failed:", error.message);
  }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Repository

https://github.com/gokceno/konfeti