envox
Version:
Fast and flexible environment variable parser with detailed error reporting.
40 lines (35 loc) • 1.18 kB
text/typescript
import { StandardSchemaV1 } from '@standard-schema/spec';
interface EnvVariable {
key: string;
value: string;
line: number;
}
interface EnvoxParseError {
line: number;
message: string;
content: string;
}
type ParseSuccess<T> = {
ok: true;
data: T;
vars: EnvVariable[];
};
type ParseFailure = {
ok: false;
errors: EnvoxParseError[];
};
type ParseResult<T> = ParseSuccess<T> | ParseFailure;
interface EnvoxOptions<T = Record<string, string>> {
allowEmpty?: boolean;
allowComments?: boolean;
allowExport?: boolean;
trimValues?: boolean;
expandVariables?: boolean;
schema?: StandardSchemaV1<Record<string, string>, T>;
}
declare function isEnvFile(content: string): boolean;
declare function fromObject(obj: Record<string, string>, { includeExport }?: {
includeExport?: boolean;
}): string;
declare function parseEnv<TOut = Record<string, string>>(source: string | Record<string, string | undefined>, options?: EnvoxOptions<TOut>): ParseResult<TOut>;
export { type EnvVariable, type EnvoxOptions, type EnvoxParseError, type ParseFailure, type ParseResult, type ParseSuccess, fromObject, isEnvFile, parseEnv };