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 🙏

© 2025 – Pkg Stats / Ryan Hefner

determination

v3.0.0

Published

Configuration resolver using confidence and shortstop.

Downloads

16

Readme

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. Protocols are bound with context config, where config is the configuration being resolved. Obviously this doesn't work with arrow functions.
    • defaults (Object | String) - optional default pre-resolved configuration values.
    • overrides (Object | String) - optional override pre-resolved 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) - merges the given value into the configuration store.
  • use(object: store) - merges the given store into the configuration store.
  • data - accessor for a clone of the underlying store data (modifying this will not modify 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.

Custom Protocol Handlers

An example of utilizing a custom protocol handler is below. This takes advantage of the context bound to the handler.

config.json

{
    "thing1": "one",
    "thing2": "two",
    "things": "eval:${thing1} and ${thing2}"
}

and

const Determination = require('determination');
const VM = require('vm');

const protocols = {
    eval(expression) {
        return VM.runInNewContext('`' + expression + '`', this);
    }
};

Determination.create({ config: Path.join(__dirname, './config.json'), protocols }).resolve((error, config) => {
    config.get('things'); //"one and two"
});

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.