0.1.5 • Published 5 years ago

@zcong/viper v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

node-viper

NPM version NPM downloads CircleCI codecov

config loader for NodeJS

Usage

const { Viper } = require('@zcong/viper')

const viper = new Viper({
  configName: 'config',
  configPaths: ['.'],
  configTypes: ['json']
})

console.log(viper.loadFiles())
console.log(viper.loadEnv())

config

interface RootConfig {
  configName?: string
  configPaths?: string[]
  configTypes?: supportTypes[]
  envPrefix?: string
}

RootConfig.configName

config file name without extension, eg: config, .env

RootConfig.configPaths

  • config file load paths, eg: ['.']

  • if start with $ will be replaced by env, eg: $HOME/test will be ~/test

RootConfig.configTypes

config file extensions, allowed is array of type supportTypes = 'json' | 'yaml' | 'toml' | 'dotenv', default is ['json', 'yaml', 'toml', 'dotenv']

RootConfig.envPrefix

if set, only load key of env whitch has this prefix. eg: set RootConfig.envPrefix = 'VIPER', only load VIPER_TEST, VIPER_FILE, TEST will be ignored.

VIPER_ or VIPER will be treated as VIPER_

Viper

Viper.loadFiles()

search config files by the order of configPaths and configTypes , will load the first finded and valid config file as return.

Viper.loadEnv()

load config from env.

you can call both of the two method, but the first will be merged by the second.

License

MIT © zcong1993

0.1.5

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago