2.2.0 • Published 4 years ago

@mangar2/config v2.2.0

Weekly downloads
9
License
LGPL-3.0-or-later
Repository
github
Last release
4 years ago

Abstract

Provides function to manage configuration files

Contents

Meta

Fileconfig.js
AbstractProvides function to manage configuration files
AuthorVolker Böhm
CopyrightCopyright ( c ) 2020 Volker Böhm
LicenseThis software is licensed under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 . It is furnished "as is" , without any support , and with no warranty , express or implied , as to its usefulness for any purpose .

Global functions

All global non private functions are listed here

getCommandLineParameters

getCommandLineParameters (whiteList) => {Object}

Gets the command line parameters as object ( Key/value )

getCommandLineParameters Parameters

NameTypeDescription
whiteListArraylist of supported arguments

getCommandLineParameters returns

TypeDescription
Objectobject with key/value

getEnvironment

getEnvironment (whiteList) => {string}

Gets the current environment name

  • if --env or --environment is specified as parameter it takes the parameter value
  • else if NODE_ENV is specified it takes the os environment variable value
  • else the default 'development' is selected

getEnvironment Parameters

NameTypeAttributeDescription
whiteListArrayoptionalprovides a white list of supported environments .

getEnvironment returns

TypeDescription
stringthe environment name limited by a white list .

selectConfiguration

selectConfiguration (configuration)

Select the right configuration from a configuration object based on the current environment setting

selectConfiguration Parameters

NameTypeDescription
configurationObjectconfiguration object for different environments

readConfiguration

readConfiguration (defaultName)

Reads the current configuration from a file

  • If the file name is specified as command line parameter ( first parameter ) this file is read
  • If the file name is not specified , it will read the default file from the current directory or up to 5 levels in parent directories
  • Then it returns the active configuration , default is 'development' from the configuration file
  • The active configuration is either specified by parameter ( '--env' or '--environment' ) or set in 'NODE_ENV'

readConfiguration Parameters

NameTypeDescription
defaultNamestringdefault configuration file name