All files / src/Instance/Configuration EnvMap.ts

87.5% Statements 7/8
60% Branches 3/5
66.66% Functions 2/3
87.5% Lines 7/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                            5x 5x 305x 305x 305x 305x                     5x                      
/**
 * @internal
 * EnvMap exports a map of arguments passed to the application
 * @module EnvMap
 * @category Configuration
 */
 
/**
 * Class representing a map of environment variables
 */
 
export class EnvironmentVariablesMap {
  /**
   * Map of environment variable name and values
   */
  private environmentVariablesMap: Map<string, string>;
 
  /**
   * Creates an instance of EnvironmentVariablesMap.
   * @param {NodeJS.ProcessEnv} [environmentVariables=process.env] - Object containing environment variables
   */
  constructor(environmentVariables: NodeJS.ProcessEnv = process.env) {
    this.environmentVariablesMap = new Map<string, string>();
    for (const key in environmentVariables) {
      Eif (environmentVariables.hasOwnProperty(key)) {
        const value = environmentVariables[key];
        Eif (value !== undefined) {
          this.environmentVariablesMap.set(key, value);
        }
      }
    }
  }
  /**
   * Gets the value of the specified environment variable
   * @param {string} variable - environment variable name
   * @returns {(string | undefined)} - environment variable value or undefined
   */
  get(variable: string): string | undefined {
    return this.environmentVariablesMap.get(variable);
  }
 
  /**
   * Iterates over the environment variables and invokes the callback function for each environment variable
   * @param {(value: string, key: string) => void} callback - Callback function
   */
  public forEach(callback: (value: string, key: string) => void): void {
    this.environmentVariablesMap.forEach(callback);
  }
}