0.0.9 • Published 1 year ago

@nexgin/configdir v0.0.9

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
1 year ago

ConfigDir

ConfigDir is a library for loading configuration files of various formats.

To add ConfigDir to your application simply install it, add your config directory/files, initialize the loader class, and get the config.

ConfigDir Concepts

  • Config directory contains subdirectory called "default" which gets loaded first
  • Config directory contains subdirectories containing any unique name which are referred to as environments
  • index files contain properties associated with config or directory root
  • Config directory can contain subdirectories which are part of the config structure
  • Index files loaded first all other files loaded secondary
  • Supports reading multiple config directories (Useful for modular projects allowing for modular configs) with primary configDir taking priority

Supported Config Formats

  • INI (.ini)
  • Javascript (.js)
  • JSON (.json)
  • JSON5 (.json5)
  • XML (.xml) Note: Due to XML schema design XML is not recommended as it doesn't merge the same as other files but does work
  • YAML (.yaml|.yml)

Install from npm

npm install @nexgin/configdir

Install from yarn

yarn add @nexgin/configdir

Example Config Directory Structure

config/
├── default
│   ├── index.ini
│   ├── index.js
│   ├── index.json
│   ├── index.json5
│   ├── index.xml
│   ├── index.yaml
│   └── tests
│       ├── index.json
│       └── test2.json
├── development
│   └── index.json
├── production
│   └── index.json
└── staging
    └── index.json

Example

// Add Import at top
import {ConfigDir} from '@nexgin/configdir';
// import * as path from 'path'; // Import used for loading additional configs example

// Create instance of Loader class
const configDir = new ConfigDir();
// const configDir = new ConfigDir({configDirs: [path.resolve('./path/to/another/configDir')]});
(async () => {
  // Initialize class
  await configDir.init();
  // Get config
  const config = configDir.get();
})();
0.0.9

1 year ago

0.0.8

1 year ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago