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

@dwaring87/config

v1.3.1

Published

Config Manager

Downloads

5

Readme

Configuration Manager

This is a general-purpose Configuration Manager that will read configuration properties from one or more json files and merge the properties. Properties in later-read files will override existing properties from earlier-read files.

Usage

const Config = require('@dwaring87/config');

Constructor

The constructor takes an optional default configuration. This can be provided as the file path to a JSON file defining the configuration OR a javascript object containing the default configuration. The default configuration can then be overridden by adding additional config files/objects. When the reset() function is used, the configuration will be reset to include the default configuration properties, if a default configuration was given.

Optionally, the constructor can take a parser function to parse the default configuration after it is read (see Read Configuration File below).

let config = new Config('/path/to/default.json');

Get Configuration

This will return an object containing all of the configuration properties.

let props = config.get();

Set Configuration

This can be used to manually set the configuration properties. This will replace all existing configuration properties.

let props = {
    propA: 'value A',
    propB: 'value B'
};
config.set(props);

Reset Configuration

This will reset the configuration properties to those in the default configuration, if provided in the constructor.

config.reset();

Clear Configuration

This will clear all of the configuration properties.

config.clear();

Read Configuration File

This can be used to add the properties of another configuration file to the existing configuration. New configuration properties will override existing configuration properties (with the exception of Arrays, where new Arrays will be appended to existing Arrays).

Optionally, a parser function can be given which can be used to modify the configuration properties after they are read from the file. This function will take the file's configuration properties as an argument and must return the modified configuration.

// Read new configuration file to merge with existing configuration
config.read('/path/to/config.json');

// Modify the configuration properties after reading
config.read('/path/to/config.json', function(config) {

    // Check for illegal value
    if ( config.propA === 'A' ) {

        // Change value to legal value
        config.propA = 'B';

    }

    // Return the modified config
    return config;

});

Merge Configuration

This can be used to merge additional configuration properties into the existing configuration. Existing properties will be overwritten and new properties will be added.

Optionally, a parser function can be given which can be used to modify the configuration properties after they are read from the file. This function will take the file's configuration properties as an argument and must return the modified configuration.

// Provide the initial configuration
let config = new Config({
  a: "Old value"
});

// Provide the additional configuration
config.merge({
  a: "New value",
  b: "New property"
});

// Get the new configuration
console.log(config.get());
// { a: 'New value', b: 'New property' }