šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

config-captain

Package Overview
Dependencies
Maintainers
0
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

config-captain

A dependency injectable configuration object

2.1.0
latest
Source
npm
Version published
Weekly downloads
51
-61.36%
Maintainers
0
Weekly downloads
Ā 
Created
Source

README

Monorepo Build Continuous Deploy

Config Captain is designed to be a dependency injectable environment configuration object that can make helpful suggestions as to what configuration you have loaded.

import { Configuration } from "config-captain";

const config = new Configuration(
  { optionalVariable: "SOME_OPTIONAL_VARIABLE" },
  { requiredVariable: "SOME_REQUIRED_VARIABLE" },
  [{ SOME_OPTIONAL_VARIABLE: "VALUE_ONE", SOME_REQUIRED_VARIABLE: "VALUE_TWO" }]
);

config.getConfigurationVariable("requiredVariable");
config.getConfigurationVariableOrUndefined("optionalVariable");
config.getConfigurationVariables();

Variables

The keys in the optional and required variable section are the names you wish to use in code for your variables. The values should refer to the datasource location you wish to take a configuration value from.

{
  nameToReferToInCode: "name-in-datasource";
}

Optional Variables

const config = new Configuration(
  { someCanHaveVariable: "some-non-critical-variable" },
  {},
  [dataSource]
);

The first parameter to Configuration is optional variables. If these variables are not found in the datasource at startup time they will return undefined when you attempt to retrieve them.

Required Variables

const config = new Configuration(
  {},
  { someMustHaveVariable: "some-critical-variable" },
  [dataSource]
);

The second parameter to Configuration is required variables. If these variables are not found in the datasource at startup time, the Configuration will throw an error.

Datasources

This should be an array of key-value objects. If two or more datasources provide a value for a given variable, the earliest in the list will take priority. Process.env can be given as a datasource.

Accessors

getConfigurationVariables

Get the entire configuration object as a key-value object. The variables specified as 'optional' will be potentially undefined.

getConfigurationVariable

Get the value of a required environment variable. This will have the type of string.

getConfigurationVariableOrUndefined

Get the value of an optional environment variable. This will have the type of string | undefined.

Keywords

config

FAQs

Package last updated on 19 Nov 2024

Did you know?

Socket

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