UNPKG

@mcma/core

Version:

Node module with type definitions and helper utils for the EBU MCMA framework

50 lines (49 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigVariables = void 0; const mcma_exception_1 = require("./mcma-exception"); class ConfigVariables { static instance; static getInstance() { if (!this.instance) { this.instance = new ConfigVariables(); } return this.instance; } _keys; _vars; constructor(variables) { if (!variables) { variables = process?.env; } this._keys = variables ? Object.keys(variables) : []; this._vars = {}; for (const key of this._keys) { this._vars[key.toUpperCase()] = variables[key]; } } keys() { return this._keys; } get(name) { if (!name) { throw new mcma_exception_1.McmaException("Invalid name specified."); } const value = this._vars[name.toUpperCase()]; if (value !== undefined) { return value; } throw new mcma_exception_1.McmaException(`No environment variable found with name '${name}'.`); } getOptional(name, defaultValue) { if (!name) { throw new mcma_exception_1.McmaException("Invalid name specified."); } const value = this._vars[name.toUpperCase()]; if (value !== undefined) { return value; } return defaultValue; } } exports.ConfigVariables = ConfigVariables;