Source

utils/composeEnv.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var pick_1 = __importDefault(require("lodash/pick"));
// Config dot env
require('dotenv').config();
/**
 * Environment variables (dotenv) composer with empty check
 * @category utils
 * @module composeEnv
 */
var composeEnv = function (keys) {
    var values = (0, pick_1.default)(process.env, keys);
    /**
     * Throw an error if any of the environment variables is not defined
     */
    (function () {
        var missingKeys = [];
        for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
            var key = keys_1[_i];
            var value = values[key];
            if (value === undefined)
                missingKeys.push(key);
        }
        if (missingKeys.length > 0)
            throw new Error("Value(s) undefined but required in environment: ".concat(missingKeys.join(', ')));
    })();
    return {
        keys: keys,
        values: values,
    };
};
exports.default = composeEnv;