@oxog/envguard
v1.0.0
Published
Zero-dependency environment variable validation with full TypeScript inference
Maintainers
Readme
EnvGuard
Features
- 🔐 Type-Safe - Full TypeScript inference
- ✅ 18+ Validators - string, number, url, email, array, json...
- 📦 Zero Dependencies - Lightweight
- 🌍 Universal - Browser, Node.js, Edge
- 🎯 Required/Optional - With defaults
- 🏷️ Prefix Support - MYAPP_* filtering
- 📁 Grouped Config - Organized env structure
- 🔒 Sensitive Masking - Hide secrets in logs
- ⚡ < 3KB - Tiny bundle
- ✅ 98%+ Test Coverage - 524 tests passing
Installation
npm install @oxog/envguardQuick Start
import { createEnv, string, number, url, port, boolean } from '@oxog/envguard'
const env = createEnv({
// Required fields
DATABASE_URL: url({ required: true }),
// Optional with defaults
PORT: port({ default: 3000 }),
DEBUG: boolean({ default: false }),
NODE_ENV: string({ default: 'development' }),
MAX_CONNECTIONS: number({ default: 10 }),
})
// Fully typed!
env.PORT // number
env.DATABASE_URL // string
env.DEBUG // boolean
env.NODE_ENV // string
env.MAX_CONNECTIONS // numberDocumentation
Visit envguard.oxog.dev for full documentation.
Available Validators
- string - Text with length/pattern validation
- number - Float numbers with range constraints
- integer - Whole numbers
- port - Network ports (1-65535)
- boolean - true/false, yes/no, on/off, enabled/disabled, 1/0
- url - URLs with protocol/domain validation
- email - Email addresses with domain restrictions
- host - Hostnames and IP addresses
- ip - IPv4 and IPv6 addresses
- enum - Predefined values
- array - Comma-separated values
- json - JSON objects with schema validation
- regex - Regular expressions
- date - Date objects with min/max
- duration - Time durations (ms, s, m, h, d, w)
- bytes - Byte sizes (B, KB, MB, GB, TB)
- path - File paths with existence checks
- custom - Your own validation logic
License
MIT © Ersin KOÇ
