@nexgin/configdir
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

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();
})();

Readme

Keywords

none

Package Sidebar

Install

npm i @nexgin/configdir

Weekly Downloads

1

Version

0.0.9

License

MIT

Unpacked Size

80.5 kB

Total Files

43

Last publish

Collaborators

  • coltonmcinroy