Skip to content

An extensible wrapper of the popular config package, supporting placeholder resolution (or variable expansion); encrypted values (via jasypt); default (or fallback) values; and asynchronous url fetching.

License

Notifications You must be signed in to change notification settings

alt-javascript/config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An Extensible Wrapper for Node Config

NPM
Language Badge Package Badge
release notes

An extensible wrapper of the popular config package, supporting placeholder resolution (or variable expansion), encrypted and default (fallback) values.

To use the module, simply import the substituted package as you would with the popular config package

const config = require('@alt-javascript/config');

config.get('key');
config.get('nested.key');
config.get('unknown','use this instead'); // this does not throw an error

Config values that include the common ${placeholder} syntax, will resolve the inline placeholders, so the config.get('placeholder')' path below will return start.one.two.end.

Config values that start with the prefix enc. will be decrypted with the jasypt package port, with the passphrase being sourced from the process.env.NODE_CONFIG_PASSPHRASE environment variable.

local-development.json

{
  "key": "value",
  "one" : "one",
  "placeholder": "start.${one}.${nested.two}.end",
  "placeholderEncrypted": "start.${nested.encrypted}.end",
  "nested" : {
    "key" : "value",
    "two" : "two",
    "placeholder": "start.${one}.${nested.two}.end",
    "encrypted" : "enc.pxQ6z9s/LRpGB+4ddJ8bsq8RqELmhVU2",
    "encryptedWithSecret" : "enc./emLGkD3cbfqoSPijGZ0jh1p1SYIHQeJ"
  }
}

Testing config is hard, and testability is a first class concern at @alt-javascript so the config wrapper, and the module exports an EphemeralConfig that can source config paths from a plain old javascript object as follows, allowing you to assert varying configurations easily

const {
    EphemeralConfig, ValueResolvingConfig, PlaceHolderResolver, PlaceHolderSelector
    
} = require('@alt-javascript/config');

const ephemeralConfig = new EphemeralConfig({
    key: 'value',
    nested: {
        key: 'value',
    },
});

const placeHolderResolver = new PlaceHolderResolver(new PlaceHolderSelector());
const config = new ValueResolvingConfig(ephemeralConfig,placeHolderResolver );

May be freely distributed under the MIT license.

Copyright (c) 2021 Craig Parravicini

About

An extensible wrapper of the popular config package, supporting placeholder resolution (or variable expansion); encrypted values (via jasypt); default (or fallback) values; and asynchronous url fetching.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published