UNPKG

envsafe-lite

Version:

Lightweight, type-safe environment variable parser for Node.js with zero dependencies.

22 lines (21 loc) 803 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bool = bool; function bool(options = {}) { return { _type: "bool", parse(key, value) { if (value === undefined || value === null || value === "") { if (options.default !== undefined) return options.default; throw new Error(`Missing required environment variable: ${key}`); } const normalized = value.toLowerCase().trim(); if (["true", "1", "yes"].includes(normalized)) return true; if (["false", "0", "no"].includes(normalized)) return false; throw new Error(`Invalid boolean for environment variable ${key}: "${value}"`); } }; }