@muerteseguraz/envguard
Version:
Simple .env schema validator with type safety
77 lines (50 loc) โข 1.29 kB
Markdown
# 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
````