Options
All
  • Public
  • Public/Protected
  • All
Menu

配置读取器,加载优先级: overwrite options -> process.env -> options(.env) -> optionsLoader(user config) -> default

Hierarchy

  • ConfigLoader

Index

Constructors

constructor

Properties

Private Readonly dotenvBy

dotenvBy: string

从 process.env 读取要加载的 .env 后缀,default: ENV

Private options

options: Options = ...

加载自 .env 的配置

Private Readonly optionsLoader

optionsLoader: FOptionsLoader

配置加载器,可以是一个方法或配置对象

Private overwriteOptions

overwriteOptions: Options

覆盖配置,优先级最高

Private requiredVariables

requiredVariables: string[]

设置必填字段

Methods

loadBoolConfig

  • loadBoolConfig(key: string, defaultValue?: null | boolean): null | boolean
  • Parameters

    • key: string
    • defaultValue: null | boolean = null

    Returns null | boolean

loadConfig

  • loadConfig<T>(key: string, defaultValue?: any, autoConvert?: boolean, ignoreCase?: boolean): null | T
  • load config from env first, then options loader, and default at last.

    Type parameters

    • T = string

    Parameters

    • key: string

      property key

    • defaultValue: any = null
    • autoConvert: boolean = false

      convert bool string to bool and numeric string to numeric

    • ignoreCase: boolean = false

      has performance issue

    Returns null | T

    • property value

loadConfig2

  • loadConfig2<T>(module: string, path: string, defaultValue?: T): null | T
  • Type parameters

    • T

    Parameters

    • module: string
    • path: string
    • Optional defaultValue: T

    Returns null | T

Private loadConfigFromOptions

  • loadConfigFromOptions(key: string, ignoreCase?: boolean): any
  • Parameters

    • key: string
    • ignoreCase: boolean = false

    Returns any

loadConfigs

  • loadConfigs(opts?: { autoConvert: boolean }): Options
  • Parameters

    • opts: { autoConvert: boolean } = ...
      • autoConvert: boolean

    Returns Options

loadNumericConfig

  • loadNumericConfig(key: string, defaultValue?: null | number): null | number
  • Parameters

    • key: string
    • defaultValue: null | number = null

    Returns null | number

setOverwriteOptions

  • setOverwriteOptions(options: Options, overwrite?: boolean): void

setRequiredVariables

  • setRequiredVariables(requires: string[], overwrite?: boolean): void
  • 设置必设参数,未找到值时报错

    Parameters

    • requires: string[]
    • overwrite: boolean = true

      是否覆盖已经设置的值,默认: true

    Returns void

validate

  • validate(): void

Private Static convertValue

  • convertValue(value: any): any

Private Static loadIgnoreCase

  • loadIgnoreCase<R>(source: Record<string, R>, key: string, ignoreCase?: boolean): undefined | R
  • Type parameters

    • R

    Parameters

    • source: Record<string, R>
    • key: string
    • ignoreCase: boolean = false

    Returns undefined | R

Legend

  • Class
  • Constructor
  • Method
  • Function
  • Type alias
  • Private property
  • Private method
  • Interface

Generated using TypeDoc