UNPKG

@t3ned/channel

Version:

Ergonomic, chaining-based Typescript framework for quick API development for Fastify

21 lines 774 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.envBoolean = void 0; const errors_1 = require("../../api/errors"); const truthy = [true, "true", 1, "1"]; const falsey = [false, "false", 0, "0"]; const validBooleans = [...truthy, ...falsey]; exports.envBoolean = ((key, required = true, defaultValue) => { const value = process.env[key] ?? defaultValue; if (required && typeof value === "undefined") { throw new errors_1.MissingEnvVariableError(key); } if (typeof value === "undefined") { return undefined; } if (!validBooleans.includes(value)) { throw new errors_1.InvalidEnvVariableError(key, "boolean"); } return truthy.includes(value); }); //# sourceMappingURL=envBoolean.js.map