@zcong/viper
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @zcong/viper

Weekly Downloads

0

Version

0.1.5

License

MIT

Unpacked Size

22.7 kB

Total Files

52

Last publish

Collaborators

  • zcong