UNPKG

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.

39 lines (38 loc) 1.86 kB
"use strict"; 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.EnumParser = void 0; var errors_1 = require("../errors"); var base_parser_1 = require("./base-parser"); var EnumParser = (function (_super) { __extends(EnumParser, _super); function EnumParser() { return _super !== null && _super.apply(this, arguments) || this; } EnumParser.prototype.parse = function (context) { var enumSchema = context.schema; this._debug.trace("Parsing value: (".concat(context.value, ") as enum")); if (!enumSchema.values.includes(context.value)) { this._debug.error("Invalid value: (".concat(context.value, ") not in allowed values: [").concat(enumSchema.values, "]")); throw new errors_1.EnvironmentValidationError(context.envKey, "Allowed values: ".concat(enumSchema.values.join(', ')), context.path); } this._debug.info("Parsed value: ".concat(context.value)); return { value: context.value }; }; return EnumParser; }(base_parser_1.BaseParser)); exports.EnumParser = EnumParser;