env-schema-checker
Version:
A zero-config, type-safe, schema-driven .env validator with automatic error reporting, autocomplete, and runtime checks
35 lines (31 loc) • 938 B
text/typescript
import { z } from 'zod';
type EnvType = 'string' | 'number' | 'boolean' | 'array' | 'object';
type EnvSchema = {
[key: string]: EnvType | string[] | z.ZodType;
};
interface LoadEnvOptions {
schema: EnvSchema;
path?: string;
encoding?: string;
override?: boolean;
debug?: boolean;
}
interface ValidationError {
key: string;
message: string;
value?: unknown;
}
interface ValidationResult {
success: boolean;
errors?: ValidationError[];
env: Record<string, unknown>;
}
interface TypeGeneratorOptions {
outputPath?: string;
schema: EnvSchema;
}
declare function loadEnv(options: LoadEnvOptions): ValidationResult;
declare function generateTypes(options: TypeGeneratorOptions): string;
declare function validateEnv(schema: EnvSchema): ValidationResult;
declare function parseEnvFile(path: string): Record<string, string>;
export { generateTypes, loadEnv, parseEnvFile, validateEnv };