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

fable-settings

v3.0.16

Published

A simple, tolerant configuration chain.

Readme

Fable Settings

A simple, tolerant configuration chain for Fable applications. Merges default settings, constructor overrides, JSON config files, and environment variables into a single settings object — with deep merge, fill-without-overwrite, and ${ENV_VAR|default} template syntax.

Build Status npm version License: MIT


Features

  • Layered Configuration - Merges defaults, constructor settings, default config file, and config file in order
  • Deep Merge - Nested objects are merged recursively rather than replaced wholesale
  • Environment Variable Templating - Use ${ENV_VAR} or ${ENV_VAR|fallback} syntax in any string setting value
  • Config File Loading - Optionally load and merge settings from DefaultConfigFile and ConfigFile JSON paths
  • Fill Without Overwrite - fill() adds missing keys from a source object without replacing existing values
  • Core Service - Extends fable-serviceproviderbase CoreServiceProviderBase, available before Fable is fully initialized
  • Browser Support - Ships with a browser shim that assigns window.FableSettings automatically

Installation

npm install fable-settings

Quick Start

const libFableSettings = require('fable-settings');

let settings = new libFableSettings(
{
	Product: 'MyApp',
	ProductVersion: '2.0.0',
	Database:
	{
		Host: '${DB_HOST|localhost}',
		Port: 5432
	}
});

console.log(settings.settings.Product);         // 'MyApp'
console.log(settings.settings.Database.Host);    // value of $DB_HOST, or 'localhost'

Legacy Factory

A .new() factory is available for backwards compatibility:

let settings = require('fable-settings').new(
{
	Product: 'MyApp',
	ProductVersion: '1.0.0'
});

Configuration Chain

Settings are resolved in the following order (later sources overwrite earlier ones):

  1. Built-in defaultsProduct, ProductVersion, ConfigFile, LogStreams
  2. Constructor settings — the object passed to new FableSettings(pSettings)
  3. Default config file — if DefaultConfigFile is set, loaded and merged
  4. Config file — if ConfigFile is set, loaded and merged

Config file loading is fault-tolerant — if a file cannot be loaded, a warning is logged and the previous settings are preserved.

Default Settings

{
	"Product": "ApplicationNameHere",
	"ProductVersion": "0.0.0",
	"ConfigFile": false,
	"LogStreams": [{ "level": "trace" }]
}

Usage

Merging Settings at Runtime

Use merge() to deep-merge new values into the current settings:

let settings = new libFableSettings({ Product: 'MyApp' });

settings.merge({ Database: { Host: 'db.example.com', Port: 5432 } });
settings.merge({ Database: { Port: 3306 } });

// settings.settings.Database.Host === 'db.example.com'
// settings.settings.Database.Port === 3306

Filling Gaps Without Overwriting

Use fill() to add missing keys without replacing existing values:

let settings = new libFableSettings({ Product: 'MyApp', LogLevel: 'info' });

settings.fill({ Product: 'DefaultApp', CacheTTL: 3600, LogLevel: 'trace' });

// settings.settings.Product === 'MyApp'       (not overwritten)
// settings.settings.LogLevel === 'info'        (not overwritten)
// settings.settings.CacheTTL === 3600          (filled in)

Environment Variable Templating

Any string value can reference environment variables with the ${VAR} or ${VAR|default} syntax. Variables are resolved recursively through nested objects:

// Given: DB_HOST=prod-db.example.com in the environment

let settings = new libFableSettings(
{
	Database:
	{
		Host: '${DB_HOST|localhost}',
		Port: '${DB_PORT|5432}',
		Name: '${DB_NAME|myapp}'
	}
});

// settings.settings.Database.Host === 'prod-db.example.com'  (from env)
// settings.settings.Database.Port === '5432'                  (default)
// settings.settings.Database.Name === 'myapp'                 (default)

Disable environment variable templating by setting NoEnvReplacement: true:

let settings = new libFableSettings(
{
	NoEnvReplacement: true,
	SomeValue: '${THIS_STAYS_LITERAL}'
});

Loading Config Files

let settings = new libFableSettings(
{
	Product: 'MyApp',
	DefaultConfigFile: '/etc/myapp/defaults.json',
	ConfigFile: '/etc/myapp/config.json'
});

API

Constructor

new FableSettings(pSettings, pServiceHash)

| Parameter | Type | Description | |-----------|------|-------------| | pSettings | Object | Initial settings to merge over defaults | | pServiceHash | String | Optional service hash identifier |

Methods

| Method | Description | |--------|-------------| | merge(pSettingsFrom, pSettingsTo) | Deep-merge pSettingsFrom into pSettingsTo (defaults to this.settings). Resolves environment variable templates after merging. Returns the merged object. | | fill(pSettingsFrom) | Deep-merge this.settings into a copy of pSettingsFrom, filling gaps without overwriting existing values. Returns this.settings. | | buildDefaultSettings() | Returns a fresh copy of the built-in default settings object. |

Properties

| Property | Type | Description | |----------|------|-------------| | settings | Object | The resolved settings object | | default | Object | The built-in default settings | | base | Object | Snapshot of settings after constructor merge, before config file loading | | settingsTemplateProcessor | Object | The Precedent-based template processor for ${ENV} resolution |

Part of the Retold Framework

Fable Settings is a core service in the Fable ecosystem:

Testing

Run the test suite:

npm test

Run with coverage:

npm run coverage

Related Packages

License

MIT

Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the Retold Contributing Guide.