1.1.0 • Published 4 years ago

config-check v1.1.0

Weekly downloads
1,565
License
SEE LICENSE IN LI...
Repository
github
Last release
4 years ago

config-check

Install

$  npm i config-check

Usage

  const cc = require('config-check')

  const config = {
    env: cc('NODE_ENV').default('production').exec(),
    port: cc('PORT').default(8080).int().exec(),
    redis: {
      uri: cc('REDIS_URI').required().exec()
    },
    aws: {
      secret: cc('AWS_SECRET').required().exec(),
      key: cc('AWS_KEY').required().exec(),
      region: cc('AWS_REGION').default('us-east-1').exec(),
      endpoint: cc('AWS_ENDPOINT').exec(),
    },
  }

Methods

required()

Enforces env var existence

  cc('SOME_ENV_VAR').required()

default(value)

Adds default value

  cc('SOME_ENV_VAR').default('default value')

int()

Enforces the value is an integer with casting

  cc('SOME_ENV_VAR').int()

float()

Enforces the value is a float with casting

  cc('SOME_ENV_VAR').float()

list(delimiter)

Splits a string into a list, not safe Default delimiter is ','

  const delimiter = ' '
  cc('SOME_ENV_VAR').list(delimiter)

exec()

Returns the final value

  cc('SOME_ENV_VAR').exec()

Development

Requirements

  • standardjs linting
  • 100% test coverage

Npm run commands

CommandDescription
lintChecks project linting
lint:fixAuto fixes project lint errors
testTest runner
test:watchTest runner with watch
coverageCoverage checker
changelogGenerate changelog

LICENSE

DBAD for more info

1.1.0

4 years ago

1.0.0

5 years ago