Socket
Socket
Sign inDemoInstall

confederation

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    confederation

You can define application's configuration in multiple ways: `.env` or `env.json` files, cli arguments, load from database and many more. They all usually have different case styling. This library aims to unify the process of loading and normalizing confi


Version published
Maintainers
1
Install size
107 kB
Created

Readme

Source

Confederation

You can define application's configuration in multiple ways: .env or env.json files, cli arguments, load from database and many more. They all usually have different case styling. This library aims to unify the process of loading and normalizing configurations so that they become a single object aka "source of truth".

Usage

Let's look an example, when we run export MODULE__VARIABLE2=from-env and then app with --module--variable3=from-cli cli argument.

const configurationSources = [
    {
        value: require(`dotenv`).config().parsed,
    },
    {
        value: utils.pick(process.env, [`MODULE__VARIABLE2`, `MODULE__VARIABLE3`]),
    },
    {
        value: require(`minimist`)(process.argv.slice(2)),
        parser: parsers.dashParser,
    },
];

console.log(configurationSources);
// Returns:
// [
//   {
//     value: {
//       MODULE__VARIABLE1: 'from-dotenv',
//       MODULE__VARIABLE2: 'from-dotenv'
//     }
//   },
//   {
//     value: { MODULE__VARIABLE2: 'from-env', MODULE__VARIABLE3: 'from-env' }
//   },
//   {
//     value: { _: [], 'module--variable3': 'from-cli' },
//     parser: { nestifyPattern: '--', keyTransformer: [Function: camelCase] }
//   }
// ]

const unifiedConfig = unifyConfigurations(configurationSources);

console.log(unifiedConfig);
// Returns:
// {
//   module: {
//     variable1: 'from-dotenv',
//     variable2: 'from-env'
//     variable3: 'from-cli',
//   },
//   _: []
// }

FAQs

Last updated on 05 Sep 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc