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

determination

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

determination

Configuration resolver using confidence and shortstop.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-28.57%
Maintainers
1
Weekly downloads
 
Created
Source

determination

Configuration resolver. determination loads a JSON configuration file, resolving against criteria using confidence and shortstop protocol handlers.

In addition, determination supports javascript style comments in your JSON using shush.

Note: determination borrows heavily from confit, but prefers confidence for resolving environment as well as other criteria for filtering.

Usage

const Determination = require('determination');

Determination.create(options)

  • options (Object) - an options object containing:
    • config (String) - required path to a JSON configuration.
    • criteria (Object) - optional resolution criteria. See confidence. Minimally will always contain process.env under the key env.
    • protocols (Object) - optional mapping of protocols for shortstop.
    • defaults (Object) - optional default configuration values.
    • overrides (Object) - optional override configuration values.
  • returns - a resolver.

resolver.resolve([callback])

  • callback (Function) - an optional callback.
  • returns - a promise if callback is not provided.
const Determination = require('determination');
const Path = require('path');
const Handlers = require('shortstop-handlers');

const config = Path.join('.', 'config', 'config.json');

const resolver = Determination.create({
    config,
    protocols: {
        require: Handlers.require(Path.dirname(config))
    }
});

resolver.resolve((error, config) => {
    //config.get
    //config.set
});

Config API

  • get(string: key) - returns the value for the given key, where a dot-delimited key may traverse the configuration store.
  • set(string: key, any: value) - sets the given value on the given key, where dot-delimited key may traverse the configuration store.
  • merge(object: value) - merged the given value into the configuration store.
config.set('some.key.name', 'value');
config.merge({ some: { key: other: 'another value' }});
config.get('some.key.other'); //'another value'

Shortstop Protocol Handlers

Two protocol handlers are enabled by default:

  • import:path - merges the contents of a given file, supporting comments (unlike require).
  • config:key - copies the value under the given key (supporting dot-delimited) to the key it is declared on.

Resolution Order

Configuration file contents are resolved in the following order:

  1. Resolve defaults against protocols.
  2. Merge defaults with config.
  3. Resolve merged config against protocols.
  4. Resolve overrides against protocols.
  5. Merge overrides into config.
  6. Resolve config against config: protocol.

Keywords

FAQs

Package last updated on 29 Apr 2017

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