Options
All
  • Public
  • Public/Protected
  • All
Menu

Class EnvironmentVariableManager<Variables>

用于以类型安全的方式获取环境变量。

example

interface ENV { DATABASE: string URL: string } const appEnvironmentVariableManager = EnvironmentVariableManager.of() const database = appEnvironmentVariableManager.get('DATABASE') // success const name = appEnvironmentVariableManager.get('NAME') // type check passed const safeName = appEnvironmentVariableManager.safeGet('NAME') // type check error

Type parameters

Hierarchy

  • EnvironmentVariableManager

Index

Methods

Static of

resetVariables

  • resetVariables(): void

get

  • get<Key>(key: Key): undefined | Variables[Key]

recklessGet

  • recklessGet<Key>(key: Key): Variables[Key]

safeGet

  • safeGet<Key>(key: Key): Variables[Key]
  • Get the value of the environment variable. When the target key is not exist in variables, an error will be thrown.

    see

    get, recklessGet

    Type parameters

    • Key: string | number | symbol

    Parameters

    • key: Key

    Returns Variables[Key]

Constructors

constructor

  • new EnvironmentVariableManager<Variables>(options?: EnvironmentVariableManagerOptions<Variables>): EnvironmentVariableManager<Variables>

Properties

_variables

_variables: Variables

_parsers

_parsers: ParsersOfVariables<Variables>

Accessors

variables

  • get variables(): Variables