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

node-config-store

v0.0.3

Published

Runtime Configuration Utility for Node JS

Downloads

4

Readme

Config Store

Easily manage the runtime setup of an app wide config store.

Features

  • Populate initial state via object, files and functions
  • Schema validation
  • Static value lookup and derived lookups based on the current state
  • Immutability Option

Usage

createConfigStore(options) => ConfigStore

Create the ConfigStore

options

  • initialState - {Object} The initial state for the store

  • initialStateFiles - {Array} Paths to the dotenv compatible files that should be used to populate the initial store.

    • If used, dotenv is a required peer-dependency.
    • The values pulled from the files are merged into the ConfigStore in the order they are encountered.
  • initialStateLoaders - {Array<Function(currentState) => ValueSet} Array of sync/async functions that return a set of values to merge into the current state at the time of execution.

    • The loaders are executed non-parellel since the new, combined state is passed to each subsequent loader.
    • initialState and initialStateFile are applied first
    • Any values returned by any loader overwrite the current state
  • derivedValues - {Object} Object of functions that are accessible and derived at runtime. Should accept a single parameter, currentState.

  • schema - {Object} A joi schema object that defines the required structure for the config state.

    • If used, joi is a required peer-dependency.
  • immutable - {Boolean} Whether or not the store should be immutable after intialization.

    • If true, initialState or initialStateFile must be provided

async loadState() => boolean

Execute the set of initialStateLoaders.

  • Only required when initialStateLoaders are provided
  • Must be executed before usage of the ConfigStore

set(key: String, value: StoreValue) => boolean

Set the value for a key in the ConfigStore.

  • Cannot be used if immutable is true

get(key: String | keySet String[]) => StoreValue | StoreValueMap | undefined

Get the value(s) for a specific key(set) in the ConfigStore

  • If passed an array of keys, the keys will be returned in a set
  • This first checks for the existence of a derivedValue function that matches the provided key and will return that, otherwise return the value for the absolute key (if exists)

State Construction Order

The creation of the ConfigStore state is deterministic and is the result of merge operation for the different methods of initial value creation:

  1. The initialState object is applied
  2. Any initialStateFiles are merged agaisnt the state in the order in which they are listed
  3. Any initialStateLoaders are merged agaisnt the state in the order in which they are listed

Validation

If a schema object is provided, the state is validated agaisnt the schema after all initialState* operations are performed

  • If initialStateLoaders are provided, and are async, the validation will only occur after those operations resolve. Don't get values from the ConfigStore until everything is loaded