Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oconf

Package Overview
Dependencies
Maintainers
4
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oconf

Configuration

  • 2.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.7K
increased by13.98%
Maintainers
4
Weekly downloads
 
Created
Source

OConf

[NPM version Build Status](https://travis-ci.org/One-com/node-oconf) Coverage Status Dependency Status

Load cjson (JSON + c-style) commentaries, with inheritance-sugar on top:

> var oconf = require('oconf');
> oconf.load('config/my-config.cjson');
{
     "some-setting": "default-value",
     "value": 50
}

Format

The basic idea is to experiment with applying #include-statements recusively inside JSON/cJSON documents:

// default-settings.cjson
{
	"some-setting": "default value",
	"value": 100
}
// my-config.cjson
{
	"#include": "./default-settings.json",
	"value": 50
}

Will result in a config with:

{
	"some-setting": "default-value",
	"value": 50
}

The extension of objects also work recursively, so setting a single sub-key somewhere doesn't override the entire thing.

Structure

There are no restrictions in how includes work (except no loops). Usually a structure like this is used:

  • project/config/default.cjson has project-wide defaults.
  • project/config/{dev,test,staging,production}.cjson inherits the default and set keys relevant to respective environments
  • project/config/$HOSTNAME.cjson (optinal) machine-specifics that inherit from the relevant environment-file.
  • /etc/$WORKNAME/$PROJECTNAME-secrets.cjson inherits the machine-specific things and typically adds production secrets.

Binary

To help resolve configuration on the command line oconf exports a CLI tool called oconf. In it's simplest form it takes a path to an cjson file, and outputs the resolved JSON object.

 $ oconf config.cjson
{
  "someConfig": "someValue",
  "obj": {
    "foo": "bar"
  }
}

Oconf also takes a --lint option. It will make oconf not output any of the resolved configuration, but only exit with an error in case of any formatting errors in the files.

 $ oconf --lint config.cjson

You can supply a path to a value as well:

 $ oconf config.cjson obj.foo
"bar"

The output from the above is the JSON.stringified format. If you need to pass it into another cli program, you'd most likely want it as a string literal and not quoted. That can be achieved like this:

 $ oconf --bare config.cjson obj.foo
bar

If the key is missing oconf will exit with exit code 1. If you need to overwrite that behaviour you can pass the --allowmissing flag to oconf which will make it exit with status code 0 if no value is found at the given path.

Tests

Download/clone, run npm install and then npm test.

License

The software is provided under the Modified BSD License; See LICENSE for further details.

Keywords

FAQs

Package last updated on 01 Mar 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc