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

@clevercloud/reglage

v0.0.5

Published

Schema-driven configuration library built on [Zod](https://zod.dev). Define your options once and get validated, type-safe config from any number of sources.

Readme

@clevercloud/reglage

Schema-driven configuration library built on Zod. Define your options once and get validated, type-safe config from any number of sources.

Usage

import { z } from 'zod';
import { createConfigBuilder } from '@clevercloud/reglage';

const builder = createConfigBuilder({
  API_URL: {
    schema: z.url().default('https://api.example.com'),
    documentation: 'The API base URL',
  },
  PORT: {
    schema: z.number().default(8080),
    tags: ['server'],
    documentation: 'Port to listen on',
  },
  SECRET: {
    schema: z.string().min(1),
    secret: true,
    documentation: 'A required secret',
  },
});

builder.addSource('defaults', { PORT: '3000' });
builder.addSource('env', process.env);

const config = builder.buildConfig(); // throws InvalidConfigError on validation failure

config.get('API_URL'); // string
config.get('PORT'); // number
config.getAll('server'); // { PORT: number }

API

createConfigBuilder(schema)

Creates a ConfigBuilder from a schema record. Each key maps to an OptionDef:

| Field | Type | Description | | --------------- | ---------------------------------- | -------------------------------------------------------- | | schema | z.ZodType | Zod schema used to validate and transform the raw value. | | secret | boolean (optional) | Marks the value as sensitive. | | tags | string[] (optional) | Arbitrary tags for categorising options. | | documentation | string \| Record<string, string> | Human-readable description of the option. |

ConfigBuilder

addSource(name, values)

Registers a named key/value source (e.g. "env", "file"). Sources are merged in order — later sources override earlier ones for the same key. Keys not present in the schema are silently ignored.

buildConfig()

Merges all sources and validates every value against the schema. Returns a Config instance or throws an InvalidConfigError.

refine(key, fn)

Adds a cross-field validation rule for the given key. The callback receives the original Zod schema and all resolved config values, and must return a Zod schema to validate the field against. Multiple refinements can be registered (even on the same key). They run after all fields have been individually validated.

// Make SECRET required when FEATURE_X is enabled
builder.refine('SECRET', (schema, resolved) => {
  if (resolved.FEATURE_X) return z.string().min(1);
  return schema;
});

// Restrict PORT in production
builder.refine('PORT', (schema, resolved) => {
  if (resolved.MODE === 'production') {
    return schema.refine((v) => v >= 1024, { message: 'Must be >= 1024 in production' });
  }
  return schema;
});

Config

get(key)

Returns the resolved value for a single key.

getAll(tag?)

Returns all resolved values. When tag is provided, only options tagged with that value are included.

getSource(key)

Returns the name of the source that provided the winning value for a key (e.g. "env", "file"), or "default" if the value came from a Zod schema default.

getSourceHistory(key)

Returns the full override history for a single key, ordered from earliest (schema default) to latest (winning source). Each entry is a SourceHistoryEntry:

interface SourceHistoryEntry {
  source: string;
  rawValue: unknown;
  resolvedValue?: unknown; // only set on the last (winning) entry
}
builder.addSource('file', { PORT: 3000 });
builder.addSource('env', { PORT: '8080' });
const config = builder.buildConfig();

config.getSourceHistory('PORT');
// [
//   { source: 'default', rawValue: 80 },
//   { source: 'file', rawValue: 3000 },
//   { source: 'env', rawValue: '8080', resolvedValue: 8080 }
// ]

getAllSourceHistory()

Returns the full history for all keys as an object mapping each key to its SourceHistoryEntry[].

toString(format?)

Returns a human-readable string of all configuration values. Secret values are masked with ******. Keys are sorted alphabetically.

  • "simple" (default) — one line per key with the winning source:

    API_URL="https://api.example.com" (env)
    PORT=8080 (env)
    SECRET=****** (env)
  • "chain" — one line per key with the full source chain:

    API_URL="https://api.example.com" (default -> env)
    PORT=8080 (default -> file -> env)
    SECRET=****** (env)
  • "verbose" — multi-line output showing each source's raw value with an <-- active marker on the winning entry:

    API_URL="https://api.example.com" (env)
      default -> "https://default.example.com"
      env     -> "https://api.example.com"  <-- active
    PORT=8080 (env)
      default -> 80
      file    -> 3000
      env     -> "8080"  <-- active
    SECRET=****** (env)
      default -> ******
      env     -> ******  <-- active

InvalidConfigError

Thrown when validation fails. Exposes an issues array of ConfigIssue objects:

interface ConfigIssue {
  key: string;
  source: string | undefined;
  message: string;
}