@n7e/environment-configuration-source
v0.2.1
Published
An environment configuration source for @n7e/configuration.
Downloads
125
Maintainers
Readme
Environment Configuration Source
An environment configuration source for @n7e/configuration.
For further insights, read on.
Installation
To install this library use your favorite package manager. No additional steps are required to start using the library.
npm install @n7e/environment-configuration-sourceThis library is implemented in TypeScript but can be used with JavaScript without any additional steps.
Usage
To use this configuration source with the default behaviour simply import and instantiate it.
import { EnvironmentConfigurationSource } from "@n7e/environment-configuration-source";
configurationBuilder.addConfigurationSource(new EnvironmentConfigurationSource());The default behaviour is to include all environment variables beginning with "N7E_CONFIGURATION_", replace "__" with "." to allow nested key paths and transform the keys to camel case.
As an example the following environment...
IGNORED=this is ignored
N7E_CONFIGURATION_KEY=value
N7E_CONFIGURATION_ANOTHER_KEY=another value
N7E_CONFIGURATION_NESTED__KEY=nested value...will result in the following configuration:
{
key: "value",
anotherKey: "another value",
nested: {
key: "nested value"
}
}Match And Transform
The configuration source constructor accepts custom match and transform functions allowing you to decide which environment variables are included and how the key paths are transformed.
Following is an example of how to include all environment variables as is.
import { EnvironmentConfigurationSource } from "@n7e/environment-configuration-source";
configurationBuilder.addConfigurationSource(new EnvironmentConfigurationSource(key => true, key => key));