envalid
Version:
Validation for your environment variables
32 lines (31 loc) • 1.62 kB
TypeScript
import { CleanedEnvAccessors, CleanOptions, ValidatorSpec } from './types';
/**
* Returns a sanitized, immutable environment object. _Only_ the env vars
* specified in the `validators` parameter will be accessible on the returned
* object.
* @param environment An object containing your env vars (eg. process.env).
* @param specs An object that specifies the format of required vars.
* @param options An object that specifies options for cleanEnv.
*/
export declare function cleanEnv<T>(environment: unknown, specs: {
[K in keyof T]: ValidatorSpec<T[K]>;
}, options?: CleanOptions<T>): Readonly<T & CleanedEnvAccessors>;
/**
* Returns a sanitized, immutable environment object, and passes it through a custom
* applyMiddleware function before being frozen. Most users won't need the flexibility of custom
* middleware; prefer cleanEnv() unless you're sure you need it
*
* @param environment An object containing your env vars (eg. process.env).
* @param specs An object that specifies the format of required vars.
* @param applyMiddleware A function that applies transformations to the cleaned env object
* @param options An object that specifies options for cleanEnv.
*/
export declare function customCleanEnv<T, MW>(environment: unknown, specs: {
[K in keyof T]: ValidatorSpec<T[K]>;
}, applyMiddleware: (cleaned: T, rawEnv: unknown) => MW, options?: CleanOptions<T>): Readonly<MW>;
/**
* Utility function for providing default values only when NODE_ENV=test
*
* For more context, see https://github.com/af/envalid/issues/32
*/
export declare const testOnly: <T>(defaultValueForTests: T) => T;