@pallad/app-env
Version:
Detects environment (production, staging, test, development, ci) and helps making decision based on that
40 lines (39 loc) • 1.48 kB
TypeScript
import { StandardEnvName } from "./StandardEnvName";
import { Info } from "./Info";
export declare class Factory<T extends Lowercase<string> = StandardEnvName, TEnvId extends string = string> {
private config;
constructor(config: FactoryConfig<T, TEnvId>);
get supportedEnvNames(): readonly ["production", "staging", "development", "ci", "test", "preview"] | T[];
isValidEnvName(name: string): name is T;
isValidEnvId(id: unknown): id is TEnvId;
createFromProcessEnv(env?: typeof process['env']): Info<T, TEnvId | undefined>;
getEnvNameFromProcess(env?: typeof process['env']): T;
getEnvIdFromProcess(env?: typeof process['env']): TEnvId | undefined;
create(env: T, envId?: TEnvId): Info<T, TEnvId | undefined>;
}
export interface FactoryConfig<T extends Lowercase<string>, TEnvId extends string | undefined> {
/**
* List of supported environments.
*
* By default all standard environments apply
*/
envName?: T[];
/**
* List of environment variable keys (in order from) considered for env name
*
* By default uses 'APP_ENV', 'NODE_ENV'
*/
envNameEnvKeys?: string[];
/**
* List of environment variable keys (in order from) considered for env id
*
* By default uses 'APP_ENV_ID'
*/
envIdEnvKeys?: string[];
/**
* Function used to validate env id.
*
* By default accepts all envId
*/
validateEnvId?: (id: unknown) => id is TEnvId;
}