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.

26 lines (25 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseParser = void 0; var debug_1 = require("../debug"); var errors_1 = require("../errors"); var BaseParser = (function () { function BaseParser() { this._debug = (0, debug_1.createDebugLogger)(this.constructor.name); } BaseParser.prototype.removeQuotes = function (value) { this._debug.trace("Removing quotes from value: ".concat(value)); return value.trim().replace(/^['"]|['"]$/g, ''); }; BaseParser.prototype.runCustomValidator = function (validator, value, context) { if (!validator) return; var validatorFunction = typeof validator === 'function' ? validator : validator.function; var message = typeof validator === 'function' ? 'Value failed custom validation' : validator.message; if (!validatorFunction(value)) { throw new errors_1.EnvironmentValidationError(context.envKey, message, context.path); } }; return BaseParser; }()); exports.BaseParser = BaseParser;