@raccoons-co/genera
Version:
Abstractions on top of Typescript 5.0.
39 lines (38 loc) • 1.4 kB
JavaScript
;
/*
* Copyright 2023, Raccoons. Developing simple way to change.
*
* @license MIT
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ethics_1 = require("@raccoons-co/ethics");
const ClassFieldDecorator_1 = __importDefault(require("./ClassFieldDecorator"));
/**
* The user environment variable.
*/
class EnvironmentVariable {
/**
* Returns environment variable decorator factory instance.
*
* @param name - the name of the environment variable
* @returns object - the decorator factory instance
*/
static of(name) {
return new class {
/** {@inheritDoc} */
orElseInitial() {
return new ClassFieldDecorator_1.default().decorator((initialValue) => { var _a; return (_a = process.env[name]) !== null && _a !== void 0 ? _a : initialValue; });
}
/** {@inheritDoc} */
orElseThrow() {
return new ClassFieldDecorator_1.default().decorator(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(initialValue) => ethics_1.Strict.notNull(process.env[name], `${name} is undefined`));
}
};
}
}
exports.default = EnvironmentVariable;