typed-environment-loader
Version:
typed-environment-loader is a lightweight utility for loading environment variables in a typed manner, ensuring type safety and consistency in your Node.js applications.
43 lines (42 loc) • 2.05 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.BooleanParser = void 0;
var errors_1 = require("../errors");
var base_parser_1 = require("./base-parser");
var BooleanParser = (function (_super) {
__extends(BooleanParser, _super);
function BooleanParser() {
return _super !== null && _super.apply(this, arguments) || this;
}
BooleanParser.prototype.parse = function (context) {
this._debug.info("Parsing boolean for key: ".concat(context.envKey, ", value: ").concat(context.value));
var normalized = context.value.toLowerCase();
if (normalized === 'true') {
this._debug.info("Parsed value is true for key: ".concat(context.envKey));
return { value: true };
}
if (normalized === 'false') {
this._debug.info("Parsed value is false for key: ".concat(context.envKey));
return { value: false };
}
this._debug.error("Failed to parse boolean for key: ".concat(context.envKey, ", value: ").concat(context.value));
throw new errors_1.EnvironmentValidationError(context.envKey, 'Must be "true" or "false"', context.path);
};
return BooleanParser;
}(base_parser_1.BaseParser));
exports.BooleanParser = BooleanParser;