UNPKG

@muerteseguraz/envguard

Version:

Simple .env schema validator with type safety

77 lines (50 loc) โ€ข 1.29 kB
# envguard > ๐Ÿ›ก๏ธ Simple `.env` schema validator with type safety, defaults, and clear errors. ## โœจ Features - โœ… Schema-based environment validation - โœ… Type-safe (TS friendly) - โœ… Defaults and enum support - โœ… Clean error messages - โœ… Zero deps (except `dotenv`) --- ## ๐Ÿ“ฆ Installation ```bash npm i envguard ```` --- ## ๐Ÿš€ Usage ```ts // envguard.config.ts import { defineEnv } from 'envguard'; export default defineEnv({ API_KEY: { type: 'string' }, PORT: { type: 'number', default: 3000 }, NODE_ENV: { type: 'enum', values: ['development', 'production'], default: 'development' }, DEBUG: { type: 'boolean', default: false } }); ``` ```ts // index.ts import config from './envguard.config'; import { loadEnv } from 'envguard'; const env = loadEnv(config); console.log(env.PORT); // โ†’ 3000 (number) ``` --- ## โŒ Errors If variables are missing or invalid, you'll get clean, readable errors: ```bash Missing required environment variable: API_KEY Invalid number for PORT: abc Invalid value for NODE_ENV. Expected one of: development, production ``` --- ## ๐Ÿงช Testing ```bash npx vitest run ``` --- ## ๐Ÿ› ๏ธ License MIT ยฉ 2025 MuerteSeguraZ ```` ---