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.
34 lines (33 loc) • 887 B
TypeScript
export interface BaseSchema {
name?: string;
required?: boolean;
description?: string;
}
type ValidatorFunction<Type> = (value: Type) => boolean;
export type Validator<Type> = ValidatorFunction<Type> | {
function: ValidatorFunction<Type>;
message: string;
description?: string;
};
export interface StringSchema extends BaseSchema {
type: 'string';
default?: string;
minLength?: number;
maxLength?: number;
pattern?: RegExp | string;
validator?: Validator<string>;
}
export interface NumberSchema extends BaseSchema {
type: 'number';
default?: number;
min?: number;
max?: number;
integer?: boolean;
validator?: Validator<number>;
}
export interface BooleanSchema extends BaseSchema {
type: 'boolean';
default?: boolean;
}
export type PrimitiveSchema = StringSchema | NumberSchema | BooleanSchema;
export {};