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

figs

v0.1.4

Published

Config inheritance & overriding

Downloads

32

Readme

Figs—config management! Build Status

What is it?

Provides config inheritance & overriding in a plethora of ways!

What ways are those?

First of all, I want to say overriding will MERGE objects, not clobber the old one with the new one. Also, the following are listed from lowest precedence to highest.

Config inheritance

This will allow you to inherit & override configs in parent directories.

This is useful if you want to share a config between multiple projects.

For example:

/home/subc/ringer.io/config.json

{"foo": "base", "bar": "meow"}

/home/subc/ringer.io/frontend/config.json

{"hello": "WORLD", "foo": "OVERRIDE"}

Result:

{"hello": "WORLD", "foo": "OVERRIDE", "bar": "meow"}

Local config overriding

We'll next load any config.local.js and config.local.json configs! Inheritance also works with these local configs too.

This is useful if you want to override things in your repo without committing them.

/home/subc/ringer.io/frontend/config.json

{"foo": "bar"}

/home/subc/ringer.io/frontend/config.local.json

{"foo": "OVERRIDE"}

Result:

{"foo": "OVERRIDE"}

Parent directory clobbering

Finally, you can club children by creating a config.js or config.json in a parent directory. This works in the exact opposite of the config inheritance, think of it as seniority.

This is useful for when you're working on multiple projects, and you want to clobber all those mofos at once, and you're too lazy to use an environment variable.

For example:

/home/subc/ringer.io/frontend/config.json

{"ringer_www_domain": "ringer.io"}

/home/subc/clobber.json

{"ringer_www_domain": "localhost"}

Result:

{"ringer_www_domain": "localhost"}

Passed overriding config

You can also load a config by setting CONFIG="/home/subc/ringer.io-override.js" in your environment before starting the Node.js process.

This is useful for production, so we can specify production configurations.


Passed overriding ENVs

You can override any property with a string by passing in a ENV variable which maps to a key in the object.

This is useful for production, if you're too lazy to add the override to a file.

To map a key to an ENV variable, replace . with __, and prepend it with CONFIG_.

Passing true, false will set booleans! Otherwise it will set the string you pass.

For example:

CONFIG_domain__ringer_www__host="dev.ringer.io.com"
CONFIG_debug="true"

Result:

{"domain": {"ringer_www": {"host": "dev.ringer.io.com"}},
 "debug": true}

Command line inspector tool

To use the tool, install this library globally with NPM:

$ npm install -g figs

Usage

Use: figs [-opts] [directory]

Arguments:
  directory   inspect from the specified directory

Options:
  --help, -h  this message
  --list, -l  all configs in the inheritance chain
  --view, -v  full stack trace of all the configs & contents
  --json, -j  View the raw JSON

Node.js Usage

Require figs directly into your config variable.

// config.js
exports.debug = true;

// app.js
var config = require('figs');

console.log('Are we in debug mode?', config.debug);

Front-end Usage

Simply pass the config object into browserify, and this will build the state of your config into your browserify bundle at the time of compilation.

// bundling
browserify.use(require('figs'));

// front-end
var config = require('figs');

You can also call figs with an object to return a Browserify plugin mounting that as your config in the front end. This will wash your configuration to only include a subset of your configuration. Because I'm sure you have secret keys in your config.

var config = require('figs');

var bundle = browserify({
    // ...
});

bundle.use(config({
    extra: 'config variables',
    domain: config.domain,
    fb: {
        app_id: config.fb.app_id,
        scope: config.fb.scope
        // We don't want our `fb.secret` in our front end!
    }
}));

You can also use it from the browserify tool.

$ browserify --plugin figs

License

(The MIT License)

Copyright (c) 2012 Ryan Munro <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.