env-seal
v0.0.6
Published
Strict, zero-dependency environment schema validator for Node, Deno, and Bun.
Downloads
240
Maintainers
Readme
env-seal
The strictest, zero-dependency environment validator.
Support for Node.js, Deno, Bun, and Edge Runtimes.
Why Env-Seal?
Most environment libraries are either too loose (runtime crashes) or too heavy (dependencies). env-seal is designed for production-grade reliability.
- Zero Dependencies: Keeps your
node_modulesclean. - Strict Typing: TypeScript first. Returns a strictly typed configuration object.
- Secure: Secrets are properly redacted from logs (
console.log) and output (JSON.stringify). - Granular Validation: Chainable rules for Email, URL, Min/Max, and Regex.
- Native .env Support: Built-in zero-dependency
.envparser (optional). - Auto-Docs: Generate markdown tables for your schema automatically.
Installation
npm install env-seal
# or
pnpm add env-seal
# or
bun add env-seal
# or
deno add npm:env-sealQuick Start
import { define, e } from 'env-seal';
// 1. Define your schema
const config = define({
PORT: e.number().default(3000),
NODE_ENV: e.string().default('development'),
API_KEY: e.string().secret(), // Required + Hidden from logs
CONTACT_EMAIL: e.string().email(),
SITE_URL: e.string().url(),
}, {
loadDotEnv: true // Optional: Load .env file
});
// 2. Use it! (Type-safe)
console.log(`Server running on port ${config.PORT}`);
// config.API_KEY is available here, but hidden if you log the whole object.Features
🛡️ Granular Validation
Validate your inputs with precise rules:
| Rule | Description | Example |
| :--- | :--- | :--- |
| .email() | Validates email format | e.string().email() |
| .url() | Validates URL format | e.string().url() |
| .min(n) | Min value (number) or length (string) | e.number().min(10) |
| .max(n) | Max value (number) or length (string) | e.string().max(100) |
| .regex(re) | Custom pattern matching | e.string().regex(/^[a-z]+$/) |
🔒 Security & Redaction
Mark sensitive variables with .secret().
- Accessible in code:
config.API_KEYworks fine. - Hidden in logs:
console.log(config)shows[REDACTED]. - Hidden in JSON:
JSON.stringify(config)shows[REDACTED].
📄 Documentation Generator
Generate a Markdown table of your environment variables for your README.md or llms.txt.
import { generateMarkdown } from 'env-seal';
const md = generateMarkdown(schema);
console.log(md);Output:
| Variable | Type | Required | Default | Rules |
| :--- | :--- | :--- | :--- | :--- |
| PORT | number | No | 3000 | - |
| API_KEY | string | Yes | [REDACTED] | (Secret) |
Example Schema Docs
Run generateMarkdown(schema) to automatically produce tables like this:
Environment Variables
| Variable | Type | Required | Default | Rules |
| :--- | :--- | :--- | :--- | :--- |
| APP_NAME | string | No | My App | - |
| PORT | number | No | 3000 | - |
| DATABASE_URL | string | Yes | - | (Secret) |
| ADMIN_EMAIL | string | Yes | - | Email |
| MAX_CONNECTIONS | number | Yes | - | Min: 1, Max: 100 |
License
MIT
