UNPKG

envkeeper

Version:

🛡️ The most human-friendly environment variable validator for Node.js - Beautiful error messages with actionable suggestions that actually help you fix issues

53 lines (45 loc) 1.55 kB
export interface ValidationRule { type?: 'string' | 'number' | 'boolean' | 'url' | 'email' | 'json' | 'port'; minLength?: number; maxLength?: number; pattern?: string; enum?: string[]; } export interface CheckResult { valid: boolean; missing: string[]; set: string[]; } export interface InvalidVariable { name: string; value: string; expected: string; reason: string; } export class EnvKeeperError extends Error { name: 'EnvKeeperError'; missing: string[]; invalid: InvalidVariable[]; suggestions: string[]; constructor(message: string, missing?: string[], invalid?: InvalidVariable[], suggestions?: string[]); toFormattedString(): string; } export interface CustomValidatorConfig { validate: (value: string) => boolean; errorMessage?: string; } export class EnvKeeper { require(vars: string[]): boolean; validate(schema: Record<string, string | ValidationRule>): boolean; get(varName: string, defaultValue?: any, validation?: string | ValidationRule): string; check(vars: string[]): CheckResult; list(hideValues?: boolean): Record<string, string>; printStatus(vars: string[]): void; addCustomValidator(typeName: string, validator: (value: string) => boolean, errorMessage?: string): this; addCustomValidators(validators: Record<string, ((value: string) => boolean) | CustomValidatorConfig>): this; removeCustomValidator(typeName: string): this; getCustomValidators(): string[]; } declare const envKeeper: EnvKeeper; export default envKeeper; export { EnvKeeper, EnvKeeperError };