# EnvironmentVariablesPlugin

A plugin to faciliate the usage of environment variables in a modular application.

# Reference

const plugin = new EnvironmentVariablesPlugin()

# Parameters

None

# Usage

# Register the plugin

import { EnvironmentVariablesPlugin } from "@squide/env-vars";
import { FireflyRuntime } from "@squide/firefly";

const runtime = new FireflyRuntime({
    plugins: [x => new EnvironmentVariablesPlugin(x)]
});

# Retrieve the plugin instance

import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

Prefer using getEnvironmentVariablesPlugin when possible
../getenvironmentvariablesplugin/

# Register an environment variable

import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

plugin.registerVariable("apiBaseUrl", "https://my-api.com");

An environment variable with the same key can be registered multiple times (e.g., by multiple modules) as long as the value remains the same. If the value differs, an Error will be thrown.

# Register multiple environment variables at once

import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

plugin.registerVariables({
    apiBaseUrl: "https://my-api.com",
    loginPageUrl: "https://login.com"
});

# Retrieve a single environment variable

import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

const apiBaseUrl = plugin.getVariable("apiBaseUrl");

# Retrieve all the environment variables

import { EnvironmentVariablesPlugin, EnvironmentVariablesPluginName } from "@squide/i18next";

const plugin = runtime.getPlugin(EnvironmentVariablesPluginName) as EnvironmentVariablesPlugin;

const variables = plugin.getVariables();