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

parfait

v0.8.0

Published

A sweet multi-layered configuration framework

Downloads

19

Readme

Parfait.js

Build Status

A sweet multi-layered configuration framework.

Dealing with complex configurations

Configuration usually starts out fairly simple. Just a config file, some JSON describing a handful of settings. As your application or framework grows, the configuration grows.

Eventually you want to break the configuration up into multiple files. And have configuration vary depending on your environment. Or the current user. Or the local machine. And that new guy runs on Windows, so the files need to be stored in a different directory.

What was simple is no longer. Parfait is here to help!

Parfait can parse both JSON and YAML configuration files. JSON files are first minified, so that they can contain comments. Parfait can also read configuration from the user config (~/.config/${appName} on Unixes) and site config (/etc/${appName} on Unixes), and properly merge these configurations with the default configuration specified in the application itself.

Installation

Parfait.js is hosted on NPM, so you can simply install it, and add it to your package.json as a dependency.

$ npm install --save parfait

How it works

In your application, simply invoke parfait.configure(). Its default conventions are fairly reasonable, but you can override them if you need to.

var parfait = require('parfait');

var config = parfait.configure({
    // environment can be provided here, or by NODE_ENV.
    //environment: process.env.NODE_ENV || 'development',

    // The configuration directory may also be specified
    //directory: 'config'

    // Optionally, a hard-coded base config can be provided as a
    // starting point.
    preConfig: {
      appdirs: {
        // If specified, user and site config can be processed on Unixes
        'appName': 'SuperApp',
        // If specified, user and site config can be processed on Windows
        'appAuthor': 'Acme'
      }
    },

    // And a hard coded config to apply on top of everything else.
    //postConfig: {}
  });

Parfait parses the configuration files in the specified directory, and builds a POJO model that directly maps to the files and file structure. For example, If the file foo.json contains { "bar": "bang" }, then the config object will look like:

{
  foo: {
    bar: 'bang'
  }
}

Once one directory is scanned, Parfait will scan the next, overlaying the new settings on top of the prior settings.

Configuration is processed starting with the most general configuration, overlaying it with the more specific configurations.

  1. The hard-coded config provided to configure()
  2. ${config} directory
  3. ${config}/${environment}.env directory

If appName (and appAuthor on Windows) is set:

  1. ${siteConfig} directory
  2. ${siteConfig}/${environment}.env directory
  3. ${userConfig} directory
  4. ${userConfig}/${environment}.env directory

Examples

The tests in the test directory actually do a fairly good job showing an example configuration, and what the expected output from that configuration should be.

TODO

  • Array append/prepend (either single item or another array)
# Append 'bar' to the array 'foo'
"foo+": "bar"
# Append 'bar', 'bam', 'bang' to the array 'foo'
"foo+": [ "bar", "bam", "bang" ]
# Prepend 'bar' to the array 'foo'
"+foo": "bar"
  • Object replacement instead of merging
# Discard 'foo' and replace with empty object
"foo=": {}
# Discard 'foo' and replace with given object
"foo=": { "bar": 3.14159 }
  • Individual key deleltion
# Remove 'foo'
"foo-": null