UNPKG

typed-environment-loader

Version:

typed-environment-loader is a lightweight utility for loading environment variables in a typed manner, ensuring type safety and consistency in your Node.js applications.

24 lines (23 loc) 655 B
import { ArraySchema, EnumSchema, PrimitiveSchema, SchemaItem } from '.'; export interface ParserContext { envKey: string; path: string[]; schema: SchemaItem; value: string; } export interface ParserResult { value: unknown; } export type ParserTypeMap = { string: PrimitiveSchema; number: PrimitiveSchema; boolean: PrimitiveSchema; enum: EnumSchema<readonly string[]>; array: ArraySchema; }; export interface Parser { parse(context: ParserContext): ParserResult; } export type SchemaType<Type extends SchemaItem> = Type extends { type: infer Key extends keyof ParserTypeMap; } ? ParserTypeMap[Key] : never;