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

@molecule/api-config

v1.0.1

Published

Configuration core interface for molecule.dev

Readme

@molecule/api-config

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Configuration core interface for molecule.dev.

Defines the standard interface for configuration providers with typed accessors for strings, numbers, booleans, and JSON values.

Quick Start

import {
  setProvider,
  get,
  getRequired,
  getNumber,
  getBoolean,
  getJson,
  has,
  validate,
} from '@molecule/api-config'
import { provider } from '@molecule/api-config-env'

// Wire the provider at app startup
setProvider(provider)

// Get configuration values
const apiKey = getRequired('API_KEY')
const port = getNumber('PORT', 3000)
const debug = getBoolean('DEBUG', false)
const config = getJson('APP_CONFIG', {})

// Validate configuration schema
const result = validate([
  { key: 'DATABASE_URL', required: true },
  { key: 'PORT', type: 'number', min: 1, max: 65535 },
])

Type

core

Installation

npm install @molecule/api-config @molecule/api-bond

API

Interfaces

ConfigProvider

Configuration provider interface.

All configuration providers must implement this interface.

interface ConfigProvider {
  /**
   * Gets a configuration value.
   *
   * @param key - Configuration key
   * @param defaultValue - Default value if not found
   */
  get<T = string>(key: string, defaultValue?: T): T | undefined

  /**
   * Gets a required configuration value.
   *
   * @param key - Configuration key
   * @throws {Error} Error if the key is not found
   */
  getRequired<T = string>(key: string): T

  /**
   * Gets all configuration values.
   */
  getAll(): Record<string, unknown>

  /**
   * Checks if a configuration key exists.
   */
  has(key: string): boolean

  /**
   * Sets a configuration value (runtime override).
   */
  set?(key: string, value: unknown): void

  /**
   * Validates configuration against a schema.
   */
  validate?(schema: ConfigSchema[]): ConfigValidationResult

  /**
   * Reloads configuration from sources.
   */
  reload?(): Promise<void>

  /**
   * Watches for configuration changes.
   */
  watch?(callback: (key: string, value: unknown) => void): () => void
}

ConfigSchema

Configuration schema for a single value.

interface ConfigSchema {
  /**
   * Configuration key (e.g., 'DATABASE_URL', 'API_KEY').
   */
  key: string

  /**
   * Human-readable description.
   */
  description?: string

  /**
   * Expected type.
   */
  type?: 'string' | 'number' | 'boolean' | 'json'

  /**
   * Whether this configuration is required.
   */
  required?: boolean

  /**
   * Default value if not provided.
   */
  default?: unknown

  /**
   * Whether this is a secret (should not be logged).
   */
  secret?: boolean

  /**
   * Validation pattern (regex for strings).
   */
  pattern?: string

  /**
   * Minimum value (for numbers).
   */
  min?: number

  /**
   * Maximum value (for numbers).
   */
  max?: number

  /**
   * Allowed values.
   */
  enum?: unknown[]
}

ConfigValidationResult

Configuration validation result.

interface ConfigValidationResult {
  /**
   * Whether validation passed.
   */
  valid: boolean

  /**
   * Validation errors.
   */
  errors: Array<{
    key: string
    message: string
  }>

  /**
   * Warnings (non-fatal issues).
   */
  warnings: Array<{
    key: string
    message: string
  }>
}

Functions

get(key, defaultValue)

Retrieves a configuration value by key, with an optional default.

function get(key: string, defaultValue?: T): T | undefined
  • key — The configuration key (e.g. 'DATABASE_URL', 'API_KEY').
  • defaultValue — Value to return if the key is not found.

Returns: The configuration value cast to T, or undefined / defaultValue if not found.

getBoolean(key, defaultValue)

Retrieves a configuration value parsed as a boolean. Recognizes 'true', '1', and 'yes' (case-insensitive) as true; everything else is false.

function getBoolean(key: string, defaultValue?: boolean): boolean | undefined
  • key — The configuration key.
  • defaultValue — Value to return if the key is not found.

Returns: The boolean value, or undefined / defaultValue.

getJson(key, defaultValue)

Retrieves a configuration value parsed as JSON. Returns the default value if the key is missing or the value is not valid JSON.

function getJson(key: string, defaultValue?: T): T | undefined
  • key — The configuration key.
  • defaultValue — Value to return if the key is missing or JSON parsing fails.

Returns: The parsed JSON value cast to T, or undefined / defaultValue.

getNumber(key, defaultValue)

Retrieves a configuration value parsed as a number. Returns the default value if the key is missing or the value is not a valid number.

function getNumber(key: string, defaultValue?: number): number | undefined
  • key — The configuration key.
  • defaultValue — Value to return if the key is missing or not a number.

Returns: The parsed number, or undefined / defaultValue.

getProvider()

Retrieves the bonded configuration provider, throwing if none is configured.

function getProvider(): ConfigProvider

Returns: The bonded configuration provider.

getRequired(key)

Retrieves a configuration value by key, throwing if not found. Use this for values that must be present for the application to function.

function getRequired(key: string): T
  • key — The configuration key.

Returns: The configuration value cast to T.

getString(key, defaultValue)

Retrieves a configuration value as a string.

function getString(key: string, defaultValue?: string): string | undefined
  • key — The configuration key.
  • defaultValue — Value to return if the key is not found.

Returns: The string value, or undefined / defaultValue if not found.

has(key)

Checks whether a configuration key exists (has a defined value).

function has(key: string): boolean
  • key — The configuration key to check.

Returns: true if the key exists in the configuration.

hasProvider()

Checks whether a configuration provider is currently bonded.

function hasProvider(): boolean

Returns: true if a configuration provider is bonded.

setProvider(provider)

Registers a configuration provider as the active singleton. Called by bond packages during application startup.

function setProvider(provider: ConfigProvider): void
  • provider — The configuration provider implementation to bond.

validate(schema)

Validates the current configuration against an array of schema rules. Returns validation errors and warnings. Throws if the provider doesn't support validation.

function validate(schema: ConfigSchema[]): ConfigValidationResult
  • schema — Array of configuration schema rules to validate against.

Returns: The validation result containing valid, errors, and warnings.

Available Providers

| Provider | Package | | ----------- | -------------------------- | | Environment | @molecule/api-config-env |

Injection Notes

Requirements

Peer dependencies:

  • @molecule/api-bond ^1.0.1

Runtime Dependencies

  • @molecule/api-bond

Config values are SERVER-SIDE. A secret read here (API_KEY, DATABASE_URL) must never be sent to the browser or exposed through a VITE_/NEXT_PUBLIC_ var — only a publishable / public value may be client-side (see @molecule/api-secrets). Use getRequired for anything the app can't run without (it throws at startup — fail fast), validate at boot to catch every missing/invalid value at once, and never log a secret value.

Translations

Translation strings are provided by @molecule/api-locales-config.