3.1.6 • Published 5 months ago

@hackbg/conf v3.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@hackbg/conf

Loads configuration from environment.

Parses the values of "empty string", false, no, and 0 as negatives.

Example usage with TypeScript:

import { Env, EnvConfig } from '@hackbg/conf'

export class MyConfig extends EnvConfig {

  /** This constructor must be copied into every subclass to support the passing of defaults.
    * This is dumb, TODO fix in next version. */
  constructor (
    env:      Env               = {},
    cwd:      string            = '',
    defaults: Partial<MyConfig> = {}
  ) {
    super(env, cwd)
    this.override(defaults)
  }

  /* If you provide no default, when the env var is not defined and error will be thrown */
  myStringField
    = this.getString('MY_STRING_FIELD')

  /* To provide a default value pass a function that returns the default */
  myNumberField
    = this.getNumber('MY_NUMBER_FIELD', () => 0)

  /* To provide a default value pass a function that returns the default */
  myBooleanField
    = this.getFlag('MY_BOOLEAN_FIELD', () =>
      this.getFlag('MY_FLAG',          () =>
      this.getFlag('MY_OTHER_FLAG',    () => {
        if (Math.random() > 0.5) {
          return true
        } else {
          return false
        }
      })))

}

const currentConfig = new MyConfig(process.env, process.cwd, /* {}: defaults */)

Made with #%&! @ Hack.bg

3.1.6

5 months ago

3.1.3

9 months ago

3.1.2

9 months ago

3.1.1

11 months ago

3.1.5

9 months ago

3.1.4

9 months ago

3.1.0

1 year ago

3.0.0

1 year ago

2.0.0

1 year ago

1.0.0

1 year ago