"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvUtil = void 0;
var fs_1 = require("fs");
var EnvUtil = (function () {
    function EnvUtil() {
    }
    EnvUtil.prototype.getEnv = function (name) {
        if (name && name.toString() !== 'undefined' && name.toString() !== 'null') {
            var isFile = void 0;
            try {
                var fileStats = fs_1.statSync(name);
                isFile = fileStats.isFile();
            }
            catch (_) {
                isFile = false;
            }
            if ((name === null || name === void 0 ? void 0 : name.startsWith('/')) === true && isFile === true) {
                try {
                    var value = fs_1.readFileSync(name, { encoding: 'utf8' });
                    return EnvUtil.tryStringToObject(value);
                }
                catch (_) {
                    return EnvUtil.tryStringToObject(name);
                }
            }
            else {
                return EnvUtil.tryStringToObject(name);
            }
        }
        else {
            return undefined;
        }
    };
    EnvUtil.tryStringToObject = function (value) {
        value = value.trim();
        if (value.startsWith('{') && value.endsWith('}')) {
            try {
                return JSON.parse(value);
            }
            catch (e) {
                return value;
            }
        }
        return value;
    };
    return EnvUtil;
}());
exports.EnvUtil = EnvUtil;
