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 🙏

© 2024 – Pkg Stats / Ryan Hefner

confab

v0.1.5

Published

fabulous configuration!

Downloads

70

Readme

Confab

Build configuration objects from chains of recycleable transformations:

Build Status Coverage Status

// file: myapp.js
'use strict';
var confab = require('confab');

var config = confab([
  confab.loadEnvironment({
    PORT: 'port'
  }),

  confab.defaults({
    role: 'api',
    port: 4500
  }),
]);

console.log(config);

With the environment and defaults applied, we see a nicely built configuration:

$ PORT=3200 node myapp.js
{ role: 'api', port: '3200' }

Installation

$ npm install confab

Convention and Configuration

Confab is configuration-first by nature, as the details of configuration may vary widely from one project to the next. Nevertheless, the built-in transformations reflect certain opinions.

Namely, configuration should be:

  • separate. Keeping configuration isolated from application logic eases deployment across multiple environments. Confab encourages developers to author complete configurations independent of the application.

  • predictable. Like any other exception, errors in configuration should be immediately fatal. All confab transformations will fail immediately if unexpected conditions are encountered, while the required transformation can assert the presence of certain configuration keys. Similarly, the defaults transformation--while unquestionably useful--should be approached with care.

  • immutable. The running application should not be concerned with configuration changes: if a change must be applied it should be applied to a new process. The freeze transformation guarantees that a config will not change after initialization.

  • simple. File-based configs (JSON, YAML, etc.) make it easy to nest data inside multiple levels of keys. This is convenient for grouping like data, but it is not immediately clear how these data would map to (e.g.) environment variables or command-line arguments. Sub-configurations can enhance separation between unrelated concerns, but they should be used with care.

And one non-opinion
  • Command-line parsing, and what impact (if any) arguments should have on the configuration is left as a project-specific decision. No transformations are provided for command-line support--but you can write your own!

Transformations

Confab ships with transformations for:

  • Loading JSON configurations
  • Mapping environment variables to a configuration object
  • Providing default values
  • Marking required values
  • Locking down the configuration

Complete reference.

Additional transformations

Known third-party transformations include:

Name | Description ------------------------------------ | ---------------------------------------- loadYaml | load YAML configuration files loadEnvConfigFile | load config files from likely locations features | declare and toggle config features

Custom transformations

Every transformation accepts the config object and returns it after any modifications have been applied. A silly example from the test suite will multiply any numeric config values by two:

function transformTimesTwo (config) {
  Object.keys(config).forEach(function (k) {
    if (typeof config[k] === 'number') config[k] *= 2;
  });
  return config;
}

This filter can then be used like any other:

var config = confab([

  confab.loadJSON([
    './config.json'
  ]),

  transformTimesTwo
]);

Test

Lint and run test suite:

$ npm test

Generate code coverage report:

$ npm run cover

License

MIT